cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/rule/label.md
118lines · 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 | value = "..." |
| 22 | required = true|false |
| 23 | } |
| 24 | ``` |
| 25 | |
| 26 | - `$pattern` - regexp pattern to match label name on, this can be templated |
| 27 | to reference checked rule fields, see [Configuration](../../configuration.md) |
| 28 | for details |
| 29 | - `severity` - set custom severity for reported issues, defaults to a warning |
| 30 | - `value` - optional value pattern to enforce, if not set only the |
| 31 | - `required` - if `true` pint will require every rule to have this label set, |
| 32 | if `false` it will only check values where label is set |
| 33 | |
| 34 | ## How to enable it |
| 35 | |
| 36 | This check is not enabled by default as it requires explicit configuration |
| 37 | to work. |
| 38 | To enable it add one or more `rule {...}` blocks and specify all required |
| 39 | labels there. |
| 40 | |
| 41 | Example that will require `severity` label to be set on alert rules with two |
| 42 | all possible values: |
| 43 | |
| 44 | ```js |
| 45 | rule { |
| 46 | match { |
| 47 | kind = "alerting" |
| 48 | } |
| 49 | |
| 50 | label "severity" { |
| 51 | value = "(warning|critical)" |
| 52 | required = true |
| 53 | } |
| 54 | } |
| 55 | ``` |
| 56 | |
| 57 | Example that enforces all alerting rules with `for` value present and greater |
| 58 | than 5 minutes field to have a label called `alert_for` and value equal to |
| 59 | `for` field. |
| 60 | |
| 61 | {% raw %} |
| 62 | ```js |
| 63 | rule { |
| 64 | match { |
| 65 | for = "> 5m" |
| 66 | } |
| 67 | |
| 68 | label "alert_for" { |
| 69 | required = true |
| 70 | value = "{{ $for }}" |
| 71 | } |
| 72 | } |
| 73 | ``` |
| 74 | {% endraw %} |
| 75 | |
| 76 | ## How to disable it |
| 77 | |
| 78 | You can disable this check globally by adding this config block: |
| 79 | |
| 80 | ```js |
| 81 | checks { |
| 82 | disabled = ["rule/label"] |
| 83 | } |
| 84 | ``` |
| 85 | |
| 86 | Or you can disable it per rule by adding a comment to it: |
| 87 | |
| 88 | `# pint disable rule/label` |
| 89 | |
| 90 | If you want to disable only individual instances of this check |
| 91 | you can add a more specific comment. |
| 92 | |
| 93 | `# pint disable rule/label($label:$required)` |
| 94 | |
| 95 | Where `$label` is the label name and `$required` is the configure value |
| 96 | of `required` option. |
| 97 | |
| 98 | ```yaml |
| 99 | groups: |
| 100 | - name: ... |
| 101 | rules: |
| 102 | # pint disable rule/label($pattern:$required) |
| 103 | - record: ... |
| 104 | expr: ... |
| 105 | ``` |
| 106 | |
| 107 | Example rule: |
| 108 | |
| 109 | ```js |
| 110 | label "severity" { |
| 111 | value = "(warning|critical)" |
| 112 | required = true |
| 113 | } |
| 114 | ``` |
| 115 | |
| 116 | Example comment disabling that rule: |
| 117 | |
| 118 | `# pint disable rule/label(severity:true)` |
| 119 | |