forked from cloudflare/pint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cloudflare#451 from cloudflare/rule/duplicate
Add rule/duplicate check
- Loading branch information
Showing
43 changed files
with
804 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
pint.error --no-color -d 'promql/.*' -d alerts/count lint rules | ||
! stdout . | ||
cmp stderr stderr.txt | ||
|
||
-- stderr.txt -- | ||
level=info msg="Loading configuration file" path=.pint.hcl | ||
rules/0001.yml:1-2: duplicated rule, identical rule found at rules/0002.yml:1 (rule/duplicate) | ||
1 | - record: "colo:duplicate" | ||
2 | expr: sum(foo) without(job) | ||
|
||
rules/0001.yml:9-12: duplicated rule, identical rule found at rules/0002.yml:11 (rule/duplicate) | ||
9 | - record: "colo:labels:equal" | ||
10 | expr: sum(foo) without(job) | ||
11 | labels: | ||
12 | same: yes | ||
|
||
level=info msg="Problems found" Bug=2 | ||
level=fatal msg="Fatal error" error="problems found" | ||
-- rules/0001.yml -- | ||
- record: "colo:duplicate" | ||
expr: sum(foo) without(job) | ||
- record: "colo:labels:empty" | ||
expr: sum(foo) without(job) | ||
- record: "colo:labels:mismatch" | ||
expr: sum(foo) without(job) | ||
labels: | ||
file: a | ||
- record: "colo:labels:equal" | ||
expr: sum(foo) without(job) | ||
labels: | ||
same: yes | ||
|
||
-- rules/0002.yml -- | ||
- record: "colo:duplicate" | ||
expr: sum(foo) without(job) | ||
- record: "colo:labels:empty" | ||
expr: sum(foo) without(job) | ||
labels: | ||
empty: nope | ||
- record: "colo:labels:mismatch" | ||
expr: sum(foo) without(job) | ||
labels: | ||
file: b | ||
- record: "colo:labels:equal" | ||
expr: sum(foo) without(job) | ||
labels: | ||
same: yes | ||
|
||
# pint file/disable rule/duplicate | ||
|
||
-- .pint.hcl -- | ||
prometheus "prom" { | ||
uri = "http://127.0.0.1:7108" | ||
failover = [] | ||
timeout = "5s" | ||
required = true | ||
} | ||
parser { | ||
relaxed = [".*"] | ||
} |
56 changes: 56 additions & 0 deletions
56
cmd/pint/tests/0109_rule_duplicate_multiple_proms_include.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
pint.ok --no-color -d 'promql/.*' -d alerts/count lint rules | ||
! stdout . | ||
cmp stderr stderr.txt | ||
|
||
-- stderr.txt -- | ||
level=info msg="Loading configuration file" path=.pint.hcl | ||
-- rules/0001.yml -- | ||
- record: "colo:duplicate" | ||
expr: sum(foo) without(job) | ||
- record: "colo:labels:empty" | ||
expr: sum(foo) without(job) | ||
- record: "colo:labels:mismatch" | ||
expr: sum(foo) without(job) | ||
labels: | ||
file: a | ||
- record: "colo:labels:equal" | ||
expr: sum(foo) without(job) | ||
labels: | ||
same: yes | ||
|
||
-- rules/0002.yml -- | ||
- record: "colo:duplicate" | ||
expr: sum(foo) without(job) | ||
- record: "colo:labels:empty" | ||
expr: sum(foo) without(job) | ||
labels: | ||
empty: nope | ||
- record: "colo:labels:mismatch" | ||
expr: sum(foo) without(job) | ||
labels: | ||
file: b | ||
- record: "colo:labels:equal" | ||
expr: sum(foo) without(job) | ||
labels: | ||
same: yes | ||
|
||
# pint file/disable rule/duplicate | ||
|
||
-- .pint.hcl -- | ||
prometheus "prom1" { | ||
uri = "http://127.0.0.1:7109/1" | ||
failover = [] | ||
timeout = "5s" | ||
required = true | ||
include = ["rules/0001.yml"] | ||
} | ||
prometheus "prom2" { | ||
uri = "http://127.0.0.1:7109/2" | ||
failover = [] | ||
timeout = "5s" | ||
required = true | ||
include = ["rules/0002.yml"] | ||
} | ||
parser { | ||
relaxed = [".*"] | ||
} |
56 changes: 56 additions & 0 deletions
56
cmd/pint/tests/0110_rule_duplicate_multiple_proms_exclude.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
pint.ok --no-color -d 'promql/.*' -d alerts/count lint rules | ||
! stdout . | ||
cmp stderr stderr.txt | ||
|
||
-- stderr.txt -- | ||
level=info msg="Loading configuration file" path=.pint.hcl | ||
-- rules/0001.yml -- | ||
- record: "colo:duplicate" | ||
expr: sum(foo) without(job) | ||
- record: "colo:labels:empty" | ||
expr: sum(foo) without(job) | ||
- record: "colo:labels:mismatch" | ||
expr: sum(foo) without(job) | ||
labels: | ||
file: a | ||
- record: "colo:labels:equal" | ||
expr: sum(foo) without(job) | ||
labels: | ||
same: yes | ||
|
||
-- rules/0002.yml -- | ||
- record: "colo:duplicate" | ||
expr: sum(foo) without(job) | ||
- record: "colo:labels:empty" | ||
expr: sum(foo) without(job) | ||
labels: | ||
empty: nope | ||
- record: "colo:labels:mismatch" | ||
expr: sum(foo) without(job) | ||
labels: | ||
file: b | ||
- record: "colo:labels:equal" | ||
expr: sum(foo) without(job) | ||
labels: | ||
same: yes | ||
|
||
# pint file/disable rule/duplicate | ||
|
||
-- .pint.hcl -- | ||
prometheus "prom1" { | ||
uri = "http://127.0.0.1:7110/1" | ||
failover = [] | ||
timeout = "5s" | ||
required = true | ||
exclude = ["rules/0002.yml"] | ||
} | ||
prometheus "prom2" { | ||
uri = "http://127.0.0.1:7110/2" | ||
failover = [] | ||
timeout = "5s" | ||
required = true | ||
exclude = ["rules/0001.yml"] | ||
} | ||
parser { | ||
relaxed = [".*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
layout: default | ||
parent: Checks | ||
grand_parent: Documentation | ||
--- | ||
|
||
# rule/duplicate | ||
|
||
This check will find and report any duplicated recording rules. | ||
|
||
When Prometheus is configured with two identical recording rules that | ||
are producing the exact time series it will discard results from one | ||
of them. When that happens you will see warnings in logs, example: | ||
|
||
``` | ||
msg="Rule evaluation result discarded" err="duplicate sample for timestamp" | ||
``` | ||
|
||
Duplicated rule itself is not catastrophic but it will cause constant unnecessary | ||
logs that might hide other issues and can lead to other problems if the | ||
duplicated rule is later updated, but only in one place, not in both. | ||
|
||
## Configuration | ||
|
||
This check doesn't have any configuration options. | ||
|
||
## How to enable it | ||
|
||
This check is enabled by default for all configured Prometheus servers. | ||
|
||
Example: | ||
|
||
```js | ||
prometheus "prod" { | ||
uri = "https://prometheus-prod.example.com" | ||
timeout = "60s" | ||
include = [ | ||
"rules/prod/.*", | ||
"rules/common/.*", | ||
] | ||
} | ||
|
||
prometheus "dev" { | ||
uri = "https://prometheus-dev.example.com" | ||
timeout = "30s" | ||
include = [ | ||
"rules/dev/.*", | ||
"rules/common/.*", | ||
] | ||
} | ||
``` | ||
|
||
## How to disable it | ||
|
||
You can disable this check globally by adding this config block: | ||
|
||
```js | ||
checks { | ||
disabled = ["rule/duplicate"] | ||
} | ||
``` | ||
|
||
You can also disable it for all rules inside given file by adding | ||
a comment anywhere in that file. Example: | ||
|
||
`# pint file/disable rule/duplicate` | ||
|
||
Or you can disable it per rule by adding a comment to it. Example: | ||
|
||
`# pint disable rule/duplicate` | ||
|
||
If you want to disable only individual instances of this check | ||
you can add a more specific comment. | ||
|
||
`# pint disable rule/duplicate($prometheus)` | ||
|
||
Where `$prometheus` is the name of Prometheus server to disable. | ||
|
||
Example: | ||
|
||
`# pint disable rule/duplicate(prod)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.