cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.53.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

docs/checks/rule/label.md

184lines · modecode

1---
2layout: default
3parent: Checks
4grand_parent: Documentation
5---
6
7# rule/label
8
9This check works the same way as [alerts/annotation](../alerts/annotation.md) check,
10but it operates on labels instead.
11It uses static labels set on alerting or recording rule. It doesn't use
12labels on time series used in those rules.
13
14## Configuration
15
16Syntax:
17
18```js
19label "$pattern" {
20 severity = "bug|warning|info"
21 token = "(.*)"
22 value = "(.*)"
23 values = ["...", ...]
24 required = true|false
25}
26```
27
28- `$pattern` - regexp pattern to match label name on, this can be templated
29 to reference checked rule fields, see [Configuration](../../configuration.md)
30 for details.
31- `severity` - set custom severity for reported issues, defaults to a warning.
32- `token` - optional regexp to tokenize label value before validating it.
33 By default the whole label value is validated against `value` regexp or
34 the `values` list. If you want to break the value into sub-strings and
35 validate each of them independently you can do this by setting `token`
36 to a regexp that captures a single sub-string.
37- `value` - optional value regexp to enforce, if not set only pint will only
38 check if the label exists.
39- `values` - optional list of allowed values - this is alternative to using
40 `value` regexp. Set this to the list of all possible valid label values.
41- `required` - if `true` pint will require every rule to have this label set,
42 if `false` it will only check values where label is set.
43
44## How to enable it
45
46This check is not enabled by default as it requires explicit configuration
47to work.
48To enable it add one or more `rule {...}` blocks and specify all required
49labels there.
50
51Example that will require `severity` label to be set on alert rules with two
52all possible values:
53
54```js
55rule {
56 match {
57 kind = "alerting"
58 }
59
60 label "severity" {
61 value = "(warning|critical)"
62 required = true
63 }
64}
65```
66
67Example that enforces all alerting rules with `for` value present and greater
68than 5 minutes field to have a label called `alert_for` and value equal to
69`for` field.
70
71{% raw %}
72
73```js
74rule {
75 match {
76 for = "> 5m"
77 }
78
79 label "alert_for" {
80 required = true
81 value = "{{ $for }}"
82 }
83}
84```
85
86{% endraw %}
87
88If you have a label that can contain multiple different values as a single string,
89for example `components: "db api memcached"`, and you want to ensure only valid values
90are included then use `token` and `values`.
91By setting `token` to a regexp that matches only a sequence of letters (`[a-zA-Z]+`)
92you tell pint to split `"db api memcached"` into `["db", "api", "memcached"]`.
93Then it iterates this list and checks each element independently.
94This allows you to have validation for multi-value strings.
95
96{% raw %}
97
98```js
99rule {
100 label "components" {
101 required = true
102 token = "[a-zA-Z]+"
103 values = [
104 "prometheus",
105 "db",
106 "memcached",
107 "api",
108 "storage",
109 ]
110 }
111}
112```
113
114{% endraw %}
115
116## How to disable it
117
118You can disable this check globally by adding this config block:
119
120```js
121checks {
122 disabled = ["rule/label"]
123}
124```
125
126You can also disable it for all rules inside given file by adding
127a comment anywhere in that file. Example:
128
129```yaml
130# pint file/disable rule/label
131```
132
133Or you can disable it per rule by adding a comment to it. Example:
134
135```yaml
136# pint disable rule/label
137```
138
139If you want to disable only individual instances of this check
140you can add a more specific comment.
141
142```yaml
143# pint disable rule/label($label:$required)
144```
145
146Where `$label` is the label name and `$required` is the configure value
147of `required` option.
148
149```yaml
150groups:
151 - name: ...
152 rules:
153 # pint disable rule/label($pattern:$required)
154 - record: ...
155 expr: ...
156```
157
158Example rule:
159
160```js
161label "severity" {
162 value = "(warning|critical)"
163 required = true
164}
165```
166
167Example comment disabling that rule:
168
169```yaml
170# pint disable rule/label(severity:true)
171```
172
173## How to snooze it
174
175You can disable this check until given time by adding a comment to it. Example:
176
177```yaml
178# pint snooze $TIMESTAMP rule/label
179```
180
181Where `$TIMESTAMP` is either use [RFC3339](https://www.rfc-editor.org/rfc/rfc3339)
182formatted or `YYYY-MM-DD`.
183Adding this comment will disable `rule/label` *until* `$TIMESTAMP`, after that
184check will be re-enabled.