Skip to content

test(monitoring): lint dashboards for range, window and legend errors #4743

Done

Description

@dan-petty

Update 2026-11-26 (infra move): the environment dashboards moved to dan-petty/homelab.

This issue keeps the 5 linter rules, their tests, the README text, the product dashboards in k8s/devops/dashboards/ and the service dashboard generator (src/devops_cli/grafana/service_dashboard.py), whose burn-rate panels use fixed windows. The environment dashboard fixes are in the homelab follow-up. Do that one before homelab takes the devops-cli release with the new rules.

Follow-up: dan-petty/homelab#277.


Problem or Motivation

The dashboard linter (src/devops_cli/grafana/linter.py, run on each shipped dashboard by tests/grafana/test_grafana_dashboards.py:205) checks only identity, panel ids, layout, datasources and PromQL syntax. It passes every defect of this plan. Measured today: 10 [$__range] targets in time series panels of project-metrics.json; 142 time series targets with a fixed rate or increase window in 8 dashboards (ai-spend 17, coredns 10, devops-cli 48, ingress-tunnel 19, llm-stack 21, otel-collector 8, prometheus-server 6, sre-service 13); 7 time series targets with 'or vector(0)'; histogram_count on seconds axes; by() over labels with no bound.

Proposed Solution & Architectural Design

Add 5 rules to the existing linter: (1) a time series or bar chart target with [$__range] that is not instant; (2) a rate, irate, increase or delta window in a time series target that is not [$__rate_interval] or [$__interval] (a burn-rate window belongs in a recording rule); (3) 'or vector(0)' in a time series target; (4) a by() or legend over a label with no bound (pod, release, workflow, sub_command, run_id, item, branch, host_name, client_ip, user_agent); (5) a histogram_count target in a panel with unit s or ms and no override for that refId. Fix the remaining targets of coredns, ingress-tunnel, otel-collector and prometheus-server in the same pull request ([$__rate_interval]). No exemption list. Write the panel rules in the dashboard section of k8s/README.md.

Target Subsystem

Kubernetes & Minikube Automation (Grafana dashboards and telemetry).

Existing Tool Considered

grafana/dashboard-linter v0.4.0 (Apache-2.0, released 2026-10-21, repository active 2026-11-09). Its target-rate-interval-rule covers only rate() without $__rate_interval. It has no rule for $__range, increase windows, legends, units or 'or vector(0)', and it takes no custom rules. Cost: about 100,000 tokens to build, 3,000 tokens a month to keep, 2 h elapsed.

Acceptance Criteria

  • For each rule, a test dashboard makes the linter report an error with the dashboard, the panel and the refId, and a corrected copy lints clean.
  • test_repository_dashboards_lint_clean passes for each dashboard of k8s/devops/dashboards/ with no per-file or per-rule exemption.
  • The new rules add less than 2 s to the test run.
  • k8s/README.md lists the 5 rules.

Files

  • src/devops_cli/grafana/linter.py
  • tests/grafana/test_grafana_dashboards.py
  • k8s/monitoring/dashboards/coredns.json
  • k8s/monitoring/dashboards/ingress-tunnel.json
  • k8s/monitoring/dashboards/otel-collector.json
  • k8s/monitoring/dashboards/prometheus-server.json
  • k8s/README.md

Dependencies

#4684, #4707, #4718, #4712, #4724, #4728, #4732.

Source: #4675

Alternatives check of 2026-11-26: not-applicable.
Class: test, no model call.
Tool: none found.

Proposed design

Problem statement

Add the five dashboard lint rules and fix the product dashboards and the service dashboard generator. The environment dashboards are out of scope and live in the homelab follow-up. The linter checks identity, panel ids, layout, datasources and PromQL syntax only. It passes range variables, fixed rate windows, or vector(0), unbounded labels and histogram_count on a seconds axis.

Acceptance criteria

Requirement: Range variable rule

