Skip to content

feat(api): answer GET /healthz?deep=1 from one SELECT now() through the database - #332

Merged
aRustyDev merged 3 commits into
mainfrom
feat/deep-healthz
Nov 19, 2026
Merged

aRustyDev merged 3 commits into
mainfrom
feat/deep-healthz

Conversation

@aRustyDev

@aRustyDev aRustyDev commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Refs #42

What

GET /healthz?deep=1 runs one statement through the database and answers 200 ok, or 503 unavailable with no word of why. Plain /healthz is unchanged and still never asks the database for a connection. This is the code half of #42; the status.woven probe line is a separate change in the infrastructure repository and goes in after this is released (it would be red until then).

  • Port: Database::ping(&SystemScope), required (no default body, so an adapter that forgot it cannot report healthy). Memory answers Ok; Postgres sends SELECT now() through the typed, counted path. now() and not 1, because Hyperdrive can answer a read from its cache when it uses only IMMUTABLE functions.
  • Use-case: thrust_core::ping_database, because the SystemScope stays private to App.
  • Handler: the query is read with RawQuery + form_urlencoded, which cannot reject, because scripts/smoke-deploy.sh (?smoke=N) and scripts/edge-controls.sh (?edge-control=...) send their own query strings to /healthz. Any deep=1 pair makes the request deep. The 503 body is the fixed word unavailable; the cause goes on the response as InternalErrorDetail, which both roots already log. Both deep answers are no-store.
  • Docs: SPEC §6.4 said the probe runs select 1; it now says SELECT now() and why (ADR-0094 and the issue always said so). Flows, architecture and patterns pages, status.md (G-3 was stale, new G-49) and by-change.md.

Tests

  • crates/api/core/tests/healthz.rs: the router with oneshot, over every query of up to two pieces from a table the test owns, crossed with a database that is up, one that is down (PgDatabase over a Connector that refuses and counts checkouts) and no App; plus a generated variant.
  • crates/core/usecases/tests/health.rs and crates/adapters/postgres/tests/ping.rs: prop_ tests (the memory adapters cannot fail, so without these ping_database -> Ok(()) survives).
  • The generated counting model against a real Postgres gained a ping step: exactly one statement, in or out of an open transaction.
  • Contract test deep_healthz_reports_the_database on every target, reading x-thrust-db-round-trips (1 for deep, 0 for plain; absent on memory). Main-pass counts 74 to 75 and stage 2's 68 to 69.

Controls (a check that cannot fail is not evidence)

  • The contract test against the old behaviour (asks_for_deep forced to false) on native-memory: 74 passed, 1 failed, at the no-store assertion.
  • cargo mutants: handler 10 mutants, 8 caught, 2 do not compile; ping_database and PgDatabase::ping: the Ok(()) mutant is caught.
  • Six defects planted by hand in the handler (no no-store, a body that carries the cause, a cause that is not logged, a 500 for the 503, a missing App answered healthy, a ping that is skipped): each killed.

Run locally

native-memory and native-pg main passes 75/75; the deps and lint jobs' checks (all of scripts/check-*, fmt, clippy for the workspace and wasm32, cargo deny, cargo metadata --locked); 2442 hermetic tests; the Docker counting model.

Run in CI, not locally

worker-memory and worker-cf cells: the installed worker-build is 0.8.7 and CI pins 0.9.0 (the worker crate is 0.9), and replacing a shared global tool was not mine to do. CI ran them on the previous head (52c985c): worker-cf main and worker-memory main both 75/75, the required gate green and every one of the 48 checks SUCCESS; the merge of main below re-runs them.

Still not shown

A database that is down is shown in process only (no contract pass stops a database, by the owner's decision: a dbdown pass would be a cell on nearly every Rust PR); G-49 says so.

Merge of main

#330 landed a G-48 row of its own (the deep nextest profile) while this branch added one for the deep health check. Main's keeps G-48, since other files already cite it; this branch's row is G-49. Nothing else conflicted, and the merged tree passes fmt, 2456 tests of the four crates, check-deps, check-cargo-lock, check-contract-counts and cargo metadata --locked.

After this merges

  1. Release to production; check curl -sD- 'https://thrust.sow.foo/healthz?deep=1' answers 200 ok with cache-control: no-store.
  2. Infrastructure PR: one Data & Apps line in shared/aws/status-page/files/gatus.yaml, with a temporary wrong-path control (red, then green).
  3. A record PR: Q-0094.4, Q-0094.7 and Q-G5.2 get "Implemented" notes, ADR-0094 an update, SPEC §6.4 the Gatus key to read the 30-day figure from.

Separately, #328 records that the uptime history lives only on the status page's own server.

🤖 Generated with Claude Code

aRustyDev and others added 2 commits November 18, 2026 23:47
…he database

`/healthz` answered `ok` without touching the database, so the availability SLO (99.5 % over 30 days) could not see the tunnel, woven-o11y or
the Workers VPC that the product now depends on (ADR-0094, Q-0094.4). With `?deep=1` it now runs one statement through the database and
answers 200 `ok`, or 503 `unavailable` with no word of why; the cause goes on the response as `InternalErrorDetail`, which both roots
already log. Both deep answers are `no-store`. Plain `/healthz` is unchanged and still never asks the database for a connection.

* `Database::ping(&SystemScope)` is a required port method (no default body: an adapter that forgot it would report healthy). The memory
  adapter answers `Ok`; the Postgres adapter sends `SELECT now()` through the typed, counted path. It is `now()` and not `1` because
  Hyperdrive can answer a read from its cache when the read uses only IMMUTABLE functions, and `now()` is STABLE.
* `thrust_core::ping_database` is the use-case, because the `SystemScope` stays private to `App`.
* The query is read with `RawQuery` and `form_urlencoded`, which cannot reject: the deploy's smoke (`?smoke=N`) and the edge's controls
  (`?edge-control=...`) send their own query strings to `/healthz` and need the 200. Any query with a `deep=1` pair is deep.

Tests: `crates/api/core/tests/healthz.rs` drives the router with `oneshot`, over every query of up to two pieces from a table it owns,
crossed with a database that is up, one that is down (`PgDatabase` over a `Connector` that refuses, which also counts checkouts) and no
`App`, plus a generated variant. `thrust-core` and the Postgres adapter each have a `prop_` test of their own (the memory adapters cannot
fail, so without them `ping_database -> Ok(())` would survive). The counting model against a real Postgres gained a `ping` step: one
statement, in or out of an open transaction. The contract test `deep_healthz_reports_the_database` runs on every target and reads
`x-thrust-db-round-trips` (1 for deep, 0 for plain); the expected main-pass counts go from 74 to 75 and stage 2's from 68 to 69.

Shown failing: `cargo mutants` on the handler (10 mutants, 8 caught, 2 do not compile), on `ping_database` and on `PgDatabase::ping`; six
defects planted by hand in the handler, each killed; the contract test against the old behaviour on native-memory (74 passed, 1 failed).
Passing locally: native-memory and native-pg main passes (75/75), the deps and lint jobs' checks, 2442 hermetic tests. Not run locally:
the worker-memory and worker-cf cells (the installed worker-build is 0.8.7 and CI pins 0.9.0); CI runs them.

Refs: #42
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…CT now()

SPEC §6.4 (line 89) still said the availability probe runs `select 1` through Hyperdrive. ADR-0094 round 29 and the issue always said
`SELECT now()`, because Hyperdrive can answer an IMMUTABLE read from its cache. The line now says so and why.

* `docs/src/flows/app.md`: a `GET /healthz?deep=1` row, and the note that any other query string is ignored.
* `docs/src/architecture/app.md`, `docs/src/contributing/patterns.md`: `ping` joins the calls that take a `SystemScope`.
* `docs/src/testing/status.md`: G-3 no longer says `thrust-api` has no tests of its own, and G-48 records what covers the deep check, what
  was shown failing, and what is not shown (a database that is down is shown in process only, by the owner's decision).
* `docs/src/testing/by-change.md`: the `oneshot` router-test gap is closed for `thrust-api` itself.

Refs: #42
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev temporarily deployed to preview-control-plane November 19, 2026 04:48 — with GitHub Actions Inactive
One conflict, in docs/src/testing/status.md: #330 added a G-48 row (the `deep` nextest profile) while this branch added a G-48 row for the
deep health check. Main's row keeps G-48, since it landed first and other files already cite it (`test_support.rs`, the ci-workflows plan).
This branch's row is now G-49, and the one place this branch cites it (the contract test's doc comment) says G-49.

Nothing else conflicted. Checked on the merged tree: fmt, 2456 tests of thrust-api, thrust-core and the two adapters, check-deps,
check-cargo-lock, check-contract-counts and `cargo metadata --locked`.

Refs: #42
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@aRustyDev
aRustyDev temporarily deployed to preview-control-plane November 19, 2026 05:16 — with GitHub Actions Inactive
@aRustyDev
aRustyDev merged commit 2d389cb into main Nov 19, 2026
48 checks passed
@aRustyDev
aRustyDev deleted the feat/deep-healthz branch November 19, 2026 05:29

This branch was previously deployed

1 inactive deployment
preview-control-plane — 106d015a Deployed Nov 19, 2026 by aRustyDev via reconcile #232
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.

1 participant