Add dependency-aware health, operator detail and redacted telemetry (F07, #12) #54

Merged
amiryahaya merged 9 commits from feat/12-health-telemetry into main 2026-10-25 12:26:53 +01:00
Owner

Refs #12 (F07).

What this adds

  • Health: a starting / ready / draining lifecycle and a registry of dependency checks, each bounded to 1 s (readiness to 2 s). Public /health/live is unchanged. /health/ready returns only status and one of four reason codes: ready, starting, draining, dependency_unavailable. Postgres is the only registered dependency today.
  • Operator detail: GET /admin/health/detail, behind the existing administrator check (401 without a session, 403 for non-administrators or a stale re-authentication, no-store). It shows per-dependency status and latency.
  • Telemetry: JSON logs with UTC time, severity, component, event, build and request ID. A server-minted UUIDv7 request ID is returned in x-request-id and is the same ID used for audit correlation. Logs carry the route template, never the raw path, query, cookies, headers, body or a client-supplied method. A PhaseTimer is the interface for later phase timing.
  • Shutdown: draining is set first, then a fixed 3 s grace before the pool refuses work, so probes can see 503 draining.
  • Docs: docs/operations/health.md.

Not in this PR

  • Metrics and trace endpoints (#33). Qdrant, model, identity and policy dependencies register when those capabilities exist.
  • Defaults (1 s bounds, 3 s grace, reason codes) were chosen without integration requirements and should be revisited when those exist.
  • Enforcer::resource / search_scope decision rows carry a per-call id while their failure rows carry the request id. No route calls them yet; R02 must reconcile this.

Verification

  • cargo fmt --check, cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
  • cargo test --workspace --locked: 191 passed, 0 failed.
  • bash scripts/test-postgres.sh --local: 234 passed, 0 failed (includes real database loss/recovery via ALLOW_CONNECTIONS + pg_terminate_backend, draining, stale administrator). One run hit the known flaky audit_postgres concurrent-append test; it passed 3/3 alone and on re-run.
  • Coverage: bash scripts/coverage.sh rust = 93.61% total lines (minimum 80%); health.rs 95.61%, telemetry.rs 94.64%.
  • Review: dual pass (ponytail complexity, then correctness); Pass 2 found three Important issues (draining never visible, client-controlled method in logs, coverage script missing the new suite), all fixed and re-checked by both passes.

🤖 Generated with Claude Code

Refs #12 (F07). ## What this adds - **Health:** a starting / ready / draining lifecycle and a registry of dependency checks, each bounded to 1 s (readiness to 2 s). Public `/health/live` is unchanged. `/health/ready` returns only `status` and one of four reason codes: `ready`, `starting`, `draining`, `dependency_unavailable`. Postgres is the only registered dependency today. - **Operator detail:** `GET /admin/health/detail`, behind the existing administrator check (401 without a session, 403 for non-administrators or a stale re-authentication, `no-store`). It shows per-dependency status and latency. - **Telemetry:** JSON logs with UTC time, severity, component, event, build and request ID. A server-minted UUIDv7 request ID is returned in `x-request-id` and is the same ID used for audit correlation. Logs carry the route template, never the raw path, query, cookies, headers, body or a client-supplied method. A `PhaseTimer` is the interface for later phase timing. - **Shutdown:** `draining` is set first, then a fixed 3 s grace before the pool refuses work, so probes can see `503 draining`. - Docs: `docs/operations/health.md`. ## Not in this PR - Metrics and trace endpoints (#33). Qdrant, model, identity and policy dependencies register when those capabilities exist. - Defaults (1 s bounds, 3 s grace, reason codes) were chosen without integration requirements and should be revisited when those exist. - `Enforcer::resource` / `search_scope` decision rows carry a per-call id while their failure rows carry the request id. No route calls them yet; R02 must reconcile this. ## Verification - `cargo fmt --check`, `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. - `cargo test --workspace --locked`: 191 passed, 0 failed. - `bash scripts/test-postgres.sh --local`: 234 passed, 0 failed (includes real database loss/recovery via `ALLOW_CONNECTIONS` + `pg_terminate_backend`, draining, stale administrator). One run hit the known flaky `audit_postgres` concurrent-append test; it passed 3/3 alone and on re-run. - **Coverage:** `bash scripts/coverage.sh rust` = **93.61%** total lines (minimum 80%); `health.rs` 95.61%, `telemetry.rs` 94.64%. - Review: dual pass (ponytail complexity, then correctness); Pass 2 found three Important issues (draining never visible, client-controlled method in logs, coverage script missing the new suite), all fixed and re-checked by both passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Enforcer::begin, the decision-row fallback and admin change correlation
now reuse the request_layer ID when inside a request, so x-request-id
matches the audit correlation. Outside a request a fresh UUIDv7 is
minted as before; per-permits-call context IDs stay fresh.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(health): drain grace, method allowlist, simpler Health wiring (#12)
All checks were successful
CI / Web checks (pull_request) Successful in 37s
CI / Web checks (push) Successful in 1m17s
CI / Rust checks (pull_request) Successful in 15m54s
CI / Rust checks (push) Successful in 24m14s
ffa67a2581
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.