Repository navigation
Description
Problem or Motivation
No test runs a dashboard panel query. The one query test (tests/prometheus/test_k8s_monitoring_dashboards.py:398 with tests/fixtures/recorded_queries/ai_spend_local_savings.yaml) compares a recorded live answer and does not evaluate the query. So wrong numbers shipped with no failed test: the throttle bars of devops-cli.json panel 23 add up to 474 in 24 h for 21 throttles; the AI spend rate[5m] of ai-spend.json panel 7 adds up to $33.30 of $77.33 (43 %) at 7 d; rate[5m] of devops_cli_ai_requests_total adds up to 37 % of the requests; the project gauges flip between 1,940 and 6.
Proposed Solution & Architectural Design
Use promtool, which the repository already pins (src/devops_cli/tools_lock/tools.lock) and CI installs (.github/workflows/ci.yml:151-156). promtool test rules accepts promql_expr_test cases with no rule file. A new pytest module reads tests/fixtures/dashboard_queries/<dashboard>.yaml. Each case names the dashboard, the panel title, the refId, the Grafana variables ($__range, $__range_s, $__interval, $__rate_interval, $job, $repo and others), input_series, eval_time and exp_samples. The test (1) substitutes the variables as Grafana does ($__rate_interval = max($__interval + scrape interval, 4 x scrape interval), with the panel Min step as the scrape interval, Grafana 13 global variables documentation), (2) fails when the case query is not the current query of that panel target, (3) writes one promtool file for each dashboard under tmp_path and (4) runs promtool. Move _promtool from tests/prometheus/test_k8s_monitoring_alerting.py:1507 to a shared support module and use the existing @pytest.mark.live('promtool') marker, so the test skips where promtool is missing (#2472). Fixture series model the 4 measured shapes: a sparse OTLP counter with a sample every 15 min, a stream that starts with a zero sample, a counter reset at a pod start, and a snapshot gauge written every 15 min. The first cases cover panels that are correct today (devops-cli.json panel 9 'AI Spend in Range'), so the item lands green; each dashboard item adds the cases of its panels. #3655 and #3851 also evaluate panel queries with promtool; they use this harness, so the repository keeps one evaluator. If #4363 removes tools.lock first, use the promtool pin that replaces it.
Target Subsystem
Kubernetes & Minikube Automation (Grafana dashboards and telemetry).
Existing Tool Considered
no open tool evaluates Grafana panel targets on fixture series; promtool evaluates the PromQL, and the new code only substitutes variables and builds the case file. Cost: about 120,000 tokens to build, 3,000 tokens a month to keep, 3 h elapsed.
Acceptance Criteria
- 'uv run pytest tests/prometheus/test_dashboard_queries.py' runs promtool once for each fixture file and passes; with no promtool on PATH, it skips with the reason.
- A change of one character in a covered panel query makes the test fail with the dashboard, the panel title and the refId in the message.
- A case with a wrong exp_samples value fails with the promtool output in the message.
- The fixture set holds each of the 4 series shapes at least once.
- The new test adds less than 10 s to the test run (measured in the pull request).
- docs/TESTING.md tells how to add a case.
Files
tests/prometheus/test_dashboard_queries.pytests/fixtures/dashboard_queries/devops-cli.yamltests/support/promtool.pytests/prometheus/test_k8s_monitoring_alerting.pydocs/TESTING.md
Dependencies
None.
Related
Source: #4675
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
testprefix of the title gives the type.(monitoring)scope of the title gives the scope.It prevents wrong dashboard numbers from shipping undetected, but it is a test improvement, not a user-facing defect.Catches silent numeric errors in shipped dashboards, improving trust in monitoring data.New test module, fixture files, shared support module, code move, and docs; body estimates about 3 hours.Both evaluate dashboard panel queries with promtool, but the candidate builds the shared harness and fixture-series test, while #3851 compares panel values against roadmap explain output using that harness.