Skip to content

[dmt] linter for checking rules and dashboards for source=deckhouse label#371

Open
rvekaterina wants to merge 12 commits into
mainfrom
feat/source-label-linter
Open

[dmt] linter for checking rules and dashboards for source=deckhouse label#371
rvekaterina wants to merge 12 commits into
mainfrom
feat/source-label-linter

Conversation

@rvekaterina
Copy link
Copy Markdown

@rvekaterina rvekaterina commented May 24, 2026

Summary

  • New linter rule source-label that checks all PrometheusRule expressions and Grafana dashboard panel queries for the presence of the source="deckhouse" label selector on every metric.
  • Recording rule names are automatically collected across all modules and excluded from the check.
  • Synthetic Prometheus metrics (ALERTS, ALERTS_FOR_STATE) are excluded.
  • Per-module configuration: disable flag, allowed-metrics list with glob pattern support (e.g. coredns_*).
  • Bug fix: operator-prometheus -> operator-prometheus-crd

Example

Module .dmtlint.yaml config:

linters:
  templates:
    source-label:
      disable: false
      allowed-metrics:
        - "coredns_*"
        - "etcd_*"

@diyliv diyliv assigned diyliv and unassigned diyliv May 25, 2026
@diyliv diyliv self-requested a review May 25, 2026 13:45
Copy link
Copy Markdown
Contributor

@diyliv diyliv left a comment

Choose a reason for hiding this comment

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

please fill the pr description in this format:

Summary

<what the pr does, bullet points>

Example

<usage / config examples>

Comment thread pkg/linters/templates/rules/source_label.go
Comment thread pkg/linters/templates/rules/source_label.go
Comment thread pkg/linters/templates/rules/source_label.go Outdated
Comment thread pkg/linters/templates/rules/source_label.go Outdated
Comment thread pkg/linters/templates/rules/source_label.go
Comment thread pkg/linters/templates/rules/source_label.go Outdated
@diyliv diyliv added enhancement New feature or request go Pull requests that update go code labels May 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-label rule 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.

Comment thread pkg/linters/templates/rules/source_label.go
Comment thread pkg/linters/templates/rules/source_label.go
Comment thread pkg/linters/templates/rules/source_label_test.go
Comment thread internal/values/global-openapi/values.yaml
@rvekaterina rvekaterina marked this pull request as ready for review May 26, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants