fix(dashboards): emit clean var-db_name in drill-down links

Summary

Three related fixes around the Dashboard 02 → single-DB drill-down flow. They are split into three commits and address the same root user-visible bug (empty panels on Dashboard 03 after clicking "Query Analysis"):

  1. fix(dashboards): emit clean var-db_name in drill-down links (056efc4f). Source dashboards (02, 04, 10) built drill-down URLs with &var-db_name=$db_name. Because db_name is multi-select on D02/D04, Grafana rendered the value as {postgres} (the multi-value notation) even with one selection. Switch the 28 affected URL fragments to ${db_name:queryparam}, which emits var-db_name=<v> per selected value without the multi-value wrapper.

  2. fix(dashboards): harmonize db_name variable across single-DB dashboards (152eefc8). After fix 1, drilling with "All" databases selected now carries var-db_name=All literally. Destination dashboards (01, 03, 05, 07–13) had db_name as a single-select variable, so they took "All" as a datname value and ran datname="All" → no series. Set every dashboard's db_name to multi: true, includeAll: true (matching D02/D04), and switch 201 datname="$db_name" PromQL occurrences across 8 dashboards to datname=~"$db_name" so Grafana's multi-value expansion works as intended. Also corrects D13's previous incoherent multi=false, includeAll=true.

  3. fix(dashboard03): show friendly fallback when query text not yet collected (6d6a7e09). D03 panel id 18 (the "Query text" table at the top) queries sink-postgres.pgss_queryid_queries for the SQL text. pgwatch writes new queryids to that table on a periodic scrape (~30s), so an immediate drill-through after a brand-new queryid first appears lands in a small window where the metrics already exist in VictoriaMetrics but the matching row in pgss_queryid_queries has not yet been written. Result: red-triangle "No data" that looks like a hard error. Rewrite the SQL as a CTE + UNION ALL that always returns exactly one row — the actual text when present, or a friendly "(query text not yet collected for this queryid — pgwatch writes it on the next scrape; refresh in ~30s)" when absent.

Closes #207 (closed).

Verification done

  • All 11 dashboard JSONs parse as valid JSON.
  • Re-survey of db_name variable shape after the patch:
    multi=True  includeAll=True   D01..D13 (all that have the var)
  • Strict vs regex datname count on D03 after patch (live Grafana DB after /api/admin/provisioning/dashboards/reload):
    datname="$db_name"  → 0
    datname=~"$db_name" → 22
  • Panel 18 SQL fallback tested against sink-postgres on the test instance:
    • With an existing queryid (1037176236034626937): returns the actual select /* pgwatch_generated */ … text.
    • With a synthetic non-existing queryid (9999999999999): returns the fallback string.
  • Live end-to-end on 473261d742b1.pgai.watch (running 0.15.0-rc.5): all 9 patched dashboards deployed into the postgres_ai_configs volume and Grafana reloaded. Verified earlier in this thread that drilling from D02 → D03 with a specific DB selected populates all 16 PromQL panels (screenshot showed "Calls (pg_stat_statements)" with data).
  • Pre-commit hooks pass: JSON validity, large-files, trailing whitespace, end-of-file.

Test plan

  • Load Dashboard 02 in browser. With DB name = postgres, click the "Query Analysis" link on any row. Confirm the URL bar shows var-db_name=postgres (no braces) and that every PromQL panel on Dashboard 03 populates.
  • Same as above but with DB name = All on D02. Confirm the destination renders all panels populated for the queryid across whichever DB(s) carry it (D03's datname=~"$db_name" will accept Grafana's All regex).
  • Click into Dashboard 03 with a brand-new queryid that hasn't yet been written to pgss_queryid_queries. Confirm the top panel shows the explanatory fallback text instead of the red-triangle "No data".
  • After ~30 s, refresh the page on the same URL; confirm the actual query text appears.
  • Repeat drill-down from D04 (Wait sampling) and D10 (Aggregated index analysis) into their respective single-dashboards. Confirm same behavior.
  • Smoke-check that the other dashboards we touched still load (D01, D05, D07, D08, D09, D12, D13). Spot-check that PromQL panels still render for the existing single-DB selection (don't need full coverage — the regex change is mechanical).

🤖 Generated with Claude Code

Edited by Denis Morozov

Merge request reports

Loading