You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 2, 2024. It is now read-only.
You can also match series using label matchers to create predicates on values of particular
128
+
label keys. This is very similar to the label matchers available in PromQL.
129
+
130
+
For example to find all metrics on in the dev namespace and on node brain using
131
+
label matcher, you can run:
132
+
133
+
```SQL
134
+
SELECT*
135
+
FROM cpu_usage u
136
+
WHERE labels ? ('namepace'=='dev') AND labels ? ('node'=='brain')
137
+
```
138
+
139
+
Label matchers are formed by using a qualifier of the form `labels ? (<tag_key> <operator> <pattern>)`.
140
+
There are four operators,
141
+
142
+
-`==` match tag values that are equal to the pattern
143
+
-`!==` match tag value that are not equal to the pattern
144
+
-`==~` match tag values that match the pattern as a regex
145
+
-`!=~` match tag values that are not equal to the pattern
146
+
147
+
These four matchers correspond to each of the four selectors in PromQL but with slightly
148
+
different names (to avoid clashing with other PostgreSQL operators). They can
149
+
be combined together using any boolean logic with any arbitrary where clauses.
150
+
151
+
For those coming from PromQL there are a few differences to keep in mind:
152
+
- Regexes are not anchored for you. Although, you can of course add anchors (`^$`) yourself.
153
+
- The logic for whether series that are missing the tag key pass the qualifier is slightly different:
154
+
If the key on the left-hand side is not found `!==` and `!=~` always match, while `==` and `==~` never match.
155
+
156
+
157
+
### Equivalence
158
+
159
+
The `eq` function tests exact equivalence between labels, without comparing the metric name (`__name__`) label key.
160
+
For instance if the labels `a` is `{"__name__":"metric", "foo":"bar", "baz":"frob"}`
161
+
then `SELECT eq(a, jsonb {"__name__":"something else", "foo":"bar", "baz":"frob"})` will evaluate to `true`, however, unlike `@>` if `SELECT eq(a, {"__name__":"metric", "foo":"bar"})` will evaluate to `false`.
162
+
Thus, it can be used to compare across metrics or within a metric.
163
+
164
+
For example, to join 2 series that are scraped at the same time:
165
+
166
+
```SQL
167
+
SELECT*
168
+
FROM cpu_usage u
169
+
INNER JOIN cpu_total t ON (u.time=t.timeAND eq(u.labels, t.labels))
0 commit comments