Skip to content

Commit

Permalink
Fix tags support in file/disable comments
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Dec 16, 2022
1 parent 3065b96 commit 1f974dc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/pint/tests/0115_file_disable_tag.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pint.ok -l debug --no-color lint rules
! stdout .
cmp stderr stderr.txt

-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=debug msg="File parsed" path=rules/0001.yml rules=1
level=debug msg="Starting query workers" name=prom uri=http://127.0.0.1:7103 workers=16
level=debug msg="Found recording rule" lines="6 8" path=rules/0001.yml record=colo:test1
level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/0001.yml rule=colo:test1
level=debug msg="Stopping query workers" name=prom uri=http://127.0.0.1:7103
-- rules/0001.yml --
# pint file/disable promql/series(+bar)
# pint file/disable promql/rate(+bar)
# pint file/disable promql/range_query(+bar)
# pint file/disable labels/conflict(+foo)

- record: "colo:test1"
# pint file/disable rule/duplicate(+foo)
expr: sum(foo) without(job)

# pint file/disable promql/vector_matching(+foo)

-- .pint.hcl --
prometheus "prom" {
uri = "http://127.0.0.1:7103"
tags = ["foo", "bar"]
}
parser {
relaxed = [".*"]
}
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.38.1

### Fixed

- `# pint file/disable` comments didn't properly handle Prometheus tags, this is fixed now.

## v0.38.0

### Added
Expand Down
6 changes: 6 additions & 0 deletions docs/ignoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ anywhere in the file. This will disable given check for all rules in that file.

See each individual [check](checks/index.md) documentation for details.

You can also use tags set on Prometheus configuration blocks inside comments.
Tags must use `+` prefix, so if you want to disable `promql/series` check on all
Prometheus servers with `testing` tag then add this comment:

`# pint file/disable promql/series(+testing)`

## Disabling individual checks for specific rules

To disable individual check for a specific rule use `# pint disable ...` comments.
Expand Down
5 changes: 5 additions & 0 deletions internal/config/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ func isEnabled(enabledChecks, disabledChecks []string, rule parser.Rule, name st
if c == name || c == instance {
return false
}
for _, tag := range promTags {
if c == fmt.Sprintf("%s(+%s)", name, tag) {
return false
}
}
}
if len(enabledChecks) == 0 {
return true
Expand Down

0 comments on commit 1f974dc

Please sign in to comment.