Skip to content

fix(deploy): probes that can say no — readiness reads /readyz, not a literal - #437

Merged
athvin merged 1 commit into
mainfrom
bm/bluegreen-p1-probes
Nov 3, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/bluegreen-p1-probes

Conversation

@athvin

@athvin athvin commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Why

Every probe on the web-api pod was one a broken pod passed.

er-server's readiness and liveness both pointed at /healthz, a static literal — so a pod whose control plane was unreachable reported ready and kept taking traffic it could only 500 on. /readyz already existed, already connects to the control store, and nothing read it; its own doc comment said exactly that. er-web was worse: both probes hit /, the prerendered marketing page, which answers 200 from a container with an unusable environment and an upstream that hasn't booted.

This is the first of a stack working toward blue/green for the web API, and it comes first because a cutover gate is only as good as the probe it reads. "The new colour is ready" has to mean the new colour can serve.

What changed

Container Startup + readiness Liveness
er-server /readyz — connects to the control store /healthz (unchanged)
er-web /api/healthz — new / (unchanged)
  • Liveness deliberately stays a literal. A liveness probe that fails on a dependency outage restarts a healthy pod and makes the outage worse. That split is the point, not an oversight.
  • The startupProbe is what lets the other two drop initialDelaySeconds — both are disabled until it passes, so the boot (which runs ensure_schema) gets a real budget instead of a guessed delay.
  • Readiness carries failureThreshold: 6. At one replica, leaving the Service is a hard 503 at the edge, and /readyz times out after 2s — so an idle dev Aurora (min_capacity = 0) resuming would otherwise flip a working pod out of rotation for the ~15s it takes to wake.

Where the logic lives, and why

The readiness decision is in src/lib/bff/readiness.ts, not the route handler. That's the tier rule here — BFF routes sit outside the coverage scope, src/lib is the unit tier's remit — and it's what makes the branches worth testing reachable: a hang and a refused connection, neither of which a flow test can produce on demand. Eleven cases, including that the probe sends no credential and that the body keeps its three keys whatever the outcome.

Deliberately not checked: the erweb database. Both colours share one Postgres, so failing readiness on it would empty the Service and turn a degraded product into a hard 503 — same reasoning as keeping liveness a literal.

Two stale claims corrected

This PR makes both actively wrong, so they're fixed here rather than left to mislead:

  • the security skill said /healthz was the only anonymous route;
  • Chart.yaml described er-dispatcher as "init-gated on the API's /healthz" when that Deployment has no init container at all — the advisory lock in ensure_schema replaced the need for one.

Does this cost anything to run idle?

No. A reviewer might reasonably worry that probing Aurora every 5s stops dev's min_capacity = 0 cluster auto-pausing. It doesn't change anything: the dispatcher's claim loop already polls the same database on a 5s idle cap, so nothing could pause while a namespace is up either way.

Verification

  • make check green — fmt, clippy, cargo doc with -D warnings, er-entity verify, skills-check, workspace tests.
  • pnpm check green — 733 tests, 56.8% line coverage against a 48% floor.
  • helm lint + helm template + kubeconform clean on the default and kind profiles; the kind profile correctly renders no /api/healthz since web.enabled: false.
  • The new test was observed failing before being trusted — probe path reverted to /healthz, confirmed the assertion fires with a useful message.

One behaviour change worth knowing as a reviewer: a container whose environment doesn't parse now never becomes ready, where before it started and 500d on first use. With --atomic --wait that fails the release instead of appearing to succeed. I checked that all five required vars do reach the container in a provisioned namespace — ERSERVER_OPERATOR_TOKEN comes from the erserver secret via an explicit env: entry, not envFrom.

🤖 Generated with Claude Code

…literal

Every probe on the web-api pod was one a broken pod passed.

`er-server`'s readiness and liveness both pointed at `/healthz`, which is a
static literal (`Json(json!({"status": "ok"}))`) — so a pod whose control
plane was unreachable reported ready and kept taking traffic it could only
500 on. `/readyz` has existed for a while, actually connects to the control
store, and nothing read it; its own doc comment said so. `er-web` was worse:
both its probes hit `/`, the prerendered marketing page, which answers 200
from a container with an unusable environment and an upstream that has not
booted.

That matters now because a blue/green cutover gate is only as good as the
probe it reads. "The new colour is ready" has to mean the new colour can
serve.

- `er-server`: readiness + a new startupProbe read `/readyz`. Liveness KEEPS
  `/healthz`, and that split is the point — a liveness probe that fails on a
  dependency outage restarts a healthy pod and makes the outage worse.
- `er-web`: readiness + startupProbe read a new `GET /api/healthz`, which
  validates the whole env schema and probes its in-pod er-server over
  localhost. Liveness keeps `/`, where a static page is exactly the right
  answer: the question is whether the node process is wedged.
- The startupProbe is what lets the other two drop `initialDelaySeconds`:
  both are disabled until it passes, so the boot — which runs `ensure_schema`
  — gets a real budget instead of a guessed delay.
- Readiness carries `failureThreshold: 6`. With one replica, leaving the
  Service is a hard 503 at the edge, and `/readyz` times out after 2s, so an
  idle dev Aurora (`min_capacity = 0`) resuming would otherwise flip a working
  pod out of rotation for the ~15s it takes to wake.

The readiness decision lives in `src/lib/bff/readiness.ts`, not the route
handler. That is the tier rule here — BFF routes are outside the coverage
scope, `src/lib` is the unit tier's remit — and it is what makes the two
branches worth testing reachable: a hang and a refused connection, neither of
which a flow test can produce on demand. Eleven cases, including that the
probe sends no credential and that the body keeps its three keys whatever the
outcome.

Deliberately NOT checked: the erweb database. Both colours share one Postgres,
so failing readiness on it would empty the Service and turn a degraded product
into a hard 503 — the same reason liveness stays a literal.

Two claims this makes actively wrong, corrected here rather than left to
mislead the next reader: the security skill said `/healthz` was the only
anonymous route, and `Chart.yaml` described er-dispatcher as "init-gated on
the API's /healthz" when that Deployment has no init container at all (the
advisory lock in `ensure_schema` replaced the need for one).

Does not change what the control plane costs to run idle: the dispatcher's
claim loop already polls the same database on a 5s idle cap, so nothing could
auto-pause while a namespace is up either way.

Verified: `make check` green (fmt, clippy, doc with -D warnings,
`er-entity verify`, skills-check, workspace tests); `pnpm check` green at 733
tests and 56.8% line coverage against a 48% floor; `helm lint` +
`helm template` + `kubeconform` clean on the default and kind profiles, with
the kind profile correctly rendering no `/api/healthz` since `web.enabled` is
false. The new test was observed FAILING — probe path reverted to `/healthz`
— before being trusted.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants