cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/promql/aggregate.md
115lines · 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 | `# pint file/disable promql/aggregate` |
| 93 | |
| 94 | Or you can disable it per rule by adding a comment to it. Example: |
| 95 | |
| 96 | `# pint disable promql/aggregate` |
| 97 | |
| 98 | If you want to disable only individual instances of this check |
| 99 | you can add a more specific comment. |
| 100 | |
| 101 | ### If `keep` is set |
| 102 | |
| 103 | `# pint disable promql/aggregate($label:true)` |
| 104 | |
| 105 | Example: |
| 106 | |
| 107 | `# pint disable promql/aggregate(job:true)` |
| 108 | |
| 109 | ### If `strip` is set |
| 110 | |
| 111 | `# pint disable promql/aggregate($label:false)` |
| 112 | |
| 113 | Example: |
| 114 | |
| 115 | `# pint disable promql/aggregate(instance:true)` |
| 116 | |