Skip to content

v14: fix: implement connection tracking in metrics#4945

Merged
steve-chavez merged 5 commits into
PostgREST:v14from
taimoorzaeem:backport/fix
May 20, 2026
Merged

v14: fix: implement connection tracking in metrics#4945
steve-chavez merged 5 commits into
PostgREST:v14from
taimoorzaeem:backport/fix

Conversation

@taimoorzaeem
Copy link
Copy Markdown
Member

Backport #4672 and related commits.

steve-chavez and others added 5 commits May 20, 2026 11:36
Proves the failure on PostgREST#4622.

This doesn't require additional test infra, only nginx. Taking advantage
of the `stream {}` context which is also compatible with unix socket
besides TCP.
Otherwise it's not enough time for the pool metric to
reach a negative value.
Right now metrics observation handler does not track database connections but updates a single Gauge based on HasqlPoolObs events. This is problematic because Hasql pool reports various connection events in multiple phases. The connection state machine is not simple and to precisely report the number of connections in various states, it is necessary to track their lifecycles.

This change adds a ConnTrack data structure and logic to track database connections lifecycles. At the moment it supports "connected" and "inUse" connection counts precisely. The "pgrst_db_pool_available" metric is implemented on top of ConnTrack instead of a simple Gauge.
This so we can wait for both readiness and liveness
Adjusted so it waits for liveness instead of requiring sleeping
Copy link
Copy Markdown
Collaborator

@mkleczek mkleczek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@steve-chavez steve-chavez merged commit b71345a into PostgREST:v14 May 20, 2026
35 checks passed
@steve-chavez
Copy link
Copy Markdown
Member

@mkleczek FYI somehow the test added in #4672 failed: https://github.com/PostgREST/postgrest/actions/runs/26178545486/job/77015023105

Will restart the job manually for now to allow CI to do the release.

@taimoorzaeem taimoorzaeem deleted the backport/fix branch May 20, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants