Repository navigation
feat(server): add GET /api/ready PostgreSQL readiness probe - #360
Closed
Sahilkumar-r wants to merge 1 commit into
Closed
Sahilkumar-r wants to merge 1 commit into
Sahilkumar-r wants to merge 1 commit into
Conversation
/api/health reports process liveness only. Add /api/ready so operators
and orchestrators can distinguish a running process from one whose
PostgreSQL connection is down: HTTP 200 {"ready":true} when reachable,
503 {"ready":false} otherwise. No connection details or raw errors are
exposed, and the route makes no LLM calls, scans, writes or migrations.
The PostgreSQL ping result is cached for one second and concurrent
requests that land while a ping is in flight wait for that ping instead
of starting their own, so a burst of probes cannot queue one ping per
request. /api/health, its route and existing authentication elsewhere
are unchanged; /api/ready is exempt from auth like /api/health.
Closes BaaRai#326
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Owner
|
The readiness probe landed in #363, which adds the route/auth, outage, timeout and cancellation tests the issue asked for. Thanks for the cache design; closing this one to keep a single probe. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #326
Problem
/api/healthreports HTTP liveness without checking PostgreSQL. Operators and orchestrators need to distinguish a running process from one whose database is unavailable.Fix
Add
GET /api/ready:{"ready":true}when PostgreSQL is reachable, 503{"ready":false}otherwise, with no connection details or raw errors./api/healthand its route are unchanged./api/health(added to the samerequireAuthexemption).Per the discussion on the issue: the PostgreSQL ping is cached for 1 second, and a request landing while a ping is already in flight waits for that ping instead of starting a new one, so a burst of probes can't queue one ping per request.
readyCacheinserver/ready.goholds this.Tests
server/ready_test.go: cache reuse within the TTL, re-ping after TTL expiry, 20 concurrent callers deduped into exactly one ping, and the handler's response/body when no database is configured.Verification
In a container (Go 1.26,
GOPROXYpointed at a mirror sincestorage.googleapis.comwas unreachable from my sandbox):go build ./...succeeds, the 4 new tests pass, andgo vet ./server/...is clean. The fullserverpackage suite passes exceptTestHealthSyncDropsStaleWrite, a pre-existing timing flake unrelated to this change — confirmed by running it 5x in isolation on this branch (all pass) and on an unpatched clone (all pass); it only showed up once, inside the full suite run. Not run: a real PostgreSQL-reachable path for/api/ready(would need a live Postgres instance), andgofmt/go veton the rest of the repo beyondserver/.AI disclosure
This change, its tests and this description were written by Claude Code (Claude Sonnet 5) for @Sahilkumar-r, and verified by running the checks above.
🤖 Generated with Claude Code