cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.71.5

Branches

Tags

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

Clone

HTTPS

Download ZIP

docs/checks/rule/label.md

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