Skip to content

[T-004b] Prometheus metrics registry and health-check helpers #24

Closed

Description

@CodewithJha

Task T-004b · Milestone M1 — Foundation · Size S · Priority P1 · Epic #1

Implements NFR-OBS-001

Branch feat/t-004b-prometheus-metrics-registry-and-health — one task = one branch = one PR (doc 32 §6)

Summary

Define every metric of doc 21 §5.2 in one registry module and provide reusable liveness/readiness helpers used later by API, orchestrator and workers.

Context / motivation

Defining metrics centrally avoids duplicate registrations and inconsistent label sets when several services are built in parallel.

Scope

In scope

  • backend/src/roboprobe/core/metrics_registry.py with roboprobe_runs_total, roboprobe_run_duration_seconds, roboprobe_queue_depth, roboprobe_workers, roboprobe_selector_propose_seconds, roboprobe_gp_fit_seconds, roboprobe_episode_rtf, roboprobe_infra_errors_total, roboprobe_api_request_duration_seconds (types + labels exactly per doc 21 §5.2).
  • Histogram buckets as settings? → bucket boundaries are module constants documented as instrumentation constants (allowed) or settings keys — pick settings if any service needs overrides; document the choice.
  • backend/src/roboprobe/core/health.py: HealthCheck protocol, HealthReport model, run_checks(checks) -> HealthReport; tiny internal HTTP server helper serve_health(port, checks, registry) for workers/orchestrator (/healthz + /metrics).
  • observability.metrics_enabled=false ⇒ no-op registry (Null Object).

Out of scope

  • API /metrics route (T-080a)
  • Grafana profile (T-125)

Implementation guidance

  • Use a dedicated CollectorRegistry (not the global default) passed via DI so tests are isolated. Health server: http.server.ThreadingHTTPServer in a daemon thread; port from worker.health_port.
  • Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff PLR2004); public APIs typed (mypy strict) and documented.

Configuration keys

From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).

  • observability.metrics_enabled
  • worker.health_port

Acceptance criteria

  • All metrics of doc 21 §5.2 registered with exact names/labels.
  • /healthz returns 200 when all checks pass, 503 with JSON details otherwise.
  • Disabled metrics produce no registry output and no errors.
  • Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
  • Docs, config reference and CHANGELOG Unreleased updated where behaviour, keys or interfaces changed.
  • Definition of Done (doc 32 §3) satisfied.

Tests required

  • tests/unit/core/test_metrics_registry.py, test_health.py (spin server on ephemeral port).

Dependencies

Blocked by: #19 (T-003a)

Blocks: #142 (T-080a), #214 (T-125)

Parallelization notes

Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:

  • backend/src/roboprobe/core/metrics_registry.py
  • backend/src/roboprobe/core/health.py
  • backend/tests/unit/core/test_metrics_registry.py
  • backend/tests/unit/core/test_health.py

Independent of T-004a.

Definition of Done

Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-004b (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.

References

Design docs: doc 21 §5.2 · doc 21 §5.4 · doc 34 §4

Requirements: NFR-OBS-001 (traceability: doc 28)

External:

Activity

  1. added this to the M1 — Foundation milestone on Nov 19, 2026
  2. added
    area:coreDomain core, plugin registry, shared types
    priority:P1Required for milestone exit
    taskChild task of a milestone epic
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreDomain core, plugin registry, shared typesarea:observabilityLogging, metrics, tracingmilestone:M1M1 — Foundationpriority:P1Required for milestone exitsize:S<= 1 daytaskChild task of a milestone epictype:featureNew functionality

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions