feat(metrics): API metrics on a private listener; HA and observability design (#60) #164

Merged
amiryahaya merged 4 commits from feat/api-metrics-60 into main 2026-11-05 16:54:17 +01:00
Owner

Part of #60 (step 1 of docs/05-observability.md), with the HA setup (#57, #58) and observability design documents.

What

  • internal/metrics: Prometheus metrics for the API: requests by route pattern and status, duration histogram, in-flight, the pgx pool, Go runtime and process.
  • Served only on a private listener KWS_METRICS_ADDR (host:port; unset = off; refused if every interface or equal to the public address). If it cannot bind, the API logs and keeps serving.
  • httpapi.WithMiddleware; problemFallback now sets r.Pattern, so the route is known through the cache and the gate.
  • Labels are route patterns only: tests prove no uuid, M-Pesa token or ticket code reaches the output.
  • Docs: docs/04-ha-setup.md, docs/05-observability.md, ADR 0036, CLAUDE.md.

Checks

  • make lint clean. make cover: 91.4% (minimum 80%).
  • New tests: metrics (labels, secrets, panic as 500, pool), httpapi (pattern through a copying route middleware and the gate; fails without the fix), config, app (private listener; API survives a taken metrics port).
  • Dual-pass review done: no must-fix or critical; the Important and Should fix items were addressed.
  • New dependency: prometheus/client_golang v1.25.0 (govulncheck clean); x/oauth2 bumped 0.36.0 to 0.37.0.

Not in this PR: business counters, worker job counters, monitoring Compose files, alert rules, runbook (steps 2 to 6).

🤖 Generated with Claude Code

Part of #60 (step 1 of docs/05-observability.md), with the HA setup (#57, #58) and observability design documents. ## What - `internal/metrics`: Prometheus metrics for the API: requests by route pattern and status, duration histogram, in-flight, the pgx pool, Go runtime and process. - Served only on a private listener `KWS_METRICS_ADDR` (host:port; unset = off; refused if every interface or equal to the public address). If it cannot bind, the API logs and keeps serving. - `httpapi.WithMiddleware`; `problemFallback` now sets `r.Pattern`, so the route is known through the cache and the gate. - Labels are route patterns only: tests prove no uuid, M-Pesa token or ticket code reaches the output. - Docs: `docs/04-ha-setup.md`, `docs/05-observability.md`, ADR 0036, CLAUDE.md. ## Checks - `make lint` clean. `make cover`: **91.4%** (minimum 80%). - New tests: metrics (labels, secrets, panic as 500, pool), httpapi (pattern through a copying route middleware and the gate; fails without the fix), config, app (private listener; API survives a taken metrics port). - Dual-pass review done: no must-fix or critical; the Important and Should fix items were addressed. - New dependency: `prometheus/client_golang` v1.25.0 (govulncheck clean); `x/oauth2` bumped 0.36.0 to 0.37.0. Not in this PR: business counters, worker job counters, monitoring Compose files, alert rules, runbook (steps 2 to 6). 🤖 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>
fix(metrics): refuse a wildcard metrics host, keep serving if it cannot bind, pin route and secret label tests (#60)
All checks were successful
ci / changes (pull_request) Successful in 19s
ci / clients (pull_request) Has been skipped
ci / web-ticket (pull_request) Has been skipped
ci / web-admin (pull_request) Has been skipped
ci / web-partner (pull_request) Has been skipped
ci / api (pull_request) Successful in 11m27s
ci / ci-gate (pull_request) Successful in 3s
7532acacb4
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!164
No description provided.