From d4bb855aa09ce7305c925e11e8528699ce1743fc Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Fri, 26 Jul 2024 15:30:20 +0100 Subject: [PATCH] Fix alerts/absent config --- cmd/pint/tests/0037_disable_checks.txt | 6 +- cmd/pint/tests/0103_file_disable.txt | 2 +- .../config/__snapshots__/config_test.snap | 433 +++++++++--------- internal/config/config.go | 2 +- internal/config/config_test.go | 9 +- 5 files changed, 228 insertions(+), 224 deletions(-) diff --git a/cmd/pint/tests/0037_disable_checks.txt b/cmd/pint/tests/0037_disable_checks.txt index 850342b6..84178faf 100644 --- a/cmd/pint/tests/0037_disable_checks.txt +++ b/cmd/pint/tests/0037_disable_checks.txt @@ -11,11 +11,11 @@ level=INFO msg="Configured new Prometheus server" name=prom uris=1 uptime=up tag level=DEBUG msg="Starting query workers" name=prom uri=http://127.0.0.1 workers=16 level=DEBUG msg="Generated all Prometheus servers" count=1 level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=default-for lines=1-3 -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)"] path=rules/0001.yml rule=default-for +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 level=DEBUG msg="Found recording rule" path=rules/0001.yml record=sum:job lines=5-6 -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)","promql/aggregate(job:true)"] path=rules/0001.yml rule=sum:job +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 level=DEBUG msg="Found alerting rule" path=rules/0001.yml alert=no-comparison lines=8-9 -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)"] path=rules/0001.yml rule=no-comparison +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 rules/0001.yml:6 Warning: `job` label is required and should be preserved when aggregating `^.+$` rules, use `by(job, ...)`. (promql/aggregate) 6 | expr: sum(foo) diff --git a/cmd/pint/tests/0103_file_disable.txt b/cmd/pint/tests/0103_file_disable.txt index 2aad6835..b0a54823 100644 --- a/cmd/pint/tests/0103_file_disable.txt +++ b/cmd/pint/tests/0103_file_disable.txt @@ -11,7 +11,7 @@ level=INFO msg="Configured new Prometheus server" name=prom uris=1 uptime=up tag level=DEBUG msg="Starting query workers" name=prom uri=http://127.0.0.1:7103 workers=16 level=DEBUG msg="Generated all Prometheus servers" count=1 level=DEBUG msg="Found recording rule" path=rules/0001.yml record=colo:test1 lines=9-10 -level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","labels/conflict(prom)","alerts/external_labels(prom)"] path=rules/0001.yml rule=colo:test1 +level=DEBUG msg="Configured checks for rule" enabled=["promql/syntax","alerts/for","alerts/comparison","alerts/template","promql/fragile","promql/regexp","promql/vector_matching(prom)","labels/conflict(prom)","alerts/external_labels(prom)","alerts/absent(prom)"] 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 -- # This should skip all online checks diff --git a/internal/config/__snapshots__/config_test.snap b/internal/config/__snapshots__/config_test.snap index e225ca46..2e1dff49 100755 --- a/internal/config/__snapshots__/config_test.snap +++ b/internal/config/__snapshots__/config_test.snap @@ -1664,7 +1664,7 @@ } --- -[TestGetChecksForRule/two_prometheus_servers_/_disable_all_checks_via_comment - 1] +[TestGetChecksForRule/single_prometheus_server - 1] { "ci": { "baseBranch": "master", @@ -1697,26 +1697,13 @@ "rule/label", "rule/link", "rule/reject" - ], - "disabled": [ - "alerts/template", - "alerts/external_labels" ] }, "owners": {}, "prometheus": [ { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "1s", - "uptime": "up", - "concurrency": 16, - "rateLimit": 100, - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", + "name": "prom", + "uri": "http://localhost", "timeout": "1s", "uptime": "up", "concurrency": 16, @@ -1727,7 +1714,7 @@ } --- -[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 1] +[TestGetChecksForRule/multiple_URIs - 1] { "ci": { "baseBranch": "master", @@ -1760,28 +1747,19 @@ "rule/label", "rule/link", "rule/reject" - ], - "disabled": [ - "alerts/template", - "alerts/external_labels" ] }, "owners": {}, "prometheus": [ { - "name": "prom1", - "uri": "http://localhost/1", - "timeout": "1s", - "uptime": "up", - "concurrency": 16, - "rateLimit": 100, - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost/2", + "name": "prom", + "uri": "http://localhost", "timeout": "1s", "uptime": "up", + "failover": [ + "http://localhost/1", + "http://localhost/2" + ], "concurrency": 16, "rateLimit": 100, "required": false @@ -1790,7 +1768,7 @@ } --- -[TestGetChecksForRule/single_prometheus_server - 1] +[TestGetChecksForRule/single_prometheus_server_/_path_match - 1] { "ci": { "baseBranch": "master", @@ -1832,6 +1810,9 @@ "uri": "http://localhost", "timeout": "1s", "uptime": "up", + "include": [ + "rules.yml" + ], "concurrency": 16, "rateLimit": 100, "required": false @@ -1840,7 +1821,7 @@ } --- -[TestGetChecksForRule/multiple_URIs - 1] +[TestGetChecksForRule/multiple_prometheus_servers - 1] { "ci": { "baseBranch": "master", @@ -1882,9 +1863,20 @@ "uri": "http://localhost", "timeout": "1s", "uptime": "up", - "failover": [ - "http://localhost/1", - "http://localhost/2" + "include": [ + "rules.yml" + ], + "concurrency": 16, + "rateLimit": 100, + "required": false + }, + { + "name": "ignore", + "uri": "http://localhost", + "timeout": "1s", + "uptime": "up", + "include": [ + "foo.+" ], "concurrency": 16, "rateLimit": 100, @@ -1894,7 +1886,7 @@ } --- -[TestGetChecksForRule/single_prometheus_server_/_path_match - 1] +[TestGetChecksForRule/prometheus_check_with_prometheus_servers_and_disable_comment - 1] { "ci": { "baseBranch": "master", @@ -1932,7 +1924,19 @@ "owners": {}, "prometheus": [ { - "name": "prom", + "name": "prom1", + "uri": "http://localhost", + "timeout": "1s", + "uptime": "up", + "include": [ + "rules.yml" + ], + "concurrency": 16, + "rateLimit": 100, + "required": false + }, + { + "name": "prom2", "uri": "http://localhost", "timeout": "1s", "uptime": "up", @@ -1943,11 +1947,16 @@ "rateLimit": 100, "required": false } + ], + "rules": [ + { + "cost": {} + } ] } --- -[TestGetChecksForRule/multiple_prometheus_servers - 1] +[TestGetChecksForRule/checks_disabled_via_config - 1] { "ci": { "baseBranch": "master", @@ -1980,12 +1989,21 @@ "rule/label", "rule/link", "rule/reject" + ], + "disabled": [ + "promql/counter", + "promql/rate", + "promql/vector_matching", + "promql/range_query", + "rule/duplicate", + "labels/conflict", + "alerts/absent" ] }, "owners": {}, "prometheus": [ { - "name": "prom", + "name": "prom1", "uri": "http://localhost", "timeout": "1s", "uptime": "up", @@ -1995,24 +2013,56 @@ "concurrency": 16, "rateLimit": 100, "required": false - }, + } + ], + "rules": [ { - "name": "ignore", + "alerts": { + "range": "1h", + "step": "1m", + "resolve": "5m" + } + } + ] +} +--- + +[TestGetChecksForRule/single_check_enabled_via_config - 1] +{ + "ci": { + "baseBranch": "master", + "maxCommits": 20 + }, + "parser": {}, + "checks": {}, + "owners": {}, + "prometheus": [ + { + "name": "prom1", "uri": "http://localhost", "timeout": "1s", "uptime": "up", "include": [ - "foo.+" + "rules.yml" ], "concurrency": 16, "rateLimit": 100, "required": false } + ], + "rules": [ + { + "alerts": { + "range": "1h", + "step": "1m", + "resolve": "5m" + } + } ] } --- -[TestGetChecksForRule/tag_snoozes_all_prometheus_checks - 1] +[TestGetChecksForRule/two_prometheus_servers_/_expired_snooze - 1] { "ci": { "baseBranch": "master", @@ -2045,6 +2095,10 @@ "rule/label", "rule/link", "rule/reject" + ], + "disabled": [ + "alerts/template", + "promql/regexp" ] }, "owners": {}, @@ -2052,13 +2106,8 @@ { "name": "prom1", "uri": "http://localhost/1", - "timeout": "2m0s", + "timeout": "1s", "uptime": "up", - "tags": [ - "foo", - "disable", - "bar" - ], "concurrency": 16, "rateLimit": 100, "required": false @@ -2066,20 +2115,8 @@ { "name": "prom2", "uri": "http://localhost/2", - "timeout": "2m0s", - "uptime": "up", - "concurrency": 16, - "rateLimit": 100, - "required": false - }, - { - "name": "prom3", - "uri": "http://localhost/3", - "timeout": "2m0s", + "timeout": "1s", "uptime": "up", - "tags": [ - "foo" - ], "concurrency": 16, "rateLimit": 100, "required": false @@ -2088,7 +2125,7 @@ } --- -[TestGetChecksForRule/prometheus_check_with_prometheus_servers_and_disable_comment - 1] +[TestGetChecksForRule/tag_disables_all_prometheus_checks - 1] { "ci": { "baseBranch": "master", @@ -2127,11 +2164,13 @@ "prometheus": [ { "name": "prom1", - "uri": "http://localhost", - "timeout": "1s", + "uri": "http://localhost/1", + "timeout": "2m0s", "uptime": "up", - "include": [ - "rules.yml" + "tags": [ + "foo", + "disable", + "bar" ], "concurrency": 16, "rateLimit": 100, @@ -2139,26 +2178,30 @@ }, { "name": "prom2", - "uri": "http://localhost", - "timeout": "1s", + "uri": "http://localhost/2", + "timeout": "2m0s", "uptime": "up", - "include": [ - "rules.yml" - ], "concurrency": 16, "rateLimit": 100, "required": false - } - ], - "rules": [ + }, { - "cost": {} + "name": "prom3", + "uri": "http://localhost/3", + "timeout": "2m0s", + "uptime": "up", + "tags": [ + "foo" + ], + "concurrency": 16, + "rateLimit": 100, + "required": false } ] } --- -[TestGetChecksForRule/multiple_cost_checks - 1] +[TestGetChecksForRule/alerts/count_defaults - 1] { "ci": { "baseBranch": "master", @@ -2196,25 +2239,10 @@ "owners": {}, "prometheus": [ { - "name": "prom1", + "name": "prom", "uri": "http://localhost", "timeout": "1s", "uptime": "up", - "include": [ - "rules.yml" - ], - "concurrency": 16, - "rateLimit": 100, - "required": false - }, - { - "name": "prom2", - "uri": "http://localhost", - "timeout": "1s", - "uptime": "up", - "include": [ - "rules.yml" - ], "concurrency": 16, "rateLimit": 100, "required": false @@ -2222,28 +2250,17 @@ ], "rules": [ { - "cost": { - "comment": "this is rule comment", - "severity": "info" - } - }, - { - "cost": { - "severity": "warning", - "maxSeries": 10000 - } - }, - { - "cost": { - "severity": "bug", - "maxSeries": 20000 + "alerts": { + "range": "1d", + "step": "1m", + "resolve": "5m" } } ] } --- -[TestGetChecksForRule/checks_disabled_via_config - 1] +[TestGetChecksForRule/alerts/count_full - 1] { "ci": { "baseBranch": "master", @@ -2276,62 +2293,15 @@ "rule/label", "rule/link", "rule/reject" - ], - "disabled": [ - "promql/counter", - "promql/rate", - "promql/vector_matching", - "promql/range_query", - "rule/duplicate", - "labels/conflict", - "alerts/absent" ] }, "owners": {}, "prometheus": [ { - "name": "prom1", - "uri": "http://localhost", - "timeout": "1s", - "uptime": "up", - "include": [ - "rules.yml" - ], - "concurrency": 16, - "rateLimit": 100, - "required": false - } - ], - "rules": [ - { - "alerts": { - "range": "1h", - "step": "1m", - "resolve": "5m" - } - } - ] -} ---- - -[TestGetChecksForRule/single_check_enabled_via_config - 1] -{ - "ci": { - "baseBranch": "master", - "maxCommits": 20 - }, - "parser": {}, - "checks": {}, - "owners": {}, - "prometheus": [ - { - "name": "prom1", + "name": "prom", "uri": "http://localhost", "timeout": "1s", "uptime": "up", - "include": [ - "rules.yml" - ], "concurrency": 16, "rateLimit": 100, "required": false @@ -2340,16 +2310,19 @@ "rules": [ { "alerts": { - "range": "1h", + "range": "1d", "step": "1m", - "resolve": "5m" + "resolve": "5m", + "comment": "this is rule comment", + "severity": "bug", + "minCount": 100 } } ] } --- -[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 1] +[TestGetChecksForRule/two_prometheus_servers_/_disable_all_checks_via_comment - 1] { "ci": { "baseBranch": "master", @@ -2385,7 +2358,7 @@ ], "disabled": [ "alerts/template", - "promql/regexp" + "alerts/external_labels" ] }, "owners": {}, @@ -2412,7 +2385,7 @@ } --- -[TestGetChecksForRule/two_prometheus_servers_/_expired_snooze - 1] +[TestGetChecksForRule/multiple_cost_checks - 1] { "ci": { "baseBranch": "master", @@ -2445,37 +2418,59 @@ "rule/label", "rule/link", "rule/reject" - ], - "disabled": [ - "alerts/template", - "promql/regexp" ] }, "owners": {}, "prometheus": [ { "name": "prom1", - "uri": "http://localhost/1", + "uri": "http://localhost", "timeout": "1s", "uptime": "up", + "include": [ + "rules.yml" + ], "concurrency": 16, "rateLimit": 100, "required": false }, { "name": "prom2", - "uri": "http://localhost/2", + "uri": "http://localhost", "timeout": "1s", "uptime": "up", + "include": [ + "rules.yml" + ], "concurrency": 16, "rateLimit": 100, "required": false } + ], + "rules": [ + { + "cost": { + "comment": "this is rule comment", + "severity": "info" + } + }, + { + "cost": { + "severity": "warning", + "maxSeries": 10000 + } + }, + { + "cost": { + "severity": "bug", + "maxSeries": 20000 + } + } ] } --- -[TestGetChecksForRule/tag_disables_all_prometheus_checks - 1] +[TestGetChecksForRule/two_prometheus_servers_/_disable_checks_via_file/disable_comment - 1] { "ci": { "baseBranch": "master", @@ -2508,6 +2503,11 @@ "rule/label", "rule/link", "rule/reject" + ], + "disabled": [ + "alerts/template", + "alerts/external_labels", + "alerts/absent" ] }, "owners": {}, @@ -2515,13 +2515,8 @@ { "name": "prom1", "uri": "http://localhost/1", - "timeout": "2m0s", + "timeout": "1s", "uptime": "up", - "tags": [ - "foo", - "disable", - "bar" - ], "concurrency": 16, "rateLimit": 100, "required": false @@ -2529,20 +2524,8 @@ { "name": "prom2", "uri": "http://localhost/2", - "timeout": "2m0s", - "uptime": "up", - "concurrency": 16, - "rateLimit": 100, - "required": false - }, - { - "name": "prom3", - "uri": "http://localhost/3", - "timeout": "2m0s", + "timeout": "1s", "uptime": "up", - "tags": [ - "foo" - ], "concurrency": 16, "rateLimit": 100, "required": false @@ -2551,7 +2534,7 @@ } --- -[TestGetChecksForRule/alerts/count_defaults - 1] +[TestGetChecksForRule/two_prometheus_servers_/_snoozed_checks_via_comment - 1] { "ci": { "baseBranch": "master", @@ -2584,33 +2567,37 @@ "rule/label", "rule/link", "rule/reject" + ], + "disabled": [ + "alerts/template", + "promql/regexp" ] }, "owners": {}, "prometheus": [ { - "name": "prom", - "uri": "http://localhost", + "name": "prom1", + "uri": "http://localhost/1", "timeout": "1s", "uptime": "up", "concurrency": 16, "rateLimit": 100, "required": false - } - ], - "rules": [ + }, { - "alerts": { - "range": "1d", - "step": "1m", - "resolve": "5m" - } + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "1s", + "uptime": "up", + "concurrency": 16, + "rateLimit": 100, + "required": false } ] } --- -[TestGetChecksForRule/alerts/count_full - 1] +[TestGetChecksForRule/tag_snoozes_all_prometheus_checks - 1] { "ci": { "baseBranch": "master", @@ -2648,25 +2635,39 @@ "owners": {}, "prometheus": [ { - "name": "prom", - "uri": "http://localhost", - "timeout": "1s", + "name": "prom1", + "uri": "http://localhost/1", + "timeout": "2m0s", "uptime": "up", + "tags": [ + "foo", + "disable", + "bar" + ], "concurrency": 16, "rateLimit": 100, "required": false - } - ], - "rules": [ + }, { - "alerts": { - "range": "1d", - "step": "1m", - "resolve": "5m", - "comment": "this is rule comment", - "severity": "bug", - "minCount": 100 - } + "name": "prom2", + "uri": "http://localhost/2", + "timeout": "2m0s", + "uptime": "up", + "concurrency": 16, + "rateLimit": 100, + "required": false + }, + { + "name": "prom3", + "uri": "http://localhost/3", + "timeout": "2m0s", + "uptime": "up", + "tags": [ + "foo" + ], + "concurrency": 16, + "rateLimit": 100, + "required": false } ] } diff --git a/internal/config/config.go b/internal/config/config.go index eb389f53..45e800f0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -158,7 +158,7 @@ func (cfg *Config) GetChecksForRule(ctx context.Context, gen *PrometheusGenerato tags: p.Tags(), }) allChecks = append(allChecks, checkMeta{ - name: checks.CounterCheckName, + name: checks.AlertsAbsentCheckName, check: checks.NewAlertsAbsentCheck(p), tags: p.Tags(), }) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index bb120005..f5b488af 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -270,6 +270,7 @@ checks { # pint disable promql/range_query # pint disable rule/duplicate # pint disable labels/conflict +# pint disable alerts/absent - record: foo expr: sum(foo) `), @@ -734,6 +735,8 @@ rule { checks.AlertForCheckName, checks.ComparisonCheckName, checks.TemplateCheckName, + checks.AlertsAbsentCheckName + "(prom1)", + checks.AlertsAbsentCheckName + "(prom2)", checks.CostCheckName + "(prom1)", checks.CostCheckName + "(prom2)", checks.CostCheckName + "(prom1:10000)", @@ -1555,7 +1558,7 @@ prometheus "prom2" { timeout = "1s" } checks { - disabled = [ "alerts/template", "alerts/external_labels" ] + disabled = [ "alerts/template", "alerts/external_labels", "alerts/absent" ] } `, entry: discovery.Entry{ @@ -1612,7 +1615,7 @@ checks { # pint snooze 2099-11-28 rule/duplicate # pint snooze 2099-11-28T00:00:00+00:00 promql/vector_matching # pint snooze 2099-11-28 promql/counter -- record: foo +- record: foo # pint snooze 2099-11-28 alerts/absent expr: sum(foo) # pint file/disable promql/vector_matching `), @@ -1782,7 +1785,7 @@ prometheus "prom3" { # pint snooze 2099-11-28 promql/rate(+disable) # pint snooze 2099-11-28 promql/vector_matching(+disable) # pint snooze 2099-11-28 rule/duplicate(+disable) -# pint snooze 2099-11-28 alers/absent(+disable) +# pint snooze 2099-11-28 alerts/absent(+disable) - record: foo expr: sum(foo) `),