How are health, logs, and metrics exposed and collected? #58

Closed
opened 2026-11-23 16:05:25 -05:00 by bobby · 7 comments
Owner

Part of #44

Question

What health endpoints does hAPI expose (liveness, readiness, dependency checks) and how does the external Uptime Kuma reach them (pull over which network, or push monitors)? Which stack collects logs and basic metrics, where does it run, and how is it accessed?

Part of #44 ## Question What health endpoints does hAPI expose (liveness, readiness, dependency checks) and how does the external Uptime Kuma reach them (pull over which network, or push monitors)? Which stack collects logs and basic metrics, where does it run, and how is it accessed?
bobby added the wayfinder:grilling label 2026-11-23 16:05:25 -05:00
bobby added a new dependency 2026-11-23 16:05:35 -05:00
bobby added a new dependency 2026-11-23 16:05:35 -05:00
Author
Owner

Inputs from Which libraries and conventions form the FastAPI app skeleton?: the app emits structlog JSON to stdout with request_id/principal_id bound and Personal data redacted; /healthz and /readyz sit outside /v1; one uvicorn process per pod.

Inputs from [Which libraries and conventions form the FastAPI app skeleton?](https://git.bobbypalko.com/bobby/hapi/issues/51#issuecomment-196): the app emits structlog JSON to stdout with `request_id`/`principal_id` bound and Personal data redacted; `/healthz` and `/readyz` sit outside `/v1`; one uvicorn process per pod.
Author
Owner

Constraint from How is hAPI reachable on the network? (ADR-0002): there are no anonymous public endpoints, so Uptime Kuma probes as a Bot with a health-only scope (token in a custom header). Metrics and detailed health are never public.

Constraint from [How is hAPI reachable on the network?](https://git.bobbypalko.com/bobby/hapi/issues/45) ([ADR-0002](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0002-network-exposure.md)): there are no anonymous public endpoints, so Uptime Kuma probes as a **Bot with a health-only scope** (token in a custom header). Metrics and detailed health are never public.
Author
Owner

Input from How does hAPI connect to its managed database? (#53, ADR-0004): hapi db breakglass emits structured audit events (start, end, reason, every statement, never results) to centralized logs. The platform has no DB statement logging, so the log pipeline is the only audit trail. Its retention and tamper-resistance matter for these events.

Input from **How does hAPI connect to its managed database?** (#53, [ADR-0004](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0004-database-access.md)): `hapi db breakglass` emits structured audit events (start, end, reason, every statement, never results) to centralized logs. The platform has no DB statement logging, so the log pipeline is the only audit trail. Its retention and tamper-resistance matter for these events.
Author
Owner

Note from How do Principals authenticate, and what may each do? (ADR-0005): Uptime Kuma is a Bot holding the health Scope, and ADR-0002 allows no anonymous public endpoints. This ticket needs to square that with kubelet liveness and readiness probes, for example by serving probes on a separate internal port that the Gateway never routes.

Note from [How do Principals authenticate, and what may each do?](https://git.bobbypalko.com/bobby/hapi/issues/54) (ADR-0005): Uptime Kuma is a Bot holding the `health` Scope, and ADR-0002 allows no anonymous public endpoints. This ticket needs to square that with kubelet liveness and readiness probes, for example by serving probes on a separate internal port that the Gateway never routes.
Author
Owner

Input from Which bridge carries jobs to Home Assistant? (ADR-0006): hAPI records the time of Home Assistant's last poll of GET /v1/smart_home/jobs/next (normally every 15–30 s). This ticket decides whether and how that becomes a health signal, e.g. a Kuma check that fails when there's been no poll for 5 min.

Input from [Which bridge carries jobs to Home Assistant?](https://git.bobbypalko.com/bobby/hapi/issues/55) (ADR-0006): hAPI records the time of Home Assistant's last poll of `GET /v1/smart_home/jobs/next` (normally every 15–30 s). This ticket decides whether and how that becomes a health signal, e.g. a Kuma check that fails when there's been no poll for 5 min.
Author
Owner

Inputs from How do code changes reach the cluster? (#56, ADR-0007): log, metrics, and health components arrive as Flux HelmReleases under deploy/infrastructure. Flux exposes its own reconcile metrics and conditions. Failed migrate Jobs and stalled rollouts are among the deploy failures worth surfacing, and alerting on them goes to ntfy (see the Notifications fog on the map).

Inputs from **How do code changes reach the cluster?** (#56, [ADR-0007](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0007-flux-pull-delivery.md)): log, metrics, and health components arrive as Flux `HelmRelease`s under `deploy/infrastructure`. Flux exposes its own reconcile metrics and conditions. Failed migrate Jobs and stalled rollouts are among the deploy failures worth surfacing, and alerting on them goes to ntfy (see the Notifications fog on the map).
bobby self-assigned this 2026-11-24 15:20:26 -05:00
Author
Owner

Resolution

Recorded as ADR-0009.

  • Ports: :8000 serves the API and is the only port the Gateway routes. :8081 is internal, never routed, and limited by NetworkPolicy to kubelet and the scraper. It serves /livez, /readyz and /metrics without auth, from the same process and event loop as the API. This replaces the skeleton's public /healthz//readyz (from Which libraries and conventions form the FastAPI app skeleton?).
  • Probes: /livez returns a constant (it proves the loop is turning). /readyz means startup is done and does not check the DB. On SIGTERM, readiness fails first, then about 5 s of drain.
  • External health: GET /v1/health needs the health Scope and returns ok, degraded or down with only check names and ok/fail. Critical checks are db and schema; if either fails, the status is down with HTTP 503. Non-critical checks are ha_bridge (no HA poll for 5 min) and job_backlog; if one fails, the status is degraded with HTTP 200. Uptime Kuma, a Bot on its own public VM, runs two monitors: up (HTTP status) and healthy (JSON query status == "ok").
  • Stack: VictoriaMetrics and VictoriaLogs (single-node) in a monitoring namespace on Block Storage PVs, delivered by Flux. vmagent scrapes the app, kubelet/cAdvisor, kube-state-metrics, node-exporter, Flux and Cilium. Vector takes pod logs and Talos machine.logging, and an event exporter ships Kubernetes Events.
  • App metrics come from prometheus-client: route template, status, latency, pool usage, Jobs, HA poll age and auth failures. There is no principal_id or Personal data in labels.
  • Retention: 30 days for logs and metrics, 1 year for breakglass audit events. Tamper-evidence is a Household ntfy alert per breakglass; there's no write-once storage in v1.
  • Access: self-hosted Grafana with login required, via kubectl port-forward over the management tailnet. Telemetry and update checks are off, and plugins are pinned. Outbound traffic from monitoring is denied except vmalert → ntfy and the Watchdog → Kuma push.
  • Alert owners: Kuma owns reachability and degraded status. Flux notification-controller owns reconciles, migrate Jobs and rollouts. vmalert owns PVs, crash loops, the DB pool, Jobs and nodes. An always-firing Watchdog pushes to a Kuma push monitor, so a dead monitoring stack is caught from outside. The push URL is a SOPS secret.

Left to implementation: the job_backlog threshold and the exact vmalert rules. ntfy topics, routing and auth remain in the Notifications fog.

## Resolution Recorded as [ADR-0009](https://git.bobbypalko.com/bobby/hapi/src/branch/main/docs/adr/0009-observability.md). - **Ports:** `:8000` serves the API and is the only port the Gateway routes. `:8081` is internal, never routed, and limited by NetworkPolicy to kubelet and the scraper. It serves `/livez`, `/readyz` and `/metrics` without auth, from the same process and event loop as the API. This **replaces the skeleton's public `/healthz`/`/readyz`** (from *Which libraries and conventions form the FastAPI app skeleton?*). - **Probes:** `/livez` returns a constant (it proves the loop is turning). `/readyz` means startup is done and does **not** check the DB. On SIGTERM, readiness fails first, then about 5 s of drain. - **External health:** `GET /v1/health` needs the `health` Scope and returns `ok`, `degraded` or `down` with only check names and `ok`/`fail`. Critical checks are `db` and `schema`; if either fails, the status is `down` with HTTP 503. Non-critical checks are `ha_bridge` (no HA poll for 5 min) and `job_backlog`; if one fails, the status is `degraded` with HTTP 200. Uptime Kuma, a Bot on its own public VM, runs two monitors: *up* (HTTP status) and *healthy* (JSON query `status == "ok"`). - **Stack:** VictoriaMetrics and VictoriaLogs (single-node) in a `monitoring` namespace on Block Storage PVs, delivered by Flux. vmagent scrapes the app, kubelet/cAdvisor, kube-state-metrics, node-exporter, Flux and Cilium. Vector takes pod logs and Talos `machine.logging`, and an event exporter ships Kubernetes Events. - **App metrics** come from `prometheus-client`: route template, status, latency, pool usage, Jobs, HA poll age and auth failures. There is no `principal_id` or Personal data in labels. - **Retention:** 30 days for logs and metrics, 1 year for breakglass audit events. Tamper-evidence is a Household ntfy alert per breakglass; there's no write-once storage in v1. - **Access:** self-hosted Grafana with login required, via `kubectl port-forward` over the management tailnet. Telemetry and update checks are off, and plugins are pinned. Outbound traffic from `monitoring` is denied except vmalert → ntfy and the Watchdog → Kuma push. - **Alert owners:** Kuma owns reachability and degraded status. Flux notification-controller owns reconciles, migrate Jobs and rollouts. vmalert owns PVs, crash loops, the DB pool, Jobs and nodes. An always-firing Watchdog pushes to a Kuma push monitor, so a dead monitoring stack is caught from outside. The push URL is a SOPS secret. Left to implementation: the `job_backlog` threshold and the exact vmalert rules. ntfy topics, routing and auth remain in the Notifications fog.
bobby closed this issue 2026-11-24 15:52:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: bobby/hapi#58