-
Notifications
You must be signed in to change notification settings - Fork 53
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 #801 from cloudflare/deps
Add rule/dependency check
- Loading branch information
Showing
44 changed files
with
1,116 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
mkdir testrepo | ||
cd testrepo | ||
exec git init --initial-branch=main . | ||
|
||
cp ../src/v1.yml rules.yml | ||
cp ../src/.pint.hcl . | ||
env GIT_AUTHOR_NAME=pint | ||
env GIT_AUTHOR_EMAIL=pint@example.com | ||
env GIT_COMMITTER_NAME=pint | ||
env GIT_COMMITTER_EMAIL=pint@example.com | ||
exec git add . | ||
exec git commit -am 'import rules and config' | ||
|
||
exec git checkout -b v2 | ||
cp ../src/v2.yml rules.yml | ||
exec git commit -am 'v2' | ||
|
||
pint.ok -l error --offline --no-color ci | ||
! stdout . | ||
cmp stderr ../stderr.txt | ||
|
||
-- stderr.txt -- | ||
rules.yml:5 Warning: This rule uses a metric produced by recording rule `up:sum` which was removed from rules.yml. (rule/dependency) | ||
5 | expr: 'up:sum == 0' | ||
|
||
-- src/v1.yml -- | ||
groups: | ||
- name: g1 | ||
rules: | ||
- alert: Alert | ||
expr: 'up:sum == 0' | ||
annotations: | ||
summary: 'Service is down' | ||
labels: | ||
cluster: dev | ||
- record: up:sum | ||
expr: sum(up) | ||
-- src/v2.yml -- | ||
groups: | ||
- name: g1 | ||
rules: | ||
- alert: Alert | ||
expr: 'up:sum == 0' | ||
annotations: | ||
summary: 'Service is down' | ||
labels: | ||
cluster: dev | ||
-- src/.pint.hcl -- | ||
ci { | ||
baseBranch = "main" | ||
} | ||
prometheus "prom" { | ||
uri = "http://127.0.0.1:7162" | ||
timeout = "5s" | ||
required = true | ||
} |
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,124 @@ | ||
--- | ||
layout: default | ||
parent: Checks | ||
grand_parent: Documentation | ||
--- | ||
|
||
# rule/dependency | ||
|
||
This check only works when running `pint ci` and will validate that any | ||
removed recording rule isn't still being used by other rules. | ||
|
||
Removing any recording rule that is a dependency of other rules is likely | ||
to make them stop working, unless there's some other source of the metric | ||
that was produced by the removed rule. | ||
|
||
Example: consider this two rules, one generates `down:count` metric | ||
that is then used by the alert rule: | ||
|
||
```yaml | ||
groups: | ||
- name: ... | ||
rules: | ||
- record: down:count | ||
expr: count(up == 0) by(job) | ||
- alert: Job is down | ||
expr: down:count > 0 | ||
``` | ||
If we were to edit this file and delete the recording rule: | ||
```yaml | ||
groups: | ||
- name: ... | ||
rules: | ||
- alert: Job is down | ||
expr: down:count > 0 | ||
``` | ||
This would leave our alert rule broken because Prometheus would | ||
no longer have `down:count` metric. | ||
|
||
This check tries to detect scenarios like this but works across all | ||
files. | ||
|
||
## 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/dependency"] | ||
} | ||
``` | ||
|
||
You can also disable it for all rules inside given file by adding | ||
a comment anywhere in that file. Example: | ||
|
||
```yaml | ||
# pint file/disable rule/dependency | ||
``` | ||
|
||
Or you can disable it per rule by adding a comment to it. Example: | ||
|
||
```yaml | ||
# pint disable rule/dependency | ||
``` | ||
|
||
If you want to disable only individual instances of this check | ||
you can add a more specific comment. | ||
|
||
```yaml | ||
# pint disable rule/dependency($prometheus) | ||
``` | ||
|
||
Where `$prometheus` is the name of Prometheus server to disable. | ||
|
||
Example: | ||
|
||
```yaml | ||
# pint disable rule/dependency(prod) | ||
``` | ||
|
||
## How to snooze it | ||
|
||
You can disable this check until given time by adding a comment to it. Example: | ||
|
||
```yaml | ||
# pint snooze $TIMESTAMP rule/dependency | ||
``` | ||
|
||
Where `$TIMESTAMP` is either use [RFC3339](https://www.rfc-editor.org/rfc/rfc3339) | ||
formatted or `YYYY-MM-DD`. | ||
Adding this comment will disable `rule/dependency` *until* `$TIMESTAMP`, after that | ||
check will be re-enabled. |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/cloudflare/pint | ||
|
||
go 1.21.3 | ||
go 1.21.4 | ||
|
||
require ( | ||
github.com/cespare/xxhash/v2 v2.2.0 | ||
|
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
Oops, something went wrong.