Repository navigation
feat(registry): migrate runtime service metadata - #2048
josecelano merged 9 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates the tracker’s runtime service registrations from torrust-server-lib 0.1.x raw registry access to torrust-server-lib 0.2.0’s immutable typed metadata and snapshot/query APIs, then updates health reporting and integration-test endpoint discovery to use canonical role/identity instead of bind-IP conventions or timing heuristics.
Changes:
- Upgrades workspace consumers to
torrust-server-lib = "0.2.0"and switches registrations toServiceRegistrationForm<RuntimeServiceMetadata>with acknowledgedregister().await. - Introduces
RuntimeServiceMetadata(derived role from canonicalConfigurationInstanceId) and propagates it through HTTP/UDP/REST/health registrations. - Reworks integration-test readiness and endpoint discovery helpers to wait for and query by canonical identities/roles (including new port-zero identity-to-final-binding coverage).
Reviewed changes
Copilot reviewed 35 out of 36 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/scaffold.rs | Updates test-module documentation to describe registry-ack readiness and snapshot-based endpoint discovery. |
| tests/common/workspace.rs | Replaces size/delay-based readiness and bind-IP endpoint classification with identity/role snapshot queries; adds service_binding_for_identity. |
| tests/common/mod.rs | Re-exports the new service_binding_for_identity helper. |
| tests/aggregate_stats_port_zero.rs | Adds regression test ensuring repeated port-zero instances retain canonical identity and resolve to distinct non-zero final bindings. |
| src/container.rs | Makes registar typed (Registar<RuntimeServiceMetadata>) and returns canonical identity alongside tracker containers. |
| src/bootstrap/jobs/udp_tracker.rs | Threads typed registration form + runtime metadata into UDP job startup. |
| src/bootstrap/jobs/tracker_apis.rs | Threads typed registration form + runtime metadata into REST API startup; updates unit test accordingly. |
| src/bootstrap/jobs/http_tracker.rs | Threads typed registration form + runtime metadata into HTTP tracker startup; updates unit test accordingly. |
| src/bootstrap/jobs/health_check_api.rs | Switches health API wiring from raw registry to typed Registar; registers health API metadata after bind/start. |
| src/app.rs | Propagates canonical ConfigurationInstanceId into runtime metadata at service startup; passes typed registar into health-check API job. |
| project-words.txt | Adds addext to the spell-check dictionary. |
| packages/udp-server/src/testing/environment.rs | Updates UDP server test environment to use typed registar + runtime metadata. |
| packages/udp-server/src/server/states.rs | Migrates UDP server registration from send(...) to acknowledged register(...).await with typed metadata. |
| packages/udp-server/src/server/mod.rs | Updates UDP server tests to use typed registar + runtime metadata. |
| packages/udp-server/src/server/launcher.rs | Adapts health-check job construction to torrust-server-lib 0.2.0 API. |
| packages/udp-server/Cargo.toml | Upgrades torrust-server-lib dependency to 0.2.0. |
| packages/primitives/src/runtime_service_metadata.rs | Adds new typed immutable metadata wrapper over ConfigurationInstanceId with derived role. |
| packages/primitives/src/lib.rs | Exposes the new runtime_service_metadata module and re-exports RuntimeServiceMetadata. |
| packages/axum-server/Cargo.toml | Upgrades torrust-server-lib dependency to 0.2.0. |
| packages/axum-rest-api-server/src/testing/environment.rs | Updates REST API test environment to pass typed metadata during registration. |
| packages/axum-rest-api-server/src/server.rs | Migrates REST API registration to typed metadata + acknowledged registration; adapts health-check job API. |
| packages/axum-rest-api-server/Cargo.toml | Upgrades torrust-server-lib dependency to 0.2.0. |
| packages/axum-http-server/src/testing/environment.rs | Updates HTTP server test environment to pass typed metadata during registration. |
| packages/axum-http-server/src/server.rs | Migrates HTTP tracker registration to typed metadata + acknowledged registration; adapts health-check job API. |
| packages/axum-http-server/Cargo.toml | Upgrades torrust-server-lib dependency to 0.2.0. |
| packages/axum-health-check-api-server/tests/server/contract.rs | Strengthens health JSON contract assertions to include service_binding and service_type compatibility. |
| packages/axum-health-check-api-server/src/server.rs | Switches server state from raw registry type to typed Registar<RuntimeServiceMetadata>. |
| packages/axum-health-check-api-server/src/handlers.rs | Builds reports from deterministic registry snapshots + metadata-derived service type, combining optional check execution results. |
| packages/axum-health-check-api-server/src/environment.rs | Updates health-check API test environment to use typed registar. |
| packages/axum-health-check-api-server/Cargo.toml | Adds torrust-tracker-primitives dep and upgrades torrust-server-lib to 0.2.0. |
| docs/issues/open/2041-migrate-runtime-service-registry-metadata/ISSUE.md | Updates implementation plan/progress and verification tracking for #2041. |
| docs/issues/open/2041-migrate-runtime-service-registry-metadata/evidence.md | Records automated/manual verification evidence for the migration, including port-zero scenarios. |
| docs/issues/drafts/fix-https-tracker-health-check-protocol.md | Adds a draft follow-up issue spec documenting the pre-existing HTTPS probe scheme mismatch. |
| Cargo.toml | Upgrades workspace torrust-server-lib dependency to 0.2.0. |
| Cargo.lock | Lockfile updates reflecting the torrust-server-lib 0.2.0 upgrade and resolved dependency graph changes. |
| .github/skills/dev/environment-setup/run-tracker-locally/SKILL.md | Documents a reusable local TLS workflow and notes the known aggregate HTTPS health-check limitation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2048 +/- ##
===========================================
+ Coverage 82.01% 82.10% +0.08%
===========================================
Files 348 348
Lines 24795 24828 +33
Branches 24795 24828 +33
===========================================
+ Hits 20336 20384 +48
+ Misses 4148 4139 -9
+ Partials 311 305 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 36 out of 37 changed files in this pull request and generated no new comments.
Suppressed comments (2)
tests/common/workspace.rs:139
http_api_urluses the canonicalServiceRole::RestApi, but it still constructs the client URL vialoopback_url(SocketAddr), which hard-codeshttp://. If the REST API is configured with TLS (HTTPS), this will return the wrong scheme and make tests/probes fail.
tests/common/workspace.rs:106http_tracker_urlsnow selects services byServiceRole::HttpTracker, which (per #2041 design) includes both HTTP and HTTPS registrations. Building URLs vialoopback_url(SocketAddr)hard-codes thehttp://scheme, so an HTTPS tracker would be returned ashttp://127.0.0.1:<tls-port>/...and clients/tests would probe the wrong protocol.
This issue also appears on line 135 of the same file.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 36 out of 37 changed files in this pull request and generated no new comments.
Suppressed comments (1)
.github/skills/dev/logging/structured-runtime-logging/SKILL.md:43
- The logging skill’s “Correct Form” example uses
%service_binding.url(), but the implementation in this PR logs theServiceBindingitself (e.g.,tracing::info!(service_binding = %service_binding, ...)). This makes the skill inconsistent with the codebase and also makes the example output below internally inconsistent.
Recommendation: adjust the example to log service_binding = %service_binding (and update the sample output accordingly, likely including the trailing / for HTTP URLs if that’s how ServiceBinding displays).
```rust
tracing::info!(
service_binding = %service_binding.url(),
"Started HTTP tracker"
);
|
ACK b0bc51e |
c2d865c docs(review): record PR 2061 suggestions audit (Jose Celano) f0ac4eb docs(review): address PR 2061 suggestions (Jose Celano) b1c4800 docs(issues): refine event metrics delivery plan (Jose Celano) Pull request description: ## Summary Refines the #2039 delivery plan before implementation. - Records risk-based manual verification checkpoints for the identity, metrics filtering, banning, and final application-integration changes. - Clarifies that #2039 producers publish policy-neutral facts independently of per-listener `tracker_usage_statistics`; metrics filtering belongs in consumers and UDP banning remains independent. - Updates #2035's remaining dependency and final-verification status after PR #2044 and PR #2048. - Adds a benchmark-led draft that investigates the cost and feasibility of disabling event publication only when every required consumer and counter is inactive. ## Validation - `linter all` - Pre-commit checks - Pre-push checks: nightly format/check/doc and stable all-target tests Related to #2039 and #2035. ACKs for top commit: josecelano: ACK c2d865c Tree-SHA512: d8f70d53bba891e6ad0f73d4064218e3fe7e295d7cf748fc70025a6ab8f9c4696f58f8db6e0b8898e9e99edfc9e18450874781f619e30fc1768186fbcc66dff0
da2ce7
left a comment
There was a problem hiding this comment.
This is a post-merge review of #2048 as its change stands at e170b96 on the default branch.
What still runs: RuntimeServiceMetadata (packages/primitives/src/runtime_service_metadata.rs) still derives the service role from its ConfigurationInstanceId, now with an optional configured public URL added later. Every listener still registers itself with that metadata. The HTTP and UDP trackers take their identity from the container tuple built at src/container.rs:206 and :232 and passed on at src/app.rs:643 and :710; the REST API and the health check API use fixed index-0 identities (src/app.rs:739, src/bootstrap/jobs/health_check_api.rs:56); and the health check handler takes service_type from the metadata role (packages/axum-health-check-api-server/src/handlers.rs:45). The integration helpers in tests/common/workspace.rs still wait on exact identities and discover endpoints by role. Three defects present at merge are already fixed and are history here: the registration expect panics became typed errors with listener cleanup (56ea123 and the token-aware start paths), the health handler no longer panics on a failed check job (52297a9), and HTTPS trackers are checked over TLS (45109d1).
[Minor] tests/common/workspace.rs:220 and :254 select HTTP trackers and the REST API by role, which since #2048 includes HTTPS listeners, but build each URL with loopback_url (tests/common/workspace.rs:323), which always writes http:// from the bare socket address. Before #2048 these helpers filtered on Protocol::HTTP, so a TLS listener was not returned at all. Now a suite that sets tls_config on an HTTP tracker or on the REST API gets http://127.0.0.1:<port>, and its first announce or API request fails with a connection error that points away from the helper. No root suite configures TLS at this commit, so the defect is latent. The smallest fix keeps the scheme of the registered binding: start from service.service_binding().url() and replace the host with 127.0.0.1 only when the bind address is unspecified. Alternatively, restore the protocol filter and document that HTTPS listeners are not discovered.
[Nit] The REST API and health check API identities are literals written in two places each: ConfigurationInstanceId::new(ServiceRole::RestApi, 0) at src/app.rs:739 and tests/common/workspace.rs:310, and ConfigurationInstanceId::new(ServiceRole::HealthCheckApi, 0) at src/bootstrap/jobs/health_check_api.rs:56 and tests/common/workspace.rs:313. Unlike the tracker identities, they are not read from the container. A change at one site, for example to support a second API block, leaves start_tracker_with_config waiting its full 10 seconds for an identity that never registers, and its timeout message does not name the missing identity. One named constructor or constant in packages/primitives (or an AppContainer accessor), used by both the starter and the helper, removes the drift.
[Nit] The servers accept any RuntimeServiceMetadata and register it unchecked (packages/axum-http-server/src/server.rs:243, packages/udp-server/src/server/states.rs:124, packages/axum-rest-api-server/src/server.rs:144, packages/axum-health-check-api-server/src/server.rs:122). As the description says, the type keeps the role consistent with the identity, but nothing ties it to the listener that registers it. A caller that passes a UDP identity to HttpServer::start_with_cancellation registers an HTTP listener that the health report labels udp_tracker and that the role-based helpers return as a UDP tracker. Every call site at this commit passes the matching role. A debug_assert_eq!(metadata.service_role(), ServiceRole::HttpTracker), with the equivalent assertion in each other server, at the top of each start path would state the contract at the point that relies on it.
Checked and found sound: role derivation and accessors in runtime_service_metadata.rs; the pairing of each tracker identity with its own container (src/container.rs:155-174, src/app.rs:629-711); health report compatibility (service_binding, binding, info, result, and service_type strings equal to ServiceRole::as_str); the health check API's own registration, which carries no check and so stays out of the report; registration-failure cleanup in all four start paths; the readiness wait in start_tracker_with_config, which passes on its first iteration because each starter awaits registration before it returns; and the identity lookups used by the port-zero, UDP error and banning suites.
Summary
Migrates tracker runtime service registrations to
torrust-server-lib0.2.0 immutable typed metadata and deterministic snapshot queries.ConfigurationInstanceIdthrough HTTP(S), UDP, REST API, and health API registrations.RuntimeServiceMetadataroles from the canonical identity, preventing mismatched role/identity state.Validation
TORRUST_GIT_HOOKS_LOG_DIR=.tmp ./contrib/dev-tools/git/hooks/pre-commit.shFollow-up
A draft issue documents the pre-existing aggregate HTTPS health-check protocol defect separately. It is out of scope for this registry-metadata migration.
Closes #2041