The linter SHALL report an error when a timeseries, graph or barchart Prometheus target uses $__range and is not instant.

Scenario: Range variable in a graph target

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k range_variable runs on a fixture dashboard whose timeseries Prometheus target uses $__range and is not instant.
  • THEN The test passes and the report names the dashboard uid, the panel title and the target refId, and the same target with $__rate_interval gives no issue.

Requirement: Range variable off a graph panel

The linter MUST NOT report a range variable error for a stat, table, gauge or heatmap panel.

Scenario: Range variable in a stat panel

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k range_variable_stat runs on a fixture dashboard whose stat Prometheus target uses $__range.
  • THEN The test passes and the report holds no issue for that panel.

Requirement: Fixed window rule

The linter SHALL report an error when a timeseries, graph or barchart Prometheus target has a rate, irate, increase or delta window that is not [$__rate_interval] or [$__interval].

Scenario: Fixed rate window

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k fixed_window runs on a fixture target that uses rate(http_requests_total[5m]).
  • THEN The test passes and the report names the dashboard uid, the panel title and the target refId, and the same target with [$__rate_interval] gives no issue.

Requirement: Constant zero fallback rule

The linter SHALL report an error when a timeseries, graph or barchart Prometheus target contains or vector(0).

Scenario: Constant zero fallback

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k vector_zero runs on a fixture target that ends with or vector(0).
  • THEN The test passes and the report names the dashboard uid, the panel title and the target refId, and the same target without the fallback gives no issue.

Requirement: Unbounded label rule

The linter SHALL report an error when a timeseries, graph or barchart Prometheus target groups by, or shows in its legend, one of the ten labels of CONST_GRAFANA_UNBOUNDED_LABELS and holds no positive matcher for that label.

Scenario: Unbounded pod label

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k unbounded_label runs on a fixture target that groups by pod and holds no pod matcher.
  • THEN The test passes and the report names the dashboard uid, the panel title and the target refId, and the same target with pod=~"$pod" gives no issue, and a label outside the ten gives no issue.

Requirement: Histogram count on a seconds axis

The linter SHALL report an error when a Prometheus target expression contains histogram_count, the panel unit is s or ms, and no field override names the target refId.

Scenario: Histogram count on a seconds panel

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k histogram_count_unit runs on a fixture panel with unit s and a target that contains histogram_count.
  • THEN The test passes and the report names the dashboard uid, the panel title and the target refId, and a field override for that refId with unit short gives no issue.

Requirement: Panels in collapsed rows

The linter SHALL check each panel inside a collapsed row and count it in panel_count.

Scenario: Defect in a collapsed row

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k collapsed_row runs on a fixture dashboard whose collapsed row holds a panel with a lint defect.
  • THEN The test passes and the report names the defect with the dashboard, the panel and the refId, and panel_count includes the nested panel.

Requirement: Product dashboards lint clean

Each dashboard JSON file under k8s/devops/dashboards/ MUST lint clean with no per-file and no per-rule exemption.

Scenario: Product dashboard lint test

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k test_repository_dashboards_lint_clean runs over each dashboard JSON file under k8s/devops/dashboards/.
  • THEN The test passes for every file, and no fixed rate or increase window remains.

Requirement: Service dashboard burn-rate rules

The service dashboard generator SHALL write a Prometheus recording rule for each burn-rate window of each spec and SHALL query the recording rule in the burn-rate chart.

Scenario: Generated service dashboard burn rate

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k service_dashboard_burn_rate runs on a fixture ServiceSpec.
  • THEN The test passes and the generated dashboard target uses the recording rule metric, and the generated rules file holds the 1 h and 6 h recording rules.

Requirement: Dashboard test runtime

The new rules SHALL add less than 2 s to the dashboard test run.

Scenario: Dashboard lint runtime

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py --durations=0 runs.
  • THEN The lint test of the product dashboards reports a duration under 2 s.

Requirement: Dashboard rules documentation

The dashboard section of k8s/README.md SHALL name each of the five rules and the ten unbounded labels.

Scenario: Rules in the k8s README

  • WHEN uv run pytest tests/grafana/test_grafana_dashboards.py -k rules_documented runs.
  • THEN The test passes and the dashboard section of k8s/README.md names the five rules and the ten labels.

Existing Tool Considered

The alternatives check of 2026-11-26 in the issue body records not-applicable (class test, no search) and names no tool. No open, maintained tool covers the need. The issue body records grafana/dashboard-linter v0.4.0 as the one candidate: its target-rate-interval-rule covers only rate() without $__rate_interval, and it has no rule for $__range, increase windows, legends, units or or vector(0), and it takes no custom rules. The proposal adds the five rules to the existing linter and builds no separate linter. The written cost to build and keep the five rules is about 100,000 tokens, 3,000 tokens a month and 2 h elapsed.

Key questions

  • Which panel types do rules 1 to 4 apply to, and which panel types does rule 5 apply to?: Rules 1 to 4 apply to timeseries, graph and barchart Prometheus targets. Rule 5 applies to each panel type with a Prometheus target. A stat, table, gauge or heatmap panel gets no range-variable error. (best practice) [sources: src/devops_cli/grafana/linter.py, k8s/devops/dashboards/ai-spend.json]
    • Rejected: Every rule on every panel type. A non-graph panel such as Active AI Backends uses $__range on purpose.
    • Chosen: Graph panels for rules 1 to 4, every panel for rule 5. It matches the measured defects and keeps correct non-graph panels.
  • What makes a label bound for the unbounded-label rule, and which labels does it check?: The rule checks the ten labels in a new CONST_GRAFANA_UNBOUNDED_LABELS constant in src/devops_cli/config/constants.py: pod, release, workflow, sub_command, run_id, item, branch, host_name, client_ip and user_agent. A label is bound only by a positive matcher for it in the same target expression, such as pod=~"$pod". A by() clause or a legend over a label with no such matcher is an error. (best practice) [sources: src/devops_cli/config/constants.py, src/devops_cli/grafana/linter.py]
    • Rejected: Any by() or legend of the ten labels. It refuses a query that filters pod=~"$pod" and needs a per-file exemption.
    • Rejected: A dashboard template variable bounds the label. A template variable is no filter, so the query still returns every series.
    • Chosen: A positive matcher in the same target expression. It detects an unbounded series and accepts the query that filters it.
  • How does the linter detect a histogram_count target on a seconds axis?: It reports an error when the target expression contains histogram_count, the panel unit is s or ms, and no field override names the target refId with a count unit. It applies to every panel type. (best practice) [sources: src/devops_cli/grafana/linter.py, src/devops_cli/grafana/schema.py]
    • Rejected: Panel unit only. It refuses a panel that overrides the unit for the histogram target.
    • Chosen: Panel unit plus a refId override. It allows a correct per-target unit override and still catches the defect.
  • Should the linter check the panels inside collapsed rows?: Yes. The linter flattens the panels of each row recursively before it runs the checks, and panel_count counts each nested panel. (best practice) [sources: src/devops_cli/grafana/schema.py:133, src/devops_cli/grafana/linter.py]
    • Rejected: Leave nested panels unchecked. The generated service dashboards hold panels in collapsed rows, so a rule would skip them and the test would pass a defect.
    • Chosen: Flatten row panels before the checks. It applies each rule to each panel with no per-file exemption.
  • How does the service dashboard generator avoid fixed burn-rate windows?: The generator writes a Prometheus recording rule for each burn-rate window of each spec and queries the recording rule in the burn-rate chart. The 1 h and 6 h windows stay fixed in the recording rule, not in the dashboard target. (best practice) [sources: src/devops_cli/grafana/service_dashboard.py, k8s/devops/monitoring/prometheus-rules-values.yaml]
    • Rejected: Use $__rate_interval in the burn-rate chart. It changes the 1 h and 6 h burn-rate window and makes the page lines wrong.
    • Chosen: Write a recording rule for each burn-rate window. It keeps the 1 h and 6 h windows and passes the fixed-window rule.
  • Where does the service dashboard generator write its burn-rate recording rules?: It writes <uid>-rules.yaml next to the dashboard file. The file holds a Prometheus rule group with one recording rule for each burn-rate window. (best practice) [sources: src/devops_cli/grafana/service_dashboard.py]
    • Rejected: Add static rules to k8s/devops/monitoring/prometheus-rules-values.yaml. The file cannot hold a rule for each service spec in homelab.
    • Chosen: Write a rules file next to the dashboard. The generator has the selectors of each spec and writes the rules with the dashboard.
  • Which dashboards must the lint test cover?: Every dashboard JSON file under k8s/devops/dashboards/. The test enumerates the files and does not fix a count. [sources: tests/grafana/test_grafana_dashboards.py]
  • Does the environment freeze block this change?: No. The change edits k8s/devops/dashboards/, k8s/README.md and src/devops_cli/grafana/. The freeze refuses a non-Markdown file under k8s/ outside k8s/devops and k8s/overlays/homelab/devops. It allows these paths. The change needs no feat(argocd): read the environment from the homelab repo #5134 step 17. [sources: docs/HOMELAB_REPO_SWITCH.md]
  • Where do the five rules go in the documentation?: In the dashboard section of k8s/README.md. The environment freeze allows a Markdown change under k8s/, and the issue names this section. (best practice) [sources: k8s/README.md]
    • Rejected: docs/guidelines/kubernetes.md. A guideline names no path of an environment tree, and the rules apply to the dashboard files of this tree.
    • Chosen: The dashboard section of k8s/README.md. The issue names it, and the freeze allows a Markdown change there.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#4684, #4707, #4712, #4718, #4724, #4728, #4732

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/test
    scope/monitoring
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/test. The test prefix of the title gives the type.
    • Scope: scope/monitoring. The (monitoring) scope of the title gives the scope.
    • Priority: P2-Medium. Catches real defects shipping in dashboards but is a quality gate, not a user-facing fix.
    • Value: Medium. Prevents a class of dashboard errors from shipping but does not fix a single user-facing bug.
    • Effort: Medium. Five new rules, four dashboard fixes, tests, and documentation.
    • Related: fix(telemetry): grafana dashboard projections, rolling averages, and panel queries #1175, which asks for a different change. Both concern Grafana dashboard query correctness, but #1175 fixes specific broken queries while the candidate adds automated lint rules to catch a class of errors.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    A gap found while building #5184: lint_dashboard reads only the top-level panels (Dashboard.panels of src/devops_cli/grafana/schema.py), so it does not check the panels of a collapsed row. The generated devops-roadmap-service.json and devops-sre-service.json hold their capacity, log and flame graph panels in collapsed rows, and devops grafana dashboards lint reports 15 panels for each, not 22 or 23.

    When the linter reads the panels of a collapsed row, a Pyroscope target needs its own rule: the Pyroscope query has labelSelector and profileTypeId and no expr, so the empty-query check would refuse it. pyroscope.json today holds an extra expr on each target only for the linter.

  6. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: test. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-14. A person decides what this means for the item. The check changes no label and closes no issue.

  7. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 699a4ef while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

  8. added
    status/ready
    and removed
    status/new
    on Nov 18, 2026
  9. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at f771237 (see proposed design in issue body).

  10. 8 remaining items

  11. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block and Watched files in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  12. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Owner question: See Suspected block and Watched files in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  13. added
    status/ready
    and removed
    status/new
    on Nov 26, 2026
  14. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  15. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  16. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  17. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 20:38 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/monitoringsource/agenttype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions