22
33## Overview
44
5- This document describes the comprehensive test suite for the metrics-processor project, including test execution , coverage measurement, and regression protection.
5+ This document describes the comprehensive test suite for the metrics-processor project, including unit tests, integration tests, E2E tests , coverage measurement, and regression protection.
66
77## Test Organization
88
99### Test Structure
1010
1111```
1212tests/
13- ├── fixtures/ # Shared test fixtures and utilities
14- │ ├── mod.rs # Module declaration
15- │ ├── configs.rs # YAML configuration fixtures
16- │ ├── graphite_responses.rs # Mock Graphite response data
17- │ └── helpers.rs # Test helper functions and assertions
18- ├── documentation_validation.rs # Documentation validation tests
19- ├── integration_health.rs # Service health integration tests
20- └── integration_api.rs # API integration tests
13+ ├── fixtures/ # Shared test fixtures and utilities
14+ │ ├── mod.rs # Module declaration
15+ │ ├── configs.rs # YAML configuration fixtures
16+ │ ├── graphite_responses.rs # Mock Graphite response data
17+ │ └── helpers.rs # Test helper functions and assertions
18+ ├── docker/ # Docker setup for E2E tests
19+ │ ├── docker-compose.yml # go-carbon + carbonapi containers
20+ │ ├── go-carbon.conf # Carbon storage configuration
21+ │ ├── carbonapi.yml # CarbonAPI configuration
22+ │ └── README.md # Docker setup documentation
23+ ├── integration_e2e_reporter.rs # E2E tests with real Graphite
24+ ├── integration_health.rs # Service health integration tests
25+ ├── integration_api.rs # API integration tests
26+ └── documentation_validation.rs # Documentation validation tests
2127
2228src/
23- ├── common.rs # + #[cfg(test)] mod tests { 11 tests }
24- ├── types.rs # + #[cfg(test)] mod tests { 6 tests }
25- ├── config.rs # + #[cfg(test)] mod tests { 7 tests }
26- ├── graphite.rs # + #[cfg(test)] mod tests { 6 tests }
27- └── api/v1.rs # + #[cfg(test)] mod tests { 4 tests }
29+ ├── common.rs # + #[cfg(test)] mod tests { 11 tests }
30+ ├── types.rs # + #[cfg(test)] mod tests { 6 tests }
31+ ├── config.rs # + #[cfg(test)] mod tests { 7 tests }
32+ ├── graphite.rs # + #[cfg(test)] mod tests { 6 tests }
33+ └── api/v1.rs # + #[cfg(test)] mod tests { 4 tests }
2834```
2935
3036### Test Categories
3137
32381 . ** Unit Tests** : Located inline with source code using ` #[cfg(test)] ` modules
33392 . ** Integration Tests** : Located in ` tests/ ` directory for cross-module scenarios
34- 3 . ** Fixtures** : Shared test data and utilities in ` tests/fixtures/ `
40+ 3 . ** E2E Tests** : Full pipeline tests with real Docker containers
41+ 4 . ** Fixtures** : Shared test data and utilities in ` tests/fixtures/ `
3542
3643## Running Tests
3744
38- ### Run All Tests
45+ ### Run All Unit Tests
3946
4047``` bash
4148cargo test
@@ -50,7 +57,7 @@ cargo test common::tests
5057# Run only config tests
5158cargo test config::tests
5259
53- # Run only integration tests
60+ # Run only integration tests (excluding E2E)
5461cargo test --test integration_*
5562```
5663
@@ -72,6 +79,108 @@ cargo test -- --test-threads=4
7279cargo test -- --test-threads=1
7380```
7481
82+ ## E2E Integration Tests
83+
84+ The E2E tests (` integration_e2e_reporter.rs ` ) validate the complete metrics-processor pipeline using real Docker containers.
85+
86+ ### What They Test
87+
88+ - Metrics ingestion via Carbon protocol
89+ - Query processing via CarbonAPI
90+ - Health expression evaluation
91+ - Incident creation and severity assignment
92+ - Reporter log output format and content
93+
94+ ### Prerequisites
95+
96+ 1 . ** Docker** : Must be installed and running
97+ 2 . ** Available Ports** :
98+ - ` 2003 ` - Carbon plaintext protocol
99+ - ` 8080 ` - CarbonAPI query endpoint
100+ - ` 3005 ` - Convertor API
101+ - ` 9999 ` - Mock Status Dashboard
102+
103+ ### Running E2E Tests
104+
105+ ``` bash
106+ # Run E2E tests (Docker containers managed automatically)
107+ cargo test --test integration_e2e_reporter -- --ignored --nocapture
108+ ```
109+
110+ The test automatically:
111+ 1 . Restarts Docker containers to ensure clean state
112+ 2 . Builds convertor and reporter binaries
113+ 3 . Runs all 4 test scenarios
114+ 4 . Validates log output for each scenario
115+
116+ ### Test Scenarios
117+
118+ | Scenario | Weight | Condition | Expected Log |
119+ | ----------| --------| -----------| --------------|
120+ | ` healthy ` | 0 | All metrics OK | No incident log |
121+ | ` degraded_slow ` | 1 | Response time > 1200ms | ` matched_expression="...api_slow..." ` |
122+ | ` degraded_errors ` | 1 | Success rate < 65% | ` matched_expression="...api_success_rate_low..." ` |
123+ | ` outage ` | 2 | 100% failures | ` matched_expression="...api_down" ` |
124+
125+ ### E2E Test Architecture
126+
127+ ```
128+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
129+ │ Test Code │────▶│ go-carbon │────▶│ carbonapi │
130+ │(write data) │ │ (storage) │ │ (query) │
131+ └─────────────┘ └─────────────┘ └─────────────┘
132+ │
133+ ┌────────────────────────────────────────┘
134+ ▼
135+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
136+ │ Convertor │────▶│ Reporter │────▶│ Mock Status │
137+ │ (process) │ │ (alert) │ │ Dashboard │
138+ └─────────────┘ └─────────────┘ └─────────────┘
139+ │ │
140+ │ ▼
141+ │ ┌─────────────┐
142+ └────────────▶│ Log Output │◀── Test validates
143+ │ (stdout) │
144+ └─────────────┘
145+ ```
146+
147+ ### Data Isolation
148+
149+ Each scenario uses a unique service name (e.g., ` rms_healthy ` , ` rms_outage ` ) to prevent data pollution between scenarios. This allows sequential execution without clearing Graphite data.
150+
151+ ### E2E Troubleshooting
152+
153+ #### "Docker containers failed to start"
154+ ``` bash
155+ # Check Docker is running
156+ docker ps
157+
158+ # Check port availability
159+ lsof -i :2003 -i :8080 -i :3005 -i :9999
160+
161+ # Manually start containers
162+ cd tests/docker && docker compose up -d
163+ ```
164+
165+ #### "Convertor not ready after timeout"
166+ - The convertor may need more time to start
167+ - Check for port conflicts on 3005
168+ - Review convertor stderr output
169+
170+ #### "No incident log found"
171+ ``` bash
172+ # Verify Graphite received data
173+ curl ' http://localhost:8080/metrics/find?query=stats.*&format=json'
174+
175+ # Check go-carbon logs
176+ docker logs metrics-processor-go-carbon
177+ ```
178+
179+ #### "Log validation failed"
180+ - Verify expected expression matches the config
181+ - Check for ANSI escape codes (test strips them automatically)
182+ - Review the full log output in test output
183+
75184## Test Coverage
76185
77186### Measuring Coverage
0 commit comments