fix: implement connection tracking in metrics

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 commit is contained in:
Michał Kłeczek
2026-05-18 10:09:00 -05:00
committed by Steve Chavez
parent 4f9bc89ab2
commit a297391071
5 changed files with 99 additions and 25 deletions
+1
View File
@@ -52,6 +52,7 @@ All notable changes to this project will be documented in this file. From versio
### Fixed
- Fix unnecessary connection pool flushes during schema cache reloading by @mkleczek in #4645
- Fix race condition in pool_available metric causing negative values during network instability by @mkleczek in #4622
## [14.9] - 2026-04-10