[dmt] linter for checking rules and dashboards for source=deckhouse label#371
Open
rvekaterina wants to merge 12 commits into
Open
[dmt] linter for checking rules and dashboards for source=deckhouse label#371rvekaterina wants to merge 12 commits into
rvekaterina wants to merge 12 commits into
Conversation
diyliv
reviewed
May 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new Templates linter rule (source-label) to enforce that PrometheusRule expressions and Grafana dashboard PromQL queries include the source="deckhouse" label selector, with support for module-level opt-out and metric allowlisting.
Changes:
- Added
source-labelrule implementation (PromQL AST inspection + Grafana dashboard/query parsing) with exclusions for recording rules and synthetic metrics. - Wired the new rule into the Templates linter execution flow and configuration mapping (local + global rule impact, per-module settings).
- Added unit tests for glob matching, datasource detection, Grafana query sanitization, and core rule behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/linters/templates/templates.go | Instantiates and runs the new source-label rule for PrometheusRule objects and Grafana dashboards. |
| pkg/linters/templates/rules/source_label.go | Implements PromQL inspection + Grafana dashboard parsing/sanitization to enforce source="deckhouse". |
| pkg/linters/templates/rules/source_label_test.go | Adds unit tests for the new rule helpers and core checking behavior. |
| pkg/config/linters_settings.go | Adds per-module config schema for templates.source-label settings and rule level mapping. |
| pkg/config/global/global.go | Adds global rule level configuration entry for source-label. |
| pkg/config.go | Extends runtime linter config with SourceLabelSettings (incl. recording rule names injection). |
| internal/module/module.go | Adds a setter to inject collected recording rule names into module linter config before linting. |
| internal/manager/manager.go | Collects recording rule names across modules once and injects them into each module prior to running linters. |
| internal/values/global-openapi/values.yaml | Updates enabledModules examples/defaults (appears unrelated to the linter change). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
source-labelthat checks all PrometheusRule expressions and Grafana dashboard panel queries for the presence of thesource="deckhouse"label selector on every metric.ALERTS,ALERTS_FOR_STATE) are excluded.disableflag,allowed-metricslist with glob pattern support (e.g.coredns_*).Example
Module
.dmtlint.yamlconfig: