cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/promql/aggregate.md
140lines · modecode
| 1 | --- |
| 2 | layout: default |
| 3 | parent: Checks |
| 4 | grand_parent: Documentation |
| 5 | --- |
| 6 | |
| 7 | # promql/aggregate |
| 8 | |
| 9 | This check is used to inspect promql expressions and ensure that specific labels |
| 10 | are kept or stripped away when aggregating results. It's mostly useful in recording |
| 11 | rules. |
| 12 | |
| 13 | ## Configuration |
| 14 | |
| 15 | Syntax: |
| 16 | |
| 17 | ```js |
| 18 | aggregate "$pattern" { |
| 19 | severity = "bug|warning|info" |
| 20 | keep = [ "...", ... ] |
| 21 | strip = [ "...", ... ] |
| 22 | } |
| 23 | ``` |
| 24 | |
| 25 | - `$pattern` - regexp pattern to match rule name on, this can be templated |
| 26 | to reference checked rule fields, see [Configuration](../../configuration.md) |
| 27 | for details |
| 28 | - `severity` - set custom severity for reported issues, defaults to a warning |
| 29 | - `keep` - list of label names that must be preserved |
| 30 | - `strip` - list of label names that must be stripped |
| 31 | |
| 32 | ## How to enable it |
| 33 | |
| 34 | This check is not enabled by default as it requires explicit configuration |
| 35 | to work. |
| 36 | To enable it add one or more `rule {...}` blocks and specify all required |
| 37 | rules there. |
| 38 | |
| 39 | Examples: |
| 40 | |
| 41 | Ensure that all series generated from recording rules have `job` labels preserved: |
| 42 | |
| 43 | ```js |
| 44 | rule { |
| 45 | match { |
| 46 | kind = "recording" |
| 47 | } |
| 48 | aggregate ".+" { |
| 49 | keep = ["job"] |
| 50 | } |
| 51 | } |
| 52 | ``` |
| 53 | |
| 54 | In some cases you might want to ensure that specific labels are removed in aggregations. |
| 55 | For example in recording rules that are producing series consumed by federation, where |
| 56 | only aggregated results (not per instance) are allowed: |
| 57 | |
| 58 | ```js |
| 59 | rule { |
| 60 | match { |
| 61 | kind = "recording" |
| 62 | } |
| 63 | aggregate "cluster:.+" { |
| 64 | strip = ["instance"] |
| 65 | } |
| 66 | } |
| 67 | ``` |
| 68 | |
| 69 | By default all issues found by this check will be reported as warnings. To adjust |
| 70 | severity set a custom `severity` key: |
| 71 | |
| 72 | ```js |
| 73 | aggregate ".+" { |
| 74 | ... |
| 75 | severity = "bug" |
| 76 | } |
| 77 | ``` |
| 78 | |
| 79 | ## How to disable it |
| 80 | |
| 81 | You can disable this check globally by adding this config block: |
| 82 | |
| 83 | ```js |
| 84 | checks { |
| 85 | disabled = ["promql/aggregate"] |
| 86 | } |
| 87 | ``` |
| 88 | |
| 89 | You can also disable it for all rules inside given file by adding |
| 90 | a comment anywhere in that file. Example: |
| 91 | |
| 92 | ```yaml |
| 93 | # pint file/disable promql/aggregate |
| 94 | ``` |
| 95 | |
| 96 | Or you can disable it per rule by adding a comment to it. Example: |
| 97 | |
| 98 | ```yaml |
| 99 | # pint disable promql/aggregate |
| 100 | ``` |
| 101 | |
| 102 | If you want to disable only individual instances of this check |
| 103 | you can add a more specific comment. |
| 104 | |
| 105 | ### If `keep` is set |
| 106 | |
| 107 | ```yaml |
| 108 | # pint disable promql/aggregate($label:true) |
| 109 | ``` |
| 110 | |
| 111 | Example: |
| 112 | |
| 113 | ```yaml |
| 114 | # pint disable promql/aggregate(job:true) |
| 115 | ``` |
| 116 | |
| 117 | ### If `strip` is set |
| 118 | |
| 119 | ```yaml |
| 120 | # pint disable promql/aggregate($label:false) |
| 121 | ``` |
| 122 | |
| 123 | Example: |
| 124 | |
| 125 | ```yaml |
| 126 | # pint disable promql/aggregate(instance:true) |
| 127 | ``` |
| 128 | |
| 129 | ## How to snooze it |
| 130 | |
| 131 | You can disable this check until given time by adding a comment to it. Example: |
| 132 | |
| 133 | ```yaml |
| 134 | # pint snooze $TIMESTAMP promql/aggregate |
| 135 | ``` |
| 136 | |
| 137 | Where `$TIMESTAMP` is either use [RFC3339](https://www.rfc-editor.org/rfc/rfc3339) |
| 138 | formatted or `YYYY-MM-DD`. |
| 139 | Adding this comment will disable `promql/aggregate` *until* `$TIMESTAMP`, after that |
| 140 | check will be re-enabled. |
| 141 | |