Skip to content

Commit

Permalink
Bump promql/regexp severity to bug
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Mar 11, 2022
1 parent e4a8c23 commit a37871f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
15 changes: 12 additions & 3 deletions cmd/pint/tests/0003_lint_workdir.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ cmp stderr stderr.txt
-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=info msg="File parsed" path=rules/0001.yml rules=3
level=info msg="File parsed" path=rules/0002.yaml rules=1
level=info msg="File parsed" path=rules/0002.yaml rules=2
level=info msg="File parsed" path=rules/0003.yaml rules=10
rules/0001.yml:2: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate)
expr: sum(rate(fl_cf_html_bytes_in[10m])) WITHOUT (colo_id, instance, node_type, region, node_status, job, colo_name)

rules/0001.yml:6: instance label should be removed when aggregating "^colo(?:_.+)?:.+$" rules, use without(instance, ...) (promql/aggregate)
expr: sum(irate(foo[3m])) WITHOUT (colo_id)

rules/0002.yaml:2: unnecessary regexp match on static string job=~"foo", use job="foo" instead (promql/regexp)
expr: up{job=~"foo"} == 0

rules/0002.yaml:5: unnecessary regexp match on static string job!~"foo", use job!="foo" instead (promql/regexp)
expr: up{job!~"foo"} == 0

rules/0003.yaml:11: instance label should be removed when aggregating "^colo(?:_.+)?:.+$" rules, use without(instance, ...) (promql/aggregate)
expr: sum(foo) without(job)

Expand Down Expand Up @@ -64,7 +70,7 @@ rules/0003.yaml:40: instance label should be removed when aggregating "^colo(?:_
rules/0003.yaml:40: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate)
expr: sum(byinstance) by(instance)

level=info msg="Problems found" Fatal=1 Warning=12
level=info msg="Problems found" Bug=2 Fatal=1 Warning=12
level=fatal msg="Fatal error" error="problems found"
-- rules/0001.yml --
- record: colo_job:fl_cf_html_bytes_in:rate10m
Expand All @@ -76,7 +82,10 @@ level=fatal msg="Fatal error" error="problems found"

-- rules/0002.yaml --
- record: colo_job:down:count
expr: up == 0
expr: up{job=~"foo"} == 0

- record: colo_job:down:count
expr: up{job!~"foo"} == 0

-- rules/0003.yaml --
# pint ignore/begin
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Always print the number of detected problems when running `pint lint`.
- `promql/series` check was refactored and will now detect a range of
problems. See [promql/series](checks/promql/series.md) for details.
- `promql/regexp` severity is now `Bug` instead of a `Warning`.

## v0.14.0

Expand Down
2 changes: 1 addition & 1 deletion internal/checks/promql_regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c RegexpCheck) Check(ctx context.Context, rule parser.Rule) (problems []Pr
Lines: expr.Lines(),
Reporter: c.Reporter(),
Text: text,
Severity: Warning,
Severity: Bug,
})
}
}
Expand Down
12 changes: 6 additions & 6 deletions internal/checks/promql_regexp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func TestRegexpCheck(t *testing.T) {
{
Fragment: `foo{job=~"bar"}`,
Lines: []int{2},
Reporter: "promql/regexp",
Reporter: checks.RegexpCheckName,
Text: `unnecessary regexp match on static string job=~"bar", use job="bar" instead`,
Severity: checks.Warning,
Severity: checks.Bug,
},
},
},
Expand All @@ -55,9 +55,9 @@ func TestRegexpCheck(t *testing.T) {
{
Fragment: `foo{job!~"bar"}`,
Lines: []int{2},
Reporter: "promql/regexp",
Reporter: checks.RegexpCheckName,
Text: `unnecessary regexp match on static string job!~"bar", use job!="bar" instead`,
Severity: checks.Warning,
Severity: checks.Bug,
},
},
},
Expand All @@ -69,9 +69,9 @@ func TestRegexpCheck(t *testing.T) {
{
Fragment: `foo{job=~""}`,
Lines: []int{2},
Reporter: "promql/regexp",
Reporter: checks.RegexpCheckName,
Text: `unnecessary regexp match on static string job=~"", use job="" instead`,
Severity: checks.Warning,
Severity: checks.Bug,
},
},
},
Expand Down

0 comments on commit a37871f

Please sign in to comment.