diff --git a/cmd/pint/lint.go b/cmd/pint/lint.go index e3f01775..6bc743f3 100644 --- a/cmd/pint/lint.go +++ b/cmd/pint/lint.go @@ -72,8 +72,10 @@ func actionLint(c *cli.Context) (err error) { problems += c } } - if problems > 0 { + if len(bySeverity) > 0 { log.Info().Fields(bySeverity).Msg("Problems found") + } + if problems > 0 { return fmt.Errorf("problems found") } diff --git a/cmd/pint/tests/0012_issue_20.txt b/cmd/pint/tests/0012_issue_20.txt index ae59d289..e290680d 100644 --- a/cmd/pint/tests/0012_issue_20.txt +++ b/cmd/pint/tests/0012_issue_20.txt @@ -11,6 +11,7 @@ rules/1.yaml:9-13: runbook_url annotation is required (alerts/annotation) summary: "HAProxy server healthcheck failure (instance {{ $labels.instance }})" description: "Some server healthcheck are failing on {{ $labels.server }}\n VALUE = {{ $value }}\n LABELS: {{ $labels }}" +level=info msg="Problems found" Warning=1 -- rules/1.yaml -- groups: - name: "haproxy.api_server.rules" diff --git a/cmd/pint/tests/0018_match_alerting.txt b/cmd/pint/tests/0018_match_alerting.txt index 2f1ae1c0..45ab434b 100644 --- a/cmd/pint/tests/0018_match_alerting.txt +++ b/cmd/pint/tests/0018_match_alerting.txt @@ -15,6 +15,7 @@ rules/0001.yml:5: alert query doesn't have any condition, it will always fire if rules/0001.yml:5: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) expr: sum(bar) without(job) +level=info msg="Problems found" Warning=2 -- rules/0001.yml -- - record: "colo:recording" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0019_match_recording.txt b/cmd/pint/tests/0019_match_recording.txt index 45497f40..d8c921ee 100644 --- a/cmd/pint/tests/0019_match_recording.txt +++ b/cmd/pint/tests/0019_match_recording.txt @@ -12,6 +12,7 @@ level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/fo rules/0001.yml:2: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) expr: sum(foo) without(job) +level=info msg="Problems found" Warning=1 -- rules/0001.yml -- - record: "colo:recording" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0020_ignore_kind.txt b/cmd/pint/tests/0020_ignore_kind.txt index 973b1892..b6f1e347 100644 --- a/cmd/pint/tests/0020_ignore_kind.txt +++ b/cmd/pint/tests/0020_ignore_kind.txt @@ -15,6 +15,7 @@ rules/0001.yml:2: job label is required and should be preserved when aggregating rules/0001.yml:5: alert query doesn't have any condition, it will always fire if the metric exists (alerts/comparison) expr: sum(bar) without(job) +level=info msg="Problems found" Warning=2 -- rules/0001.yml -- - record: "colo:recording" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0022_ignore_multi.txt b/cmd/pint/tests/0022_ignore_multi.txt index 0422aade..7574dc86 100644 --- a/cmd/pint/tests/0022_ignore_multi.txt +++ b/cmd/pint/tests/0022_ignore_multi.txt @@ -11,6 +11,7 @@ rules/1.yaml:2: dropped label should be removed when aggregating "^.+$" rules, r rules/1.yaml:5: keep label is required and should be preserved when aggregating "^.+$" rules, remove keep from without() (promql/aggregate) expr: sum(errors_total) without(keep,dropped) +level=info msg="Problems found" Warning=2 -- rules/1.yaml -- - record: disabled expr: sum(errors_total) by(keep,dropped) diff --git a/cmd/pint/tests/0037_disable_checks.txt b/cmd/pint/tests/0037_disable_checks.txt index 71d94e12..4af4204b 100644 --- a/cmd/pint/tests/0037_disable_checks.txt +++ b/cmd/pint/tests/0037_disable_checks.txt @@ -8,6 +8,7 @@ level=info msg="File parsed" path=rules/0001.yml rules=3 rules/0001.yml:6: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate) expr: sum(foo) +level=info msg="Problems found" Warning=1 -- rules/0001.yml -- - alert: default-for expr: foo > 1 diff --git a/cmd/pint/tests/0038_disable_checks_regex.txt b/cmd/pint/tests/0038_disable_checks_regex.txt index 0e8319f7..92352afa 100644 --- a/cmd/pint/tests/0038_disable_checks_regex.txt +++ b/cmd/pint/tests/0038_disable_checks_regex.txt @@ -8,6 +8,7 @@ level=info msg="File parsed" path=rules/0001.yml rules=3 rules/0001.yml:6: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate) expr: sum(foo) +level=info msg="Problems found" Warning=1 -- rules/0001.yml -- - alert: default-for expr: foo > 1 diff --git a/cmd/pint/tests/0039_prom_selected_path.txt b/cmd/pint/tests/0039_prom_selected_path.txt index 3eb26b0b..9293c79f 100644 --- a/cmd/pint/tests/0039_prom_selected_path.txt +++ b/cmd/pint/tests/0039_prom_selected_path.txt @@ -14,6 +14,7 @@ level=debug msg="Configured checks for rule" enabled=["promql/syntax","alerts/fo rules/0001.yml:6: job label is required and should be preserved when aggregating "^.+$" rules, use by(job, ...) (promql/aggregate) expr: sum(bar) +level=info msg="Problems found" Warning=1 -- rules/0001.yml -- - alert: first expr: foo > 1 diff --git a/cmd/pint/tests/0040_rule_match_label.txt b/cmd/pint/tests/0040_rule_match_label.txt index 6d4fd4c4..0aa87181 100644 --- a/cmd/pint/tests/0040_rule_match_label.txt +++ b/cmd/pint/tests/0040_rule_match_label.txt @@ -19,6 +19,7 @@ rules/rules.yml:5: job label is required and should be preserved when aggregatin rules/rules.yml:13: job label is required and should be preserved when aggregating "^.*$" rules, use by(job, ...) (promql/aggregate) expr: sum(foo) > 0 +level=info msg="Problems found" Warning=2 -- rules/rules.yml -- - record: ignore expr: sum(foo) diff --git a/cmd/pint/tests/0052_match_multiple.txt b/cmd/pint/tests/0052_match_multiple.txt index 306cf80e..37e05ba3 100644 --- a/cmd/pint/tests/0052_match_multiple.txt +++ b/cmd/pint/tests/0052_match_multiple.txt @@ -15,6 +15,7 @@ rules/0001.yml:2: job label is required and should be preserved when aggregating rules/0001.yml:5: job label is required and should be preserved when aggregating "^.+$" rules, remove job from without() (promql/aggregate) expr: sum(bar) without(job) > 0 +level=info msg="Problems found" Warning=2 -- rules/0001.yml -- - record: "colo:recording" expr: sum(foo) without(job) diff --git a/cmd/pint/tests/0056_prometheus_required.txt b/cmd/pint/tests/0056_prometheus_required.txt index e4d2fbd0..d6351ccd 100644 --- a/cmd/pint/tests/0056_prometheus_required.txt +++ b/cmd/pint/tests/0056_prometheus_required.txt @@ -2,7 +2,7 @@ pint.ok -l debug --no-color lint rules ! stdout . stderr 'level=error msg=\"Query failed" error=\"Post \\"https:///api/v1/query\\": http: no Host in request URL\" query=count\(up\) uri=https://' stderr 'level=error msg=\"Failed to query Prometheus configuration\" error=\"Get \\"https:///api/v1/status/config\\": http: no Host in request URL\" uri=https://' -! stderr 'level=info msg="Problems found"' +stderr 'level=info msg="Problems found" Warning=8' -- rules/1.yaml -- - record: one diff --git a/docs/changelog.md b/docs/changelog.md index 556dc41c..771f0853 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,11 @@ # Changelog +## v0.14.1 + +### Changed + +- Always print the number of detected problems when running `pint lint`. + ## v0.14.0 ### Added