Skip to content

fix(grafanactl): require a regex on the dashboard datasource variable#249

Merged
stevekuznetsov merged 1 commit into
Azure:mainfrom
mmazur:fix/require-datasource-regex
Jun 16, 2026
Merged

fix(grafanactl): require a regex on the dashboard datasource variable#249
stevekuznetsov merged 1 commit into
Azure:mainfrom
mmazur:fix/require-datasource-regex

Conversation

@mmazur

@mmazur mmazur commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What

Promote the dashboard datasource-variable regex check from a warning to a hard validation error in grafanactl.

Why

validateDashboard previously only warned when a datasource template variable had no regex. A dashboard with an unconstrained datasource picker — which lists every datasource in the org, including obsolete Managed Prometheus datasources that carry no data — would still pass grafanactl verify dashboards in CI.

Making it an error lets teams enforce that every dashboard constrains its datasource variable. Dashboards that intentionally allow any datasource can set a permissive regex (e.g. ^Managed_Prometheus_.*$).

This complements Azure/ARO-HCP#5653, which gives every ARO-HCP dashboard a datasource regex; with that merged, no ARO-HCP dashboard is left unfiltered, so this check can be enforced without breaking CI.

Changes

  • internal/grafana/syncer.go: missing-regex issue moved from warnings to errors (one-line change).

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 15, 2026 16:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds validation coverage and tightens dashboard validation so missing datasource regex is treated as an error (not just a warning).

Changes:

  • Add unit tests asserting missing datasource regex is an error and that a present regex passes.
  • Promote “missing datasource variable regex” from warning to error in validateDashboard.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tools/grafanactl/internal/grafana/validate_test.go New tests for the updated regex validation severity/behavior.
tools/grafanactl/internal/grafana/syncer.go Changes validation outcome from warning to error and clarifies rationale in comments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/grafanactl/internal/grafana/validate_test.go Outdated
Comment thread tools/grafanactl/internal/grafana/syncer.go
@mmazur mmazur force-pushed the fix/require-datasource-regex branch from f347494 to 8a46a79 Compare June 15, 2026 16:39
Dashboard validation previously only emitted a *warning* when a
datasource template variable had no regex. As a result, dashboards could
ship with an unconstrained datasource picker that lists every datasource
in the org -- including obsolete Managed Prometheus datasources that
carry no data -- and still pass `grafanactl verify dashboards` in CI.

Promote the missing-regex check from a warning to a hard validation
error so CI fails when a dashboard does not constrain its datasource
variable. Dashboards that intentionally want any datasource can set a
permissive regex (e.g. ^Managed_Prometheus_.*$).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 15, 2026 16:40
@mmazur mmazur force-pushed the fix/require-datasource-regex branch from 8a46a79 to 1de2f20 Compare June 15, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread tools/grafanactl/internal/grafana/syncer.go
Comment thread tools/grafanactl/internal/grafana/syncer.go

@raelga raelga left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm
/approve

mmazur added a commit to mmazur/ARO-HCP that referenced this pull request Jun 16, 2026
Adds a proper dashboard whose datasource variable has an empty regex, to
observe how the observability-verify CI check handles it.

With the current grafanactl this is only a warning (CI passes); once
Azure/ARO-Tools#249 lands and the grafanactl dependency is bumped, the
missing regex becomes a hard error. For demonstration only -- not
intended to merge.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@stevekuznetsov

Copy link
Copy Markdown
Contributor

/ok-to-test
/test all

@stevekuznetsov stevekuznetsov merged commit 1847386 into Azure:main Jun 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants