cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.77.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

docs/checks/promql/impossible.md

123lines · modecode

1---
2layout: default
3parent: Checks
4grand_parent: Documentation
5---
6
7# promql/impossible
8
9This check will report PromQL queries that can never return anything.
10
11Example query:
12
13```js
14foo{job="bar"} unless sum(foo)
15```
16
17The 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
19having at least the `job` label, while the right hand side has no labels, so we end up with:
20
21```js
22foo{job="bar"} unless {}
23```
24
25Both 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
27This check will also detect aggregations on labels that are already removed. Example:
28
29```js
30group by(cluster) (
31 sum(errors)
32)
33```
34
35In the above `sum(errors)` removes all labels from the results, so there will be no `cluster` label to aggregate
36in the `group by(cluster)` outer query.
37
38Similarly this check will warn about joins using labels that are already removed, example:
39
40```js
41sum(foo) / on(cluster) count(bar)
42```
43
44Since both `sum(...)` calls remove all labels there won't be any `cluster` label to join on.
45
46Another problem detected by this check is binary aggregations that block labels from propagating to the results.
47Consider this query:
48
49```js
50service_ready * on (cluster) group_left(env, location) cluster_info
51```
52
53What 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.
55But what happens if someone wanted to further filter down the results of `service_ready` with a filter like:
56
57```js
58service_ready and on (instance) (service_errors == 0)
59```
60
61We can simply add it to the query:
62
63```js
64service_ready and on (instance) (service_errors == 0) * on (cluster) group_left(env, location) cluster_info
65```
66
67But 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
72When we the evaluate `A and on(instance) B` we no longer propagate `env` and `location` to the results, because
73these labels are only added to the results on the `B` side.
74One 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
83This check doesn't have any configuration options.
84
85## How to enable it
86
87This check is enabled by default.
88
89## How to disable it
90
91You can disable this check globally by adding this config block:
92
93```js
94checks {
95 disabled = ["promql/impossible"]
96}
97```
98
99You can also disable it for all rules inside given file by adding
100a comment anywhere in that file. Example:
101
102```yaml
103# pint file/disable promql/impossible
104```
105
106Or 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
114You 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
120Where `$TIMESTAMP` is either use [RFC3339](https://www.rfc-editor.org/rfc/rfc3339)
121formatted or `YYYY-MM-DD`.
122Adding this comment will disable `promql/impossible` *until* `$TIMESTAMP`, after that
123check will be re-enabled.
124