Skip to content

feat(health): bounded DB connectivity check on /health - #3

Merged
AquiGorka merged 1 commit into
mainfrom
feat/health-db-check
Jun 22, 2026
Merged

feat(health): bounded DB connectivity check on /health#3
AquiGorka merged 1 commit into
mainfrom
feat/health-db-check

Conversation

@AquiGorka

@AquiGorka AquiGorka commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What

`/api/v1/health` now runs a 2s-bounded `SELECT 1` against the app `PgPool` and reports `deps.db`:

  • 200 `{ status: "ok", version, deps: { db: "ok" } }` when Postgres answers.
  • 503 `{ status: "error", version, deps: { db: "error" } }` when the DB is unreachable or unresponsive (timeout).

The existing `status`/`version` fields are preserved.

Why

A static `{status:"ok"}` health endpoint masked a dead DB during a prod incident. The SaaS provider-platform + council-platform already gained a DB-aware `/health`; this brings the Rust provider-stand-in to parity, mirroring the Deno `checkDbHealth` reference (`src/http/v1/health/db-check.ts`).

Design

  • Connectivity-only: `SELECT 1` checks that a connection can be established; it does not depend on migrated schema, so a still-migrating boot with a reachable Postgres still reports `db:ok`.
  • Timeout-bounded (`tokio::time::timeout`, 2s) — kept well under the container/compose healthcheck `timeout` so a slow/unreachable DB resolves to a fast 503 instead of hanging the health gate.
  • Single-PP semantics untouched.

Tests (`crates/api/tests/health_http.rs`)

  • `health_reports_503_when_db_unreachable` — lazy pool pointed at an unreachable port; no live DB needed.
  • `health_reports_200_and_db_ok_with_live_db` — per-test migrated DB (skips with an `eprintln` when `DATABASE_URL` is unset).

Both verified locally against an isolated throwaway Postgres; the DB-down path also runs without any DB.

Version

Workspace `0.1.0` -> `0.2.0`.

@AquiGorka
AquiGorka force-pushed the feat/health-db-check branch from ff8349c to 6071c66 Compare June 22, 2026 18:04
/api/v1/health now runs a 2s-bounded SELECT 1 against the app PgPool and
reports deps.db (ok|error), returning 503 when Postgres is unreachable or
unresponsive and 200 otherwise. Keeps the existing status/version fields.

A static {status:"ok"} masked a dead DB during a prod incident; this mirrors
the Deno provider-platform/council checkDbHealth landing. Connectivity-only
(SELECT 1, no schema dependency) and timeout-bounded so a still-migrating boot
with a reachable Postgres still reports db:ok and the endpoint never hangs the
container/compose health gate.

Tests cover both the ok (live DB) and DB-down (lazy pool to an unreachable
port, no live DB) paths. Workspace version 0.1.1 -> 0.1.2.
@AquiGorka
AquiGorka force-pushed the feat/health-db-check branch from 6071c66 to 1960958 Compare June 22, 2026 18:26
@AquiGorka
AquiGorka merged commit d409b4c into main Jun 22, 2026
5 checks passed
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