From a37871f18cab22289fbc02d1020987059eb90040 Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Fri, 11 Mar 2022 09:21:56 +0000 Subject: [PATCH] Bump promql/regexp severity to bug --- cmd/pint/tests/0003_lint_workdir.txt | 15 ++++++++++++--- docs/changelog.md | 1 + internal/checks/promql_regexp.go | 2 +- internal/checks/promql_regexp_test.go | 12 ++++++------ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/cmd/pint/tests/0003_lint_workdir.txt b/cmd/pint/tests/0003_lint_workdir.txt index 86c68ac0..02e50331 100644 --- a/cmd/pint/tests/0003_lint_workdir.txt +++ b/cmd/pint/tests/0003_lint_workdir.txt @@ -5,7 +5,7 @@ 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) @@ -13,6 +13,12 @@ rules/0001.yml:2: job label is required and should be preserved when aggregating 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) @@ -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 @@ -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 diff --git a/docs/changelog.md b/docs/changelog.md index a12576b0..6616cb2b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/internal/checks/promql_regexp.go b/internal/checks/promql_regexp.go index 2bdafb0a..f49cd46f 100644 --- a/internal/checks/promql_regexp.go +++ b/internal/checks/promql_regexp.go @@ -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, }) } } diff --git a/internal/checks/promql_regexp_test.go b/internal/checks/promql_regexp_test.go index cb92d4f9..cca7dd1a 100644 --- a/internal/checks/promql_regexp_test.go +++ b/internal/checks/promql_regexp_test.go @@ -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, }, }, }, @@ -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, }, }, }, @@ -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, }, }, },