cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.81.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/checks/promql/selector.md

181lines · modecode

1---
2layout: default
3parent: Checks
4grand_parent: Documentation
5---
6
7# promql/selector
8
9This check is used to enforce rules on how vector selectors must be structured.
10
11## Configuration
12
13Syntax:
14
15```js
16selector "$pattern" {
17 comment = "..."
18 severity = "bug|warning|info"
19 requiredLabels = [ "...", ... ]
20}
21```
22
23- `$pattern` - regexp pattern to match time series name used in the vector selector,
24 this can be templated to reference checked rule fields, see [Configuration](../../configuration.md)
25 for details.
26- `comment` - set a custom comment that will be added to reported problems.
27- `severity` - set custom severity for reported issues, defaults to a warning.
28- `requiredLabels` - list of label names that must be present on all matching vector selectors.
29
30The `selector` block can be optionally wrapped inside a `call` block to restrict this check
31only to selectors used inside specific function, syntax:
32
33```js
34call "$pattern" {
35 selector { ... }
36}
37```
38
39- `$pattern` - regexp pattern to match the name of the function,
40 this can be templated to reference checked rule fields, see [Configuration](../../configuration.md)
41 for details.
42
43## How to enable it
44
45This check is not enabled by default as it requires explicit configuration to work.
46To enable it add one or more `rule {...}` blocks and specify all required rules there.
47
48Examples:
49
50Ensure that all alerting rules are scoped to specific scrape job we can enforce that they
51all have a `job` label filter:
52
53```js
54rule {
55 match {
56 kind = "alerting"
57 }
58 selector ".+" {
59 requiredLabels = ["job"]
60 comment = "All alerts must be scoped to a specific scrape job via the `job` label."
61 }
62}
63```
64
65The above rule would flag this rule:
66
67```yaml
68- alert: TargetDown
69 expr: up == 0
70```
71
72but this one would pass:
73
74```yaml
75- alert: TargetDown
76 expr: up{job="myjob"}
77```
78
79We can also restrict this check only to some metrics, for example only to the `up` metric, by
80changing the regexp pattern in the `selector` block from `.+` to `up`:
81
82```js
83rule {
84 selector "up" { ... }
85}
86```
87
88The `selector` block can be nested under the `call` block if we want to apply it only to selectors
89used inside some specific function. To ensure that all alerts using `absent()` and `absent_over_time()`
90call have the `job` label:
91
92```js
93rule {
94 match {
95 kind = "alerting"
96 }
97 call "absent|absent_over_time" {
98 selector ".+" {
99 requiredLabels = ["job"]
100 comment = "All alerts using absent() must be specify the `job` label."
101 }
102 }
103}
104```
105
106## How to disable it
107
108You can disable this check globally by adding this config block:
109
110```js
111checks {
112 disabled = ["promql/selector"]
113}
114```
115
116You can also disable it for all rules inside given file by adding
117a comment anywhere in that file. Example:
118
119```yaml
120# pint file/disable promql/selector
121```
122
123Or you can disable it per rule by adding a comment to it. Example:
124
125```yaml
126# pint disable promql/selector
127```
128
129If you want to disable only individual instances of this check
130you can add a more specific comment.
131
132### If you only have the `selector` config block
133
134```yaml
135# pint disable promql/selector($pattern:$label)
136```
137
138Example:
139
140```js
141selector "up" {
142 requiredLabels = ["job"]
143}
144```
145
146```yaml
147# pint disable promql/selector(^up$:job)
148```
149
150### If you have the `call` config block
151
152```yaml
153# pint disable promql/selector($callPattern:$selectorPattern:$label)
154```
155
156Example:
157
158```js
159call "absent" {
160 selector "up" {
161 requiredLabels = ["job"]
162 }
163}
164```
165
166```yaml
167# pint disable promql/selector(^absent$:^up$:job)
168```
169
170## How to snooze it
171
172You can disable this check until given time by adding a comment to it. Example:
173
174```yaml
175# pint snooze $TIMESTAMP promql/selector
176```
177
178Where `$TIMESTAMP` is either use [RFC3339](https://www.rfc-editor.org/rfc/rfc3339)
179formatted or `YYYY-MM-DD`.
180Adding this comment will disable `promql/selector` *until* `$TIMESTAMP`, after that
181check will be re-enabled.