Comparison operators
Every PromQL query starts by selecting series: a metric name plus label matchers in curly braces. Each matcher narrows the series set the query reads, which is the biggest single lever on query cost.
Equal (=)
Selects time series whose label value is exactly equal to the given string. Matchers appear in curly braces after the metric name; every additional matcher narrows the series set the query reads, which is the single biggest lever on query cost.
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Required |
A label on the metric, such as |
|
Required |
The exact string to match; case-sensitive. |
Example
Select the goroutine-count gauge for the Kloudfuse query-service only, then sum it into a single series.
sum(go_goroutines{app_kubernetes_io_name="query-service"})
| Value |
|---|
64,531 |
|
Combine matchers with commas: A bare metric name with no matchers selects every series of that metric across all sources. |
Not equal (!=)
Selects time series whose label value is not equal to the given string. Use it to exclude one known series from an otherwise broad selection.
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Required |
The label to test. |
|
Required |
The string value to exclude. |
Example
Count goroutines across Kloudfuse services excluding the query-service, grouped by service name.
sum by (app_kubernetes_io_name) (
go_goroutines{app_kubernetes_io_instance="kfuse", app_kubernetes_io_name!="query-service"}
)
| app_kubernetes_io_name | Value |
|---|---|
rum-query-service |
1,302 |
zapper |
2,567 |
config-mgmt-service |
725 |
ingester |
98,322 |
envoy-gateway |
1,927 |
|
Pair negative matchers with at least one positive matcher — a selector of only negations reads every series of the metric. |
Regex not match (!~)
Selects time series whose label value does not match an RE2 regular expression. One !~ matcher can exclude several values at once via alternation.
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Required |
The label to test. |
|
Required |
An anchored RE2 expression; fully matching series are excluded. |
Example
Count goroutines for Kloudfuse services that are not one of the query services.
sum by (app_kubernetes_io_name) (
go_goroutines{app_kubernetes_io_instance="kfuse", app_kubernetes_io_name!~".*query-service"}
)
| app_kubernetes_io_name | Value |
|---|---|
envoy-gateway |
1,926 |
zapper |
2,570 |
kfuse-grafana |
60,471 |
trace-transformer |
97,843 |
hydration-service |
558 |
|
Like |
Regex match (=~)
Selects time series whose label value matches an RE2 regular expression. The expression is fully anchored — it must match the entire label value. Use it to select a family of related series in one matcher.
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Required |
The label to test. |
|
Required |
An RE2 regular expression, anchored at both ends of the value. |
Example
Select goroutine gauges for every Kloudfuse query service — query-service, events-query-service, and rum-query-service all match the expression.
sum by (app_kubernetes_io_name) (
go_goroutines{app_kubernetes_io_name=~".*query-service"}
)
| app_kubernetes_io_name | Value |
|---|---|
rum-query-service |
1,312 |
logs-query-service |
19,541 |
query-service |
64,555 |
trace-query-service |
3,052 |
events-query-service |
3,017 |
|
Because the match is anchored, Prefer |