cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/rule/reject.md
120lines · modecode
| 1 | --- |
| 2 | layout: default |
| 3 | parent: Checks |
| 4 | grand_parent: Documentation |
| 5 | --- |
| 6 | |
| 7 | # rule/reject |
| 8 | |
| 9 | This check allows rejecting label or annotations keys and values using regexp |
| 10 | rules. |
| 11 | |
| 12 | ## Configuration |
| 13 | |
| 14 | Syntax: |
| 15 | |
| 16 | ```js |
| 17 | reject "$pattern" { |
| 18 | severity = "bug|warning|info" |
| 19 | label_keys = true|false |
| 20 | label_values = true|false |
| 21 | annotation_keys = true|false |
| 22 | annotation_values = true|false |
| 23 | } |
| 24 | ``` |
| 25 | |
| 26 | - `$pattern` - regexp pattern to reject, 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 bug. |
| 30 | - `label_keys` - if true label keys for recording and alerting rules will |
| 31 | be checked. |
| 32 | - `label_values` - if true label values for recording and alerting rules will |
| 33 | be checked. |
| 34 | - `annotation_keys` - if true annotation keys for alerting rules will be checked. |
| 35 | - `annotation_values` - if true label values for alerting rules will be checked. |
| 36 | |
| 37 | ## How to enable it |
| 38 | |
| 39 | This check is not enabled by default as it requires explicit configuration |
| 40 | to work. |
| 41 | To enable it add one or more `rule {...}` blocks and specify all rejected patterns |
| 42 | there. |
| 43 | |
| 44 | Examples: |
| 45 | |
| 46 | Disallow using URLs as label keys or values: |
| 47 | |
| 48 | ```js |
| 49 | rule { |
| 50 | match { |
| 51 | kind = "alerting" |
| 52 | } |
| 53 | |
| 54 | reject "https?://.+" { |
| 55 | label_keys = true |
| 56 | label_values = true |
| 57 | } |
| 58 | } |
| 59 | ``` |
| 60 | |
| 61 | Disallow spaces in label and annotation keys: |
| 62 | |
| 63 | ```js |
| 64 | rule { |
| 65 | reject ".* +.*" { |
| 66 | annotation_keys = true |
| 67 | label_keys = true |
| 68 | } |
| 69 | } |
| 70 | ``` |
| 71 | |
| 72 | Disallow label and annotation values equal to alert name: |
| 73 | |
| 74 | {% raw %} |
| 75 | ```js |
| 76 | rule { |
| 77 | match { |
| 78 | kind = "alerting" |
| 79 | } |
| 80 | |
| 81 | reject "{{ $alert }}" { |
| 82 | annotation_values = true |
| 83 | label_values = true |
| 84 | } |
| 85 | } |
| 86 | ``` |
| 87 | {% endraw %} |
| 88 | |
| 89 | ## How to disable it |
| 90 | |
| 91 | You can disable this check globally by adding this config block: |
| 92 | |
| 93 | ```js |
| 94 | checks { |
| 95 | disabled = ["rule/reject"] |
| 96 | } |
| 97 | ``` |
| 98 | |
| 99 | Or you can disable it per rule by adding a comment to it. |
| 100 | |
| 101 | `# pint disable rule/reject` |
| 102 | |
| 103 | If you want to disable only individual instances of this check |
| 104 | you can add a more specific comment. |
| 105 | |
| 106 | ### If `label_keys` or `annotation_keys` is set |
| 107 | |
| 108 | `# pint disable rule/reject(key=~'$pattern`)` |
| 109 | |
| 110 | Example: |
| 111 | |
| 112 | `# pint disable rule/reject(key=~'^https?://.+$')` |
| 113 | |
| 114 | ### If `label_values` or `annotation_values` is set |
| 115 | |
| 116 | `# pint disable promql/reject(val=~'$pattern')` |
| 117 | |
| 118 | Example: |
| 119 | |
| 120 | `# pint disable rule/reject(val=~'^https?://.+$')` |
| 121 | |