Skip to content

[*] improve single query details pg dashboard#1276

Merged
0xgouda merged 10 commits intocybertec-postgresql:masterfrom
Bishoywadea:fix/1152-sync-pg-with-prom-updates
Mar 13, 2026
Merged

[*] improve single query details pg dashboard#1276
0xgouda merged 10 commits intocybertec-postgresql:masterfrom
Bishoywadea:fix/1152-sync-pg-with-prom-updates

Conversation

@Bishoywadea
Copy link
Copy Markdown
Contributor

@Bishoywadea Bishoywadea commented Mar 4, 2026

Description

based on @0xgouda request this PR modify queries in single query dashboard in pg to match the updates in correspond prom dashboard and partially solves #1152 in this dashboard

fixes partially: #1152

image image

AI & Automation Policy

  • I am the human author and take full personal responsibility for every change in this PR.
  • I have disclosed all tool(s) below.

AI/automation tools used (leave blank if none):

No agents were used in this PR i only used Gemini the free tier to help me with the queries but i have reviewed it carefully and tested it well

Checklist

  • Code compiles and existing tests pass locally.
  • New or updated tests are included where applicable.
  • Documentation is updated where applicable.

@0xgouda 0xgouda force-pushed the fix/1152-sync-pg-with-prom-updates branch from b86bd15 to c5f65ba Compare March 9, 2026 15:26
@0xgouda
Copy link
Copy Markdown
Collaborator

0xgouda commented Mar 9, 2026

Can you please attach a clear description of the approach you took for fixing the queries?

@Bishoywadea
Copy link
Copy Markdown
Contributor Author

@0xgouda
i have solved it using the approach you mentioned in the #1152, by making CTE that get the last row from before the begining of that time range by selecting only time from stat_statments where dbname and query_id matched and the time is less than the begining of the range then sort them desc and get the first one
then replaced the $__timeFilter() with

time >= (SELECT time FROM baseline)
AND time <= $__timeTo()::timestamptz

by this modification i get another extra row for the first row in the required time range which make lag() not getting null for the first row
another thing i have modified queries to be /second and bytes instead of blocks units like in prom dashboard as per our conversation on slack

@Bishoywadea
Copy link
Copy Markdown
Contributor Author

ping @0xgouda

@0xgouda 0xgouda force-pushed the fix/1152-sync-pg-with-prom-updates branch from e5ddb67 to c01eef1 Compare March 13, 2026 14:37
@0xgouda
Copy link
Copy Markdown
Collaborator

0xgouda commented Mar 13, 2026

@Bishoywadea
I believe we should use nullif(extract(epoch from sum(time - time_lag)), 0) instead of the places where we have nullif(extract(epoch from '$agg_interval'::interval), 0).

As this would cause the very last time group to output incorrect values, as it will have less than the number of expected data points (as they are still being collected), for example

See the drop at the end here and how it affects the Min field:

image

vs if we used nullif(extract(epoch from sum(time - time_lag)), 0):

image

As it won't add extra minutes in the divisor for the points that haven't been collected yet.


Also, I get why you did that, for performance, but I hope that pg will be able to handle the additional lag() efficiently as we are already calculating it for a previous column

@Bishoywadea
Copy link
Copy Markdown
Contributor Author

Bishoywadea commented Mar 13, 2026

@0xgouda makes sense, i think this is more accurate indeed, check it after the commit

@0xgouda 0xgouda force-pushed the fix/1152-sync-pg-with-prom-updates branch from dceafa1 to cb2acdb Compare March 13, 2026 18:30
@0xgouda 0xgouda self-assigned this Mar 13, 2026
@0xgouda 0xgouda added the dashboards Grafana dashboards related label Mar 13, 2026
@0xgouda 0xgouda changed the title [*] sync pg single query dahboard with prom single query dahboard updates [*] improve single query details pg dashboard Mar 13, 2026
Copy link
Copy Markdown
Collaborator

@0xgouda 0xgouda left a comment

Choose a reason for hiding this comment

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

LGTM, Good Job!

@0xgouda 0xgouda merged commit fe137de into cybertec-postgresql:master Mar 13, 2026
5 checks passed
@Bishoywadea Bishoywadea deleted the fix/1152-sync-pg-with-prom-updates branch March 13, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboards Grafana dashboards related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants