cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/rule/label.md
184lines · modecode
| 1 | --- |
| 2 | layout: default |
| 3 | parent: Checks |
| 4 | grand_parent: Documentation |
| 5 | --- |
| 6 | |
| 7 | # rule/label |
| 8 | |
| 9 | This check works the same way as [alerts/annotation](../alerts/annotation.md) check, |
| 10 | but it operates on labels instead. |
| 11 | It uses static labels set on alerting or recording rule. It doesn't use |
| 12 | labels on time series used in those rules. |
| 13 | |
| 14 | ## Configuration |
| 15 | |
| 16 | Syntax: |
| 17 | |
| 18 | ```js |
| 19 | label "$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 | |
| 46 | This check is not enabled by default as it requires explicit configuration |
| 47 | to work. |
| 48 | To enable it add one or more `rule {...}` blocks and specify all required |
| 49 | labels there. |
| 50 | |
| 51 | Example that will require `severity` label to be set on alert rules with two |
| 52 | all possible values: |
| 53 | |
| 54 | ```js |
| 55 | rule { |
| 56 | match { |
| 57 | kind = "alerting" |
| 58 | } |
| 59 | |
| 60 | label "severity" { |
| 61 | value = "(warning|critical)" |
| 62 | required = true |
| 63 | } |
| 64 | } |
| 65 | ``` |
| 66 | |
| 67 | Example that enforces all alerting rules with `for` value present and greater |
| 68 | than 5 minutes field to have a label called `alert_for` and value equal to |
| 69 | `for` field. |
| 70 | |
| 71 | {% raw %} |
| 72 | |
| 73 | ```js |
| 74 | rule { |
| 75 | match { |
| 76 | for = "> 5m" |
| 77 | } |
| 78 | |
| 79 | label "alert_for" { |
| 80 | required = true |
| 81 | value = "{{ $for }}" |
| 82 | } |
| 83 | } |
| 84 | ``` |
| 85 | |
| 86 | {% endraw %} |
| 87 | |
| 88 | If you have a label that can contain multiple different values as a single string, |
| 89 | for example `components: "db api memcached"`, and you want to ensure only valid values |
| 90 | are included then use `token` and `values`. |
| 91 | By setting `token` to a regexp that matches only a sequence of letters (`[a-zA-Z]+`) |
| 92 | you tell pint to split `"db api memcached"` into `["db", "api", "memcached"]`. |
| 93 | Then it iterates this list and checks each element independently. |
| 94 | This allows you to have validation for multi-value strings. |
| 95 | |
| 96 | {% raw %} |
| 97 | |
| 98 | ```js |
| 99 | rule { |
| 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 | |
| 118 | You can disable this check globally by adding this config block: |
| 119 | |
| 120 | ```js |
| 121 | checks { |
| 122 | disabled = ["rule/label"] |
| 123 | } |
| 124 | ``` |
| 125 | |
| 126 | You can also disable it for all rules inside given file by adding |
| 127 | a comment anywhere in that file. Example: |
| 128 | |
| 129 | ```yaml |
| 130 | # pint file/disable rule/label |
| 131 | ``` |
| 132 | |
| 133 | Or you can disable it per rule by adding a comment to it. Example: |
| 134 | |
| 135 | ```yaml |
| 136 | # pint disable rule/label |
| 137 | ``` |
| 138 | |
| 139 | If you want to disable only individual instances of this check |
| 140 | you can add a more specific comment. |
| 141 | |
| 142 | ```yaml |
| 143 | # pint disable rule/label($label:$required) |
| 144 | ``` |
| 145 | |
| 146 | Where `$label` is the label name and `$required` is the configure value |
| 147 | of `required` option. |
| 148 | |
| 149 | ```yaml |
| 150 | groups: |
| 151 | - name: ... |
| 152 | rules: |
| 153 | # pint disable rule/label($pattern:$required) |
| 154 | - record: ... |
| 155 | expr: ... |
| 156 | ``` |
| 157 | |
| 158 | Example rule: |
| 159 | |
| 160 | ```js |
| 161 | label "severity" { |
| 162 | value = "(warning|critical)" |
| 163 | required = true |
| 164 | } |
| 165 | ``` |
| 166 | |
| 167 | Example comment disabling that rule: |
| 168 | |
| 169 | ```yaml |
| 170 | # pint disable rule/label(severity:true) |
| 171 | ``` |
| 172 | |
| 173 | ## How to snooze it |
| 174 | |
| 175 | You 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 | |
| 181 | Where `$TIMESTAMP` is either use [RFC3339](https://www.rfc-editor.org/rfc/rfc3339) |
| 182 | formatted or `YYYY-MM-DD`. |
| 183 | Adding this comment will disable `rule/label` *until* `$TIMESTAMP`, after that |
| 184 | check will be re-enabled. |