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