Skip to content

fix: suppress connection_info metric when DB is unreachable using component-level ping#5708

Closed
gaantunes wants to merge 2 commits into
mainfrom
gaantunes/fix/dbo11y-connection-info-component-ping
Closed

fix: suppress connection_info metric when DB is unreachable using component-level ping#5708
gaantunes wants to merge 2 commits into
mainfrom
gaantunes/fix/dbo11y-connection-info-component-ping

Conversation

@gaantunes
Copy link
Copy Markdown
Contributor

Summary

Test plan

  • TestConnectionInfo_Unregister — metric disappears from registry after Unregister()
  • TestConnectionInfo_Reregister — metric reappears with correct label values after Reregister()
  • TestComponent_PingConnectionInfo_UnregistersAfterThresholdFailures — metric unregistered after 3 consecutive ping failures (postgres + mysql)
  • TestComponent_PingConnectionInfo_ReregistersAfterThresholdSuccesses — metric re-registered after 3 consecutive ping successes (postgres + mysql)
  • TestComponent_PingConnectionInfo_RemainsRegisteredWhilePingsSucceed — metric stays registered while pings succeed (postgres + mysql)
  • All existing tests pass

Made with Cursor

…ponent-level ping

The connection_info metric was always emitted once on Start and never
removed, even when the DB became unreachable. This caused stale metrics
to be served for disconnected instances.

Instead of a separate per-collector goroutine, the existing 30-second
ticker in each component's Run() loop now performs a single DB ping and
calls Unregister/Reregister on the ConnectionInfo collector after
connectionInfoPingThreshold (3) consecutive failures/successes. This
keeps the fix self-contained in the component, avoids multiplying DB
pings, and applies uniformly to both postgres and mysql.

ConnectionInfo gains Unregister(), Reregister(), and IsRegistered()
methods that safely toggle registration state under a mutex. The label
values resolved in Start() are stored on the struct so Reregister() can
restore the metric with the correct labels.

Made-with: Cursor
@gaantunes gaantunes requested a review from a team as a code owner March 4, 2026 22:28
…ility package

Eliminates the duplicated pingConnectionInfo method, ciPingState struct, and
connectionInfoPingThreshold constant from both the postgres and mysql components
by extracting them into a single PingConnectionInfo function in the shared
database_observability package. The function is tested once using a lightweight
mock; component-level tests that duplicated this coverage are removed.

Both components now call database_observability.PingConnectionInfo directly
from their existing ticker loop with a goroutine-local CIPingState.

Made-with: Cursor
@gaantunes gaantunes closed this Mar 4, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant