|
| 1 | +# Fix HTTP Tracker Health Check Endpoint |
| 2 | + |
| 3 | +**Issue**: #224 |
| 4 | +**Parent Epic**: #216 - Release and Run Commands |
| 5 | +**Related**: #220 - Tracker Slice Release and Run Commands |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +The HTTP tracker health check validation is using the wrong endpoint URL (`/api/health_check`) and producing warnings instead of errors when validation fails. The correct endpoint is `/health_check` (without the `/api` prefix), and validation failures should be treated as errors to ensure proper deployment validation. |
| 10 | + |
| 11 | +## Goals |
| 12 | + |
| 13 | +- [x] Fix HTTP tracker health check endpoint URL from `/api/health_check` to `/health_check` |
| 14 | +- [x] Convert HTTP tracker validation warnings to errors (make it a required check) |
| 15 | +- [x] Include the attempted URL in error messages for better debugging |
| 16 | +- [x] Update documentation to reflect the correct endpoint and validation behavior |
| 17 | + |
| 18 | +## 🏗️ Architecture Requirements |
| 19 | + |
| 20 | +**DDD Layer**: Infrastructure |
| 21 | +**Module Path**: `src/infrastructure/external_validators/` |
| 22 | +**Pattern**: External Validator (Remote Action) |
| 23 | + |
| 24 | +### Module Structure Requirements |
| 25 | + |
| 26 | +- [x] Follow DDD layer separation (see [docs/codebase-architecture.md](../docs/codebase-architecture.md)) |
| 27 | +- [x] Respect dependency flow rules (infrastructure can depend on domain) |
| 28 | +- [x] Use appropriate module organization (see [docs/contributing/module-organization.md](../docs/contributing/module-organization.md)) |
| 29 | + |
| 30 | +### Architectural Constraints |
| 31 | + |
| 32 | +- [x] External validators run from test runner/deployment machine (not via SSH) |
| 33 | +- [x] Error handling follows project conventions (see [docs/contributing/error-handling.md](../docs/contributing/error-handling.md)) |
| 34 | +- [x] Validation failures must be actionable with clear troubleshooting steps |
| 35 | + |
| 36 | +### Anti-Patterns to Avoid |
| 37 | + |
| 38 | +- ❌ Using warnings for required validation checks |
| 39 | +- ❌ Generic error messages without context (e.g., missing attempted URL) |
| 40 | +- ❌ Incorrect endpoint URLs that don't match actual service endpoints |
| 41 | + |
| 42 | +## Specifications |
| 43 | + |
| 44 | +### Current Issue |
| 45 | + |
| 46 | +The HTTP tracker health check in `src/infrastructure/external_validators/running_services.rs` has two problems: |
| 47 | + |
| 48 | +1. **Wrong URL**: Uses `/api/health_check` but should use `/health_check` |
| 49 | +2. **Warning vs Error**: Logs warnings on failure instead of returning errors |
| 50 | + |
| 51 | +```rust |
| 52 | +// Current (incorrect) implementation |
| 53 | +let url = format!("http://{server_ip}:{port}/api/health_check"); |
| 54 | +// ... logs warning on failure, doesn't propagate error |
| 55 | +``` |
| 56 | + |
| 57 | +### Expected Behavior |
| 58 | + |
| 59 | +```rust |
| 60 | +// Correct implementation |
| 61 | +let url = format!("http://{server_ip}:{port}/health_check"); |
| 62 | +let response = reqwest::get(&url).await.map_err(|e| { |
| 63 | + RemoteActionError::ValidationFailed { |
| 64 | + action_name: self.name().to_string(), |
| 65 | + message: format!( |
| 66 | + "HTTP Tracker external health check failed for URL '{url}': {e}. \n\ |
| 67 | + Check that HTTP tracker is running and firewall allows port {port}." |
| 68 | + ), |
| 69 | + } |
| 70 | +})?; |
| 71 | + |
| 72 | +if !response.status().is_success() { |
| 73 | + return Err(RemoteActionError::ValidationFailed { |
| 74 | + action_name: self.name().to_string(), |
| 75 | + message: format!( |
| 76 | + "HTTP Tracker returned HTTP {} for URL '{url}': {}. Service may not be healthy.", |
| 77 | + response.status(), |
| 78 | + response.status().canonical_reason().unwrap_or("Unknown") |
| 79 | + ), |
| 80 | + }); |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Affected Files |
| 85 | + |
| 86 | +1. **`src/infrastructure/external_validators/running_services.rs`** |
| 87 | + |
| 88 | + - Fix URL in `check_http_tracker_external` method |
| 89 | + - Change return type from `()` to `Result<(), RemoteActionError>` |
| 90 | + - Convert warning logs to error returns with URL context |
| 91 | + |
| 92 | +2. **`docs/user-guide/commands/run.md`** |
| 93 | + |
| 94 | + - Update HTTP tracker health check endpoint documentation |
| 95 | + - Change status from "optional" to "required" |
| 96 | + |
| 97 | +3. **`docs/console-commands.md`** |
| 98 | + |
| 99 | + - Update health check endpoint documentation |
| 100 | + |
| 101 | +4. **`src/application/command_handlers/test/handler.rs`** |
| 102 | + - Update documentation comments to reflect correct endpoint |
| 103 | + |
| 104 | +## Implementation Plan |
| 105 | + |
| 106 | +### Phase 1: Fix HTTP Tracker Health Check Method (15 minutes) |
| 107 | + |
| 108 | +- [x] Update `check_http_tracker_external` method URL to use `/health_check` |
| 109 | +- [x] Change return type from `()` to `Result<(), RemoteActionError>` |
| 110 | +- [x] Add URL to error messages for debugging |
| 111 | +- [x] Update `validate_external_accessibility` to propagate errors with `?` operator |
| 112 | + |
| 113 | +### Phase 2: Update Documentation (10 minutes) |
| 114 | + |
| 115 | +- [x] Update module documentation header to reflect correct endpoint |
| 116 | +- [x] Update `docs/user-guide/commands/run.md` endpoint URL |
| 117 | +- [x] Update `docs/console-commands.md` health check description |
| 118 | +- [x] Update `src/application/command_handlers/test/handler.rs` comments |
| 119 | + |
| 120 | +### Phase 3: Testing and Verification (10 minutes) |
| 121 | + |
| 122 | +- [x] Run pre-commit checks: `./scripts/pre-commit.sh` |
| 123 | +- [x] Verify linting passes (especially clippy and rustfmt) |
| 124 | +- [ ] Run manual E2E test to verify HTTP tracker health check works |
| 125 | +- [ ] Confirm error messages display the attempted URL |
| 126 | + |
| 127 | +## Acceptance Criteria |
| 128 | + |
| 129 | +> **Note for Contributors**: These criteria define what the PR reviewer will check. Use this as your pre-review checklist before submitting the PR to minimize back-and-forth iterations. |
| 130 | +
|
| 131 | +**Quality Checks**: |
| 132 | + |
| 133 | +- [x] Pre-commit checks pass: `./scripts/pre-commit.sh` |
| 134 | + |
| 135 | +**Task-Specific Criteria**: |
| 136 | + |
| 137 | +- [x] HTTP tracker health check uses `/health_check` endpoint (not `/api/health_check`) |
| 138 | +- [x] Validation failures return errors instead of logging warnings |
| 139 | +- [x] Error messages include the attempted URL for debugging |
| 140 | +- [x] `check_http_tracker_external` returns `Result<(), RemoteActionError>` |
| 141 | +- [x] `validate_external_accessibility` properly propagates HTTP tracker errors |
| 142 | +- [x] Documentation accurately reflects the correct endpoint URL |
| 143 | +- [x] Documentation describes HTTP tracker check as "required" not "optional" |
| 144 | +- [ ] Manual E2E test confirms health check works with deployed tracker |
| 145 | + |
| 146 | +## Related Documentation |
| 147 | + |
| 148 | +- [docs/codebase-architecture.md](../codebase-architecture.md) - Project architecture |
| 149 | +- [docs/contributing/error-handling.md](../contributing/error-handling.md) - Error handling conventions |
| 150 | +- [docs/user-guide/commands/run.md](../user-guide/commands/run.md) - Run command documentation |
| 151 | +- [src/infrastructure/external_validators/running_services.rs](../../src/infrastructure/external_validators/running_services.rs) - Implementation file |
| 152 | + |
| 153 | +## Notes |
| 154 | + |
| 155 | +### Why This Fix Is Important |
| 156 | + |
| 157 | +1. **Correct Endpoint**: The Torrust Tracker HTTP tracker exposes health checks at `/health_check`, not `/api/health_check`. Using the wrong endpoint causes all validations to fail with 404 errors. |
| 158 | + |
| 159 | +2. **Error Visibility**: Converting warnings to errors ensures that deployment failures are properly reported and CI/CD pipelines can detect issues. Warnings can be easily missed in logs. |
| 160 | + |
| 161 | +3. **Debugging Support**: Including the attempted URL in error messages helps developers quickly identify configuration issues or endpoint mismatches. |
| 162 | + |
| 163 | +### Verification Steps |
| 164 | + |
| 165 | +After implementation, verify with: |
| 166 | + |
| 167 | +```bash |
| 168 | +# Run pre-commit checks |
| 169 | +./scripts/pre-commit.sh |
| 170 | + |
| 171 | +# Deploy tracker and test health check |
| 172 | +cargo run -- create e2e-test --env-file envs/e2e-test.json |
| 173 | +cargo run -- provision e2e-test |
| 174 | +cargo run -- configure e2e-test |
| 175 | +cargo run -- release e2e-test |
| 176 | +cargo run -- run e2e-test # Should succeed without warnings |
| 177 | + |
| 178 | +# Manual health check test |
| 179 | +INSTANCE_IP=$(cat data/e2e-test/environment.json | jq -r '.Running.context.runtime_outputs.instance_ip') |
| 180 | +curl http://$INSTANCE_IP:7070/health_check # Should return success |
| 181 | +``` |
0 commit comments