cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/rule/label.md
189lines · 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 | 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 | |
| 48 | This check is not enabled by default as it requires explicit configuration |
| 49 | to work. |
| 50 | To enable it add one or more `rule {...}` blocks and specify all required |
| 51 | labels there. |
| 52 | |
| 53 | Example that will require `severity` label to be set on alert rules with two |
| 54 | all possible values: |
| 55 | |
| 56 | ```js |
| 57 | rule { |
| 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 | |
| 70 | Example that enforces all alerting rules with `for` value present and greater |
| 71 | than 5 minutes field to have a label called `alert_for` and value equal to |
| 72 | `for` field. |
| 73 | |
| 74 | {% raw %} |
| 75 | |
| 76 | ```js |
| 77 | rule { |
| 78 | match { |
| 79 | for = "> 5m" |
| 80 | } |
| 81 | |
| 82 | label "alert_for" { |
| 83 | required = true |
| 84 | value = "{{ $for }}" |
| 85 | } |
| 86 | } |
| 87 | ``` |
| 88 | |
| 89 | {% endraw %} |
| 90 | |
| 91 | If you have a label that can contain multiple different values as a single string, |
| 92 | for example `components: "db api memcached"`, and you want to ensure only valid values |
| 93 | are included then use `token` and `values`. |
| 94 | By setting `token` to a regexp that matches only a sequence of letters (`[a-zA-Z]+`) |
| 95 | you tell pint to split `"db api memcached"` into `["db", "api", "memcached"]`. |
| 96 | Then it iterates this list and checks each element independently. |
| 97 | This allows you to have validation for multi-value strings. |
| 98 | |
| 99 | {% raw %} |
| 100 | |
| 101 | ```js |
| 102 | rule { |
| 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 | |
| 121 | You can disable this check globally by adding this config block: |
| 122 | |
| 123 | ```js |
| 124 | checks { |
| 125 | disabled = ["rule/label"] |
| 126 | } |
| 127 | ``` |
| 128 | |
| 129 | You can also disable it for all rules inside given file by adding |
| 130 | a comment anywhere in that file. Example: |
| 131 | |
| 132 | ```yaml |
| 133 | # pint file/disable rule/label |
| 134 | ``` |
| 135 | |
| 136 | Or you can disable it per rule by adding a comment to it. Example: |
| 137 | |
| 138 | ```yaml |
| 139 | # pint disable rule/label |
| 140 | ``` |
| 141 | |
| 142 | If you want to disable only individual instances of this check |
| 143 | you can add a more specific comment. |
| 144 | |
| 145 | If `value` is set: |
| 146 | |
| 147 | ```yaml |
| 148 | # pint disable rule/label($label:$required:$value) |
| 149 | ``` |
| 150 | |
| 151 | If `value` is NOT set: |
| 152 | |
| 153 | ```yaml |
| 154 | # pint disable rule/label($label:$required) |
| 155 | ``` |
| 156 | |
| 157 | Where: |
| 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 | |
| 163 | Example pint rule: |
| 164 | |
| 165 | ```js |
| 166 | label "severity" { |
| 167 | value = "(warning|critical)" |
| 168 | required = true |
| 169 | } |
| 170 | ``` |
| 171 | |
| 172 | Example comment disabling that rule: |
| 173 | |
| 174 | ```yaml |
| 175 | # pint disable rule/label(severity:true:^(warning|critical)$) |
| 176 | ``` |
| 177 | |
| 178 | ## How to snooze it |
| 179 | |
| 180 | You 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 | |
| 186 | Where `$TIMESTAMP` is either use [RFC3339](https://www.rfc-editor.org/rfc/rfc3339) |
| 187 | formatted or `YYYY-MM-DD`. |
| 188 | Adding this comment will disable `rule/label` _until_ `$TIMESTAMP`, after that |
| 189 | check will be re-enabled. |
| 190 | |