Repository navigation
[+] add longest_idle_in_tx_seconds to backends - #1613
Open
pashagolub wants to merge 2 commits into
Open
pashagolub wants to merge 2 commits into
pashagolub wants to merge 2 commits into
Conversation
The new gauge holds the seconds since the oldest idle-in-transaction client session, aborted ones included, entered that state. It is null when there is no such session. Add a matching panel to both v13 sessions overview dashboards.
The backends metric stores *_seconds columns rounded to three decimals, so casting them to int or int8 fails with "invalid input syntax for type bigint". Cast them to float in the v13 postgres dashboards.
Coverage Report for CI Build 39777029889Warning No base build found for commit Coverage: 89.684%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
🟢 Approval recommended
No blocking issues were identified; the remaining review comments are non-blocking documentation nits.
2 open issues
What changed in this PR
Adds longest_idle_in_tx_seconds to the backends metric and exposes it in the PostgreSQL and Prometheus v13 sessions dashboards. It also corrects affected fractional-duration casts.
Changes:
- Calculates the oldest client session’s idle-in-transaction duration, including aborted sessions.
- Adds a contract test covering the complete
backendscolumn set. - Adds dashboard panels and updates duration casts to
float.
| File | Description |
|---|---|
pkg/metrics/metrics.yaml |
Defines and documents the new idle-in-transaction duration gauge. |
pkg/metrics/metrics_yaml_test.go |
Verifies the complete backends SQL column contract. |
grafana/prometheus/v13/sessions-overview-prometheus.json |
Adds the Prometheus sessions panel and dashboard placement. |
grafana/postgres/v13/sessions-overview.json |
Adds the PostgreSQL sessions panel and fixes fractional duration casts. |
grafana/postgres/v13/recommendations.json |
Fixes fractional duration casts in recommendation queries. |
grafana/postgres/v13/global-health.json |
Fixes the fractional transaction-duration cast. |
Review effort: Lite
| "spec": { | ||
| "id": 15, | ||
| "title": "Longest idle-in-transaction duration", | ||
| "description": "Seconds since the oldest idle-in-transaction client session (aborted ones included) entered that state. Such a session holds its snapshot and locks, so vacuum cannot remove dead rows.", |
| "spec": { | ||
| "id": 10, | ||
| "title": "Longest idle-in-transaction duration", | ||
| "description": "Seconds since the oldest idle-in-transaction client session (aborted ones included) entered that state. Such a session holds its snapshot and locks, so vacuum cannot remove dead rows.", |
This branch has not been deployed
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.

Summary
backendscounts idle-in-transaction sessions but does not say how long they have been idle. The new gaugelongest_idle_in_tx_secondsholds the seconds since the oldest idle-in-transaction client session, aborted ones included, entered that state. It is null when there is no such session.It uses
state_change, notxact_start, so a transaction that worked for ten minutes and then paused for one second shows 1 s.longest_tx_secondsalready reports the transaction age.Both v13 sessions overview dashboards get a new panel after "Longest TX duration":
Sessions overview (postgres, prometheus) Longest TX duration + Longest idle-in-transaction duration ...The second commit fixes the v13 postgres dashboards, which cast the fractional
*_secondscolumns ofbackendstoint/int8. Postgres rejects that cast, so the panels returned errors instead of data. They now cast tofloatinsessions-overview,global-healthandrecommendations.Evidence
backendshad no idle age column. The v13 dashboard cast failed:postgres:19beta2-alpine:::floatreturns12.345.TestBackendsColumnschecks that everybackendscolumn, the new one included, stays in the SQL. Lint andgo test ./...pass.Merge Danger
Door: two-way
The change adds a column and panels and renames nothing. Reverting removes them.
Blast Radius: small
Sinks store one more field per
backendsrow, and Prometheus exposes one more series,pgwatch_backends_longest_idle_in_tx_seconds, per database. The v12 postgres dashboards still have the int cast bug in 11 queries.