Skip to content

Commit 983e1fb

Browse files
committed
Fix default state handling
1 parent b2f7bfd commit 983e1fb

28 files changed

+79
-62
lines changed

cmd/pint/scan.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func checkRules(ctx context.Context, workers int, isOffline bool, gen *config.Pr
7878
slog.String("path", entry.Path.Name),
7979
slog.String("record", entry.Rule.RecordingRule.Record.Value),
8080
slog.String("lines", entry.Rule.Lines.String()),
81+
slog.String("state", entry.State.String()),
8182
)
8283
}
8384
if entry.Rule.AlertingRule != nil {
@@ -86,12 +87,14 @@ func checkRules(ctx context.Context, workers int, isOffline bool, gen *config.Pr
8687
slog.String("path", entry.Path.Name),
8788
slog.String("alert", entry.Rule.AlertingRule.Alert.Value),
8889
slog.String("lines", entry.Rule.Lines.String()),
90+
slog.String("state", entry.State.String()),
8991
)
9092
}
9193
if entry.Rule.Error.Err != nil {
9294
slog.Debug("Found invalid rule",
9395
slog.String("path", entry.Path.Name),
9496
slog.String("lines", entry.Rule.Lines.String()),
97+
slog.String("state", entry.State.String()),
9598
)
9699
rulesParsedTotal.WithLabelValues(config.InvalidRuleType).Inc()
97100
}

cmd/pint/tests/0018_match_alerting.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ level=INFO msg="Finding all rules to check" paths=["rules"]
99
level=DEBUG msg="File parsed" path=rules/0001.yml rules=2
1010
level=DEBUG msg="Glob finder completed" count=2
1111
level=DEBUG msg="Generated all Prometheus servers" count=0
12-
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=1-2
12+
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=1-2 state=noop
1313
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:recording
14-
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=4-5
14+
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=4-5 state=noop
1515
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:alerting
1616
rules/0001.yml:5 Warning: Alert query doesn't have any condition, it will always fire if the metric exists. (alerts/comparison)
1717
5 | expr: sum(bar) without(job)

cmd/pint/tests/0019_match_recording.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ level=INFO msg="Finding all rules to check" paths=["rules"]
99
level=DEBUG msg="File parsed" path=rules/0001.yml rules=2
1010
level=DEBUG msg="Glob finder completed" count=2
1111
level=DEBUG msg="Generated all Prometheus servers" count=0
12-
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=1-2
12+
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=1-2 state=noop
1313
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording
14-
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=4-5
14+
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=4-5 state=noop
1515
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:alerting
1616
rules/0001.yml:2 Warning: `job` label is required and should be preserved when aggregating `^.+$` rules, remove job from `without()`. (promql/aggregate)
1717
2 | expr: sum(foo) without(job)

cmd/pint/tests/0020_ignore_kind.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ level=INFO msg="Finding all rules to check" paths=["rules"]
99
level=DEBUG msg="File parsed" path=rules/0001.yml rules=2
1010
level=DEBUG msg="Glob finder completed" count=2
1111
level=DEBUG msg="Generated all Prometheus servers" count=0
12-
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=4-5
12+
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=4-5 state=noop
1313
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording
14-
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=7-8
14+
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=7-8 state=noop
1515
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:alerting
1616
rules/0001.yml:5 Warning: `job` label is required and should be preserved when aggregating `^.+$` rules, remove job from `without()`. (promql/aggregate)
1717
5 | expr: sum(foo) without(job)

cmd/pint/tests/0037_disable_checks.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ level=DEBUG msg="Glob finder completed" count=3
1111
level=INFO msg="Configured new Prometheus server" name=prom uris=1 uptime=up tags=[] include=[] exclude=[]
1212
level=DEBUG msg="Starting query workers" name=prom uri=http://127.0.0.1 workers=16
1313
level=DEBUG msg="Generated all Prometheus servers" count=1
14-
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=default-for lines=1-3
14+
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=default-for lines=1-3 state=noop
1515
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","rule/duplicate(prom)","labels/conflict(prom)","alerts/absent(prom)"] path=rules/0001.yml rule=default-for
16-
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=sum:job lines=5-6
16+
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=sum:job lines=5-6 state=noop
1717
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","rule/duplicate(prom)","labels/conflict(prom)","alerts/absent(prom)","promql/aggregate(job:true)"] path=rules/0001.yml rule=sum:job
18-
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=no-comparison lines=8-9
18+
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=no-comparison lines=8-9 state=noop
1919
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","rule/duplicate(prom)","labels/conflict(prom)","alerts/absent(prom)"] path=rules/0001.yml rule=no-comparison
2020
rules/0001.yml:6 Warning: `job` label is required and should be preserved when aggregating `^.+$` rules, use `by(job, ...)`. (promql/aggregate)
2121
6 | expr: sum(foo)

cmd/pint/tests/0039_prom_selected_path.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ level=DEBUG msg="Glob finder completed" count=3
1111
level=INFO msg="Configured new Prometheus server" name=disabled uris=1 uptime=up tags=[] include=["^invalid/.+$"] exclude=["^invalid/rules/.+$"]
1212
level=DEBUG msg="Starting query workers" name=disabled uri=http://127.0.0.1:123 workers=16
1313
level=DEBUG msg="Generated all Prometheus servers" count=1
14-
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=first lines=1-3
14+
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=first lines=1-3 state=noop
1515
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=first
16-
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=second lines=5-6
16+
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=second lines=5-6 state=noop
1717
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=second
18-
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=third lines=8-9
18+
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=third lines=8-9 state=noop
1919
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=third
2020
rules/0001.yml:6 Warning: `job` label is required and should be preserved when aggregating `^.+$` rules, use `by(job, ...)`. (promql/aggregate)
2121
6 | expr: sum(bar)

cmd/pint/tests/0040_rule_match_label.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ level=INFO msg="Finding all rules to check" paths=["rules"]
99
level=DEBUG msg="File parsed" path=rules/rules.yml rules=4
1010
level=DEBUG msg="Glob finder completed" count=4
1111
level=DEBUG msg="Generated all Prometheus servers" count=0
12-
level=DEBUG msg="Found recording rule" path=rules/rules.yml record=ignore lines=1-2
12+
level=DEBUG msg="Found recording rule" path=rules/rules.yml record=ignore lines=1-2 state=noop
1313
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/rules.yml rule=ignore
14-
level=DEBUG msg="Found recording rule" path=rules/rules.yml record=match lines=4-7
14+
level=DEBUG msg="Found recording rule" path=rules/rules.yml record=match lines=4-7 state=noop
1515
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/rules.yml rule=match
16-
level=DEBUG msg="Found alerting rule" path=rules/rules.yml alert=ignore lines=9-10
16+
level=DEBUG msg="Found alerting rule" path=rules/rules.yml alert=ignore lines=9-10 state=noop
1717
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/rules.yml rule=ignore
18-
level=DEBUG msg="Found alerting rule" path=rules/rules.yml alert=match lines=12-15
18+
level=DEBUG msg="Found alerting rule" path=rules/rules.yml alert=match lines=12-15 state=noop
1919
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/rules.yml rule=match
2020
rules/rules.yml:5 Warning: `job` label is required and should be preserved when aggregating `^.*$` rules, use `by(job, ...)`. (promql/aggregate)
2121
5 | expr: sum(foo)

cmd/pint/tests/0052_match_multiple.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ level=INFO msg="Finding all rules to check" paths=["rules"]
99
level=DEBUG msg="File parsed" path=rules/0001.yml rules=2
1010
level=DEBUG msg="Glob finder completed" count=2
1111
level=DEBUG msg="Generated all Prometheus servers" count=0
12-
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=4-5
12+
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=4-5 state=noop
1313
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:recording
14-
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=7-8
14+
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=7-8 state=noop
1515
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/aggregate(job:true)"] path=rules/0001.yml rule=colo:alerting
1616
rules/0001.yml:5 Warning: `job` label is required and should be preserved when aggregating `^.+$` rules, remove job from `without()`. (promql/aggregate)
1717
5 | expr: sum(foo) without(job)

cmd/pint/tests/0053_ignore_multiple.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ level=INFO msg="Finding all rules to check" paths=["rules"]
99
level=DEBUG msg="File parsed" path=rules/0001.yml rules=2
1010
level=DEBUG msg="Glob finder completed" count=2
1111
level=DEBUG msg="Generated all Prometheus servers" count=0
12-
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=4-5
12+
level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:recording lines=4-5 state=noop
1313
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:recording
14-
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=7-8
14+
level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=colo:alerting lines=7-8 state=noop
1515
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:alerting
1616
-- rules/0001.yml --
1717
groups:

cmd/pint/tests/0092_dir_symlink.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ level=INFO msg="Finding all rules to check" paths=["rules","linked","rules/src/r
1212
level=DEBUG msg="File parsed" path=rules/src/rule.yaml rules=1
1313
level=DEBUG msg="Glob finder completed" count=1
1414
level=DEBUG msg="Generated all Prometheus servers" count=0
15-
level=DEBUG msg="Found recording rule" path=rules/src/rule.yaml record=down lines=4-5
15+
level=DEBUG msg="Found recording rule" path=rules/src/rule.yaml record=down lines=4-5 state=noop
1616
level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp"] path=rules/src/rule.yaml rule=down
1717
-- rules/src/rule.yaml --
1818
groups:

0 commit comments

Comments
 (0)