cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
docs/checks/promql/impossible.md
123lines · modecode
| 1 | --- |
| 2 | layout: default |
| 3 | parent: Checks |
| 4 | grand_parent: Documentation |
| 5 | --- |
| 6 | |
| 7 | # promql/impossible |
| 8 | |
| 9 | This check will report PromQL queries that can never return anything. |
| 10 | |
| 11 | Example query: |
| 12 | |
| 13 | ```js |
| 14 | foo{job="bar"} unless sum(foo) |
| 15 | ``` |
| 16 | |
| 17 | The right hand side (`unless sum(foo)`) cannot ever match any time series returned by the left hand side |
| 18 | (`foo{job="bar"}`) because `sum()` strips away all labels. This means that we end up with left hand side |
| 19 | having at least the `job` label, while the right hand side has no labels, so we end up with: |
| 20 | |
| 21 | ```js |
| 22 | foo{job="bar"} unless {} |
| 23 | ``` |
| 24 | |
| 25 | Both sides can only match if they have the same label set, see [Prometheus docs](https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching). A result with `{job="bar"}` will never be matched with empty label set `{}`. |
| 26 | |
| 27 | This check will also detect aggregations on labels that are already removed. Example: |
| 28 | |
| 29 | ```js |
| 30 | group by(cluster) ( |
| 31 | sum(errors) |
| 32 | ) |
| 33 | ``` |
| 34 | |
| 35 | In the above `sum(errors)` removes all labels from the results, so there will be no `cluster` label to aggregate |
| 36 | in the `group by(cluster)` outer query. |
| 37 | |
| 38 | Similarly this check will warn about joins using labels that are already removed, example: |
| 39 | |
| 40 | ```js |
| 41 | sum(foo) / on(cluster) count(bar) |
| 42 | ``` |
| 43 | |
| 44 | Since both `sum(...)` calls remove all labels there won't be any `cluster` label to join on. |
| 45 | |
| 46 | Another problem detected by this check is binary aggregations that block labels from propagating to the results. |
| 47 | Consider this query: |
| 48 | |
| 49 | ```js |
| 50 | service_ready * on (cluster) group_left(env, location) cluster_info |
| 51 | ``` |
| 52 | |
| 53 | What happens above is that we are joining our results for the `service_ready` series with an extra time series |
| 54 | `cluster_info` and add two labels (`env` and `location`) to query results. |
| 55 | But what happens if someone wanted to further filter down the results of `service_ready` with a filter like: |
| 56 | |
| 57 | ```js |
| 58 | service_ready and on (instance) (service_errors == 0) |
| 59 | ``` |
| 60 | |
| 61 | We can simply add it to the query: |
| 62 | |
| 63 | ```js |
| 64 | service_ready and on (instance) (service_errors == 0) * on (cluster) group_left(env, location) cluster_info |
| 65 | ``` |
| 66 | |
| 67 | But doing it this way splits our query in two parts: |
| 68 | |
| 69 | - A: `service_ready` |
| 70 | - B: `(service_errors == 0) * on (cluster) group_left(env, location) cluster_info` |
| 71 | |
| 72 | When we the evaluate `A and on(instance) B` we no longer propagate `env` and `location` to the results, because |
| 73 | these labels are only added to the results on the `B` side. |
| 74 | One way to fix this is to ensure that we join extra labels with the entire |
| 75 | `service_ready and on (instance) (service_errors == 0)` expression by wrapping it in parentheses. |
| 76 | |
| 77 | ```js |
| 78 | (service_ready and on (instance) (service_errors == 0)) * on (cluster) group_left(env, location) cluster_info |
| 79 | ``` |
| 80 | |
| 81 | ## Configuration |
| 82 | |
| 83 | This check doesn't have any configuration options. |
| 84 | |
| 85 | ## How to enable it |
| 86 | |
| 87 | This check is enabled by default. |
| 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 = ["promql/impossible"] |
| 96 | } |
| 97 | ``` |
| 98 | |
| 99 | You can also disable it for all rules inside given file by adding |
| 100 | a comment anywhere in that file. Example: |
| 101 | |
| 102 | ```yaml |
| 103 | # pint file/disable promql/impossible |
| 104 | ``` |
| 105 | |
| 106 | Or you can disable it per rule by adding a comment to it. Example: |
| 107 | |
| 108 | ```yaml |
| 109 | # pint disable promql/impossible |
| 110 | ``` |
| 111 | |
| 112 | ## How to snooze it |
| 113 | |
| 114 | You can disable this check until given time by adding a comment to it. Example: |
| 115 | |
| 116 | ```yaml |
| 117 | # pint snooze $TIMESTAMP promql/impossible |
| 118 | ``` |
| 119 | |
| 120 | Where `$TIMESTAMP` is either use [RFC3339](https://www.rfc-editor.org/rfc/rfc3339) |
| 121 | formatted or `YYYY-MM-DD`. |
| 122 | Adding this comment will disable `promql/impossible` *until* `$TIMESTAMP`, after that |
| 123 | check will be re-enabled. |
| 124 | |