feat(dashboard): surface additional query metrics in the drill-down - #386
feat(dashboard): surface additional query metrics in the drill-down#386dpage wants to merge 1 commit into
Conversation
Adds the metrics requested in #350, bar the client IP, which is not achievable without a collector change and is tracked separately. The query drill-down now shows minimum and maximum execution time as KPI tiles, and a new tile giving the average execution time scoped to the selected range, labelled with that range so it cannot be confused with the cumulative lifetime figure beside it; the existing tile is relabelled "Mean Time (All Time)" for the same reason. The database role that ran the query is shown beside the query text, falling back to "Unknown" when it cannot be resolved. The period-scoped average comes from a new GET /api/v1/metrics/query- stats endpoint, computed as the sum of per-sample deltas rather than a first-versus-last subtraction, so a pg_stat_reset() or restart part way through the range costs a single interval instead of corrupting the whole figure; it returns null rather than zero when no usable sample pairs exist. The role name is resolved from pg_stat_activity via a usesysid lookup mirroring the existing datid resolution, which only works for roles observed with an active backend inside the retention window. This also fixes a pre-existing bug: the drill-down's execution-time and call-count charts sent no query filter, so they aggregated across every statement on the connection rather than the query being inspected. /api/v1/metrics/query gains an optional `queryid` filter, which rejects probes lacking that column rather than emitting invalid SQL. Note one behaviour change beyond the issue: the database-name lookup now picks the most recently observed name per OID instead of an arbitrary one, so a database renamed within the retention window no longer reports a name that can flip between requests. Closes #350
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Up to standards ✅🟢 Issues
|
| Category | Results |
|---|---|
| Complexity | 1 medium |
🟢 Metrics 378 complexity · 45 duplication
Metric Results Complexity 378 Duplication 45
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Summary
Implements issue #350, bar the client IP / hostname, which turned out not to be achievable without a collector change and is tracked separately as #384.
GET /api/v1/metrics/query-stats, computed as the sum of per-sample deltas rather than a first-versus-last subtraction, so apg_stat_reset()or restart part way through the range costs one interval instead of corrupting the whole figure. It returnsnull, not zero, when there is no usable data.pg_stat_activityvia ausesysidlookup mirroring the existingdatidresolution; falls back to "Unknown", since resolution only works for roles observed with an active backend inside the retention window.GET /api/v1/metrics/querygains an optionalqueryidfilter, which rejects probes lacking that column rather than emitting invalid SQL.Behaviour change worth a reviewer's eye
The database-name lookup CTE now picks the most recently observed name per OID (
DISTINCT ON (datid) ... ORDER BY datid, collected_at DESC) instead of an arbitrary one. Previously a database renamed within the retention window could report either name depending on which the planner reached first, so this makes an existing wobble deterministic rather than introducing new behaviour.Test plan
QueryDetail.test.tsx(there was none) covering the new tiles, thenullaverage path, the unresolved-username path,queryidreaching the chart requests, and refetch on time-range change.queryidfilter on both the time-series and latest-row paths, and username resolution including the unresolvable case.handleQueryStats,buildQueryStats,buildTopQueriesSQL,metricQueryBase,buildLatestRowsQueryall 100%;QueryDetail.tsx99.0%;useQueryStats.tsanduseMetrics.ts100%.go test -race ./internal/api/ ./internal/metrics/and the client suite (27 files, 521 tests) both pass;gofmt,golangci-lintandnpm run lintclean.Closes #350