fix(health): report real per-dependency status instead of hardcoded ok:true
Security Scan (SIAX Cloud) / security (push) Successful in 21s
CI (SIAX Cloud) / security (push) Successful in 21s
CI (SIAX Cloud) / quality (push) Successful in 41s
CI (SIAX Cloud) / security (pull_request) Successful in 22s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / quality (pull_request) Successful in 41s
Security Scan (SIAX Cloud) / security (push) Successful in 21s
CI (SIAX Cloud) / security (push) Successful in 21s
CI (SIAX Cloud) / quality (push) Successful in 41s
CI (SIAX Cloud) / security (pull_request) Successful in 22s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / quality (pull_request) Successful in 41s
BACKLOG P0-3: /api/health only ever checked *presence* of DATABASE_URL/
REDIS_URL and always returned ok:true regardless of whether anything was
reachable -- ARCHITECTURE.md's own words, "an uptime monitor watching HTTP
200 would show green for a dying instance".
lib/health-checks.ts adds real dependency probes:
- db: a live `select 1` round trip (not just DATABASE_URL presence)
- engine: a real HTTP call to the FastAPI engine's own GET /health
- stripe: Stripe's documented lightweight balance.retrieve() liveness call
- queue: honestly reports "not_integrated" when REDIS_URL is set but
unused -- no Redis client is wired anywhere in this repo, so reporting
"ok" would fabricate a check that doesn't exist
/api/health stays a liveness check (always 200 while the process can
respond; the body's `ok` field is the honest signal). New GET /api/ready
fails closed with 503 when the load-bearing dependency (db) isn't both
configured and reachable -- the "no /ready route" gap.
contracts/openapi.yaml, docs/architecture/ARCHITECTURE.md, and docs/slo.md
updated to match. 17 new unit tests (dependency-injected fakes, no real
network/DB) + 5 route-level tests.
This commit is contained in:
@@ -132,6 +132,7 @@ Risknivå = SIAX L0–L5-taxonomin, bedömd av mig utifrån vad handlern gör.
|
||||
| Operation | Metod/sökväg | Risknivå | Kräver godkännande |
|
||||
|---|---|---|---|
|
||||
| Liveness | `GET /api/health` | L0 | Nej (avsiktligt) |
|
||||
| Readiness | `GET /api/ready` | L0 | Nej (avsiktligt) |
|
||||
| Prisestimat | `POST /api/estimates` | L1 | Nej |
|
||||
| Katalog / källor / fordon | `GET /api/{catalog,sources,vehicles}` | L1 | Nej |
|
||||
| Sanktions-/PEP-screening | `GET /api/screen?q=` | L2 | Nej — proxar mot OpenSanctions |
|
||||
@@ -240,11 +241,20 @@ inget sådant jobb, ingen TTL, ingen `DELETE`-väg och ingen radering finns i ko
|
||||
## 6. Drift
|
||||
|
||||
### Hälsokontroll
|
||||
`GET /api/health` → `{ok, service:"0pt-web", db, queue, ts}`. Den svarar **alltid
|
||||
`ok:true`** oavsett om databasen finns — den rapporterar bara `"not_configured"`
|
||||
i ett fält. En uptime-monitor som tittar på HTTP 200 kommer därför visa grönt
|
||||
för en instans utan databas, vilket är exakt vad som gäller idag. Engine har ett
|
||||
separat `GET /health`.
|
||||
**Fixat (BACKLOG P0-3):** `GET /api/health` → `{ok, service:"0pt-web", db, queue,
|
||||
engine, stripe, ts}`. `db`/`engine`/`stripe` rapporterar nu en riktig
|
||||
beroendeprobe (`lib/health-checks.ts`): `"ok"` = lyckad live-anrop, `"error"` =
|
||||
konfigurerad men onåbar (se `detail`), `"not_configured"` = env-variabel ej
|
||||
satt. `queue` kan bara vara `"not_configured"`/`"not_integrated"` — ingen
|
||||
Redis-klient finns i repot, så en satt `REDIS_URL` rapporteras ärligt i stället
|
||||
för att låtsas testa en anslutning som aldrig görs. `ok` är `true` endast när
|
||||
ingen konfigurerad dependency ligger i `"error"`. HTTP-statusen är fortsatt
|
||||
alltid 200 (liveness — processen svarar) oavsett dependency-läge; en extern
|
||||
beroendekrasch ska inte omstarta instansen. Ny `GET /api/ready` failar stängt
|
||||
(503) när databasen (den enda lastbärande dependencyn idag) inte både är
|
||||
konfigurerad och nåbar — peka en Coolify/lastbalanserar-readiness-probe dit,
|
||||
inte mot `/api/health`. Engine har ett separat `GET /health` som `checkEngine()`
|
||||
nu faktiskt anropar (tidigare kollades bara `ENGINE_URL`-närvaro).
|
||||
|
||||
### Loggar
|
||||
Ingen strukturerad loggning. `console.warn` i `src/auth/context.ts` är den enda
|
||||
|
||||
Reference in New Issue
Block a user