feat(api): add DB-touching /health/ready readiness probe (GRO-2678) #233
Reference in New Issue
Block a user
Delete Branch "feat/gro-2678-db-readiness-probe"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds
GET /health/ready— a public, DB-touching readiness endpoint registered before the/api/*auth middleware so it is reachable by K8sreadinessProbeon pod port 3000 without auth.Behaviour
{"status":"ready"}— DB query succeeds, schema is present{"status":"degraded"}— DB query throws for any reason (schema dropped42P01, connection refused, etc.)Why this matters
/healthreturns{"status":"ok"}with no DB check. This mask allowed the GRO-2678 PROD schema drop to go undetected for ~43 h./health/readycloses that gap: a dropped schema immediately surfaces as non-200 and removes the pod from Service endpoints once wired asreadinessProbe(Deliverable 2 — infra PR).Files changed
apps/api/src/index.ts— new route registered at line 64 (immediately after/api/health, before auth middleware)apps/api/src/__tests__/health-ready.test.ts— 3 tests: 200 on success, 503 on42P01, 503 on ECONNREFUSED; all assert no SQL leakage in responseUAT Playbook
No new user-facing behaviour — probe is infrastructure-only. No UAT_PLAYBOOK.md update required.
Related
cc @cpfarhood
Register GET /health/ready before the /api/* auth middleware so it is public and reachable by K8s readinessProbe on port 3000 without auth. On success → 200 {"status":"ready"}; on any DB/schema failure → 503 {"status":"degraded"}. Logs the pg error code; never leaks SQL in body. A dropped schema (42P01) surfaces as non-200, closing the /health mask that allowed the GRO-2678 incident to go undetected for ~43h. Add health-ready.test.ts covering the 200 success path, 503 on schema drop (42P01), and 503 on connection error; all assert no SQL leakage. Co-Authored-By: Paperclip <noreply@paperclip.ing>