Files
archie/internal/webui/api_health.go
T
sam 6af0d51459 feat(webui): add /health and /health/detailed readiness endpoints (#717)
* feat(webui): add /health and /health/detailed readiness endpoints (archie-core-1786637496789-265-b052b772)

Implements the Operations: readiness probes bead from the hermes gap analysis
(docs/prds/hermes-gap-analysis.md sections 9-10).

- GET /health: liveness, no auth, always 200 ok.
- GET /health/detailed: authenticated (dashboard token), JSON report with
  overall ok/degraded status plus per-subsystem probe results.

New readiness probes, each reporting real current state:
- state_db: read-only StatusCounts against the store.
- config: configuration.Validate against the running config.
- disk: statfs, degraded above 90% used.
- model: active model configured + provider endpoint reachable.
- gateway: channel running/failed state + connected session count.

Layering: probe contract in internal/domain/health, implementations in
internal/infrastructure/readiness, wiring in internal/app/archied,
HTTP surface in internal/webui.

* no-mistakes(document): docs(archied): fix stale doc pointer in readiness probe comment
2026-09-05 13:25:04 +10:00

32 lines
1.4 KiB
Go

package webui
import "net/http"
// handleHealth is a liveness probe: the process is up and able to serve a
// request. It deliberately bypasses requireToken, like /healthz -- a local
// orchestration tool (systemd, a watchdog, a container healthcheck) must be
// able to ask "is the process alive?" without the dashboard token. It does no
// subsystem work and always answers 200 when the process can respond at all.
func (s *Server) handleHealth(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
}
// handleHealthDetailed is the authenticated readiness surface. It runs every
// registered readiness probe and returns each subsystem's live result plus
// the overall rollup, so an operator can see exactly which subsystem is
// degraded rather than only that the daemon is unhealthy.
//
// It requires the dashboard token (and is mounted behind requireToken) because
// it exposes real subsystem state -- a remote caller should not be able to
// probe the disk layout or provider reachability unauthenticated. When no
// probe registry is wired, it answers 503 rather than pretending to know.
func (s *Server) handleHealthDetailed(w http.ResponseWriter, r *http.Request) {
if s.Health == nil {
http.Error(w, "readiness probes are not configured", http.StatusServiceUnavailable)
return
}
report := s.Health.Run(r.Context())
writeJSON(w, report)
}