cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/alerts/annotation.md
140lines · modecode
| 1 | --- |
| 2 | layout: default |
| 3 | parent: Checks |
| 4 | grand_parent: Documentation |
| 5 | --- |
| 6 | |
| 7 | # alerts/annotation |
| 8 | |
| 9 | This check can be used to enforce annotations on alerting rules. |
| 10 | |
| 11 | ## Configuration |
| 12 | |
| 13 | Syntax: |
| 14 | |
| 15 | ```js |
| 16 | annotation "$pattern" { |
| 17 | severity = "bug|warning|info" |
| 18 | value = "(.*)" |
| 19 | required = true|false |
| 20 | } |
| 21 | ``` |
| 22 | |
| 23 | - `$pattern` - regexp pattern to match annotation name on, this can be templated |
| 24 | to reference checked rule fields, see [Configuration](../../configuration.md) |
| 25 | for details |
| 26 | - `severity` - set custom severity for reported issues, defaults to a warning |
| 27 | - `value` - optional value pattern to enforce, if not set only the |
| 28 | - `required` - if `true` pint will require every alert to have this annotation set, |
| 29 | if `false` it will only check values where annotation is set |
| 30 | |
| 31 | ## How to enable it |
| 32 | |
| 33 | This check is not enabled by default as it requires explicit configuration |
| 34 | to work. |
| 35 | To enable it add one or more `rule {...}` blocks and specify all required |
| 36 | annotations there. |
| 37 | |
| 38 | Example set of rules that will: |
| 39 | - require `summary` annotation to be present, if missing it will be reported as a warning |
| 40 | - if a `dashboard` annotation is provided it must match `https://grafana\.example\.com/.+` |
| 41 | pattern, if it doesn't match that pattern it will be reported as a bug |
| 42 | |
| 43 | ```js |
| 44 | rule { |
| 45 | match { |
| 46 | kind = "alerting" |
| 47 | } |
| 48 | |
| 49 | annotation "summary" { |
| 50 | required = true |
| 51 | } |
| 52 | |
| 53 | annotation "dashboard" { |
| 54 | severity = "bug" |
| 55 | value = "https://grafana\.example\.com/.+" |
| 56 | } |
| 57 | } |
| 58 | ``` |
| 59 | |
| 60 | Example that enforces all alerting rules with non-zero `for` field to have an |
| 61 | annotation called `alert_for` and value equal to `for` field. |
| 62 | |
| 63 | {% raw %} |
| 64 | ```js |
| 65 | rule { |
| 66 | match { |
| 67 | for = "> 0" |
| 68 | } |
| 69 | |
| 70 | annotation "alert_for" { |
| 71 | required = true |
| 72 | value = "{{ $for }}" |
| 73 | } |
| 74 | } |
| 75 | ``` |
| 76 | {% endraw %} |
| 77 | |
| 78 | ## How to disable it |
| 79 | |
| 80 | You can disable this check globally by adding this config block: |
| 81 | |
| 82 | ```js |
| 83 | checks { |
| 84 | disabled = ["alerts/annotations"] |
| 85 | } |
| 86 | ``` |
| 87 | |
| 88 | Or you can disable it per rule by adding a comment to it. |
| 89 | |
| 90 | `# pint disable alerts/annotation` |
| 91 | |
| 92 | If you want to disable only individual instances of this check |
| 93 | you can add a more specific comment. |
| 94 | |
| 95 | ### If `value` is NOT set |
| 96 | |
| 97 | ```yaml |
| 98 | groups: |
| 99 | - name: ... |
| 100 | rules: |
| 101 | # pint disable alerts/annotation($pattern:$required) |
| 102 | - record: ... |
| 103 | expr: ... |
| 104 | ``` |
| 105 | |
| 106 | Example rule: |
| 107 | |
| 108 | ```js |
| 109 | annotation "summary" { |
| 110 | required = true |
| 111 | } |
| 112 | ``` |
| 113 | |
| 114 | Example comment disabling that rule: |
| 115 | |
| 116 | `# pint disable alerts/annotation(summary:true)` |
| 117 | |
| 118 | ### If `value` is set |
| 119 | |
| 120 | ```yaml |
| 121 | groups: |
| 122 | - name: ... |
| 123 | rules: |
| 124 | # pint disable alerts/annotation($pattern:$value:$required) |
| 125 | - record: ... |
| 126 | expr: ... |
| 127 | ``` |
| 128 | |
| 129 | Example rule: |
| 130 | |
| 131 | ```js |
| 132 | annotation "dashboard" { |
| 133 | severity = "bug" |
| 134 | value = "https://grafana\.example\.com/.+" |
| 135 | } |
| 136 | ``` |
| 137 | |
| 138 | Example comment disabling that rule: |
| 139 | |
| 140 | `# pint disable alerts/annotation(dashboard:https://grafana\.example\.com/.+:true)` |
| 141 | |