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.

Syntax

<metric>{<label>="<value>"}
none

Parameters

Parameter Required Description

<label>

Required

A label on the metric, such as kube_namespace, app_kubernetes_io_name, or availability_zone.

<value>

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"})
Expected output
Value

64,531

Combine matchers with commas: {app_kubernetes_io_instance="kfuse", availability_zone="us-east-1b"}. All must hold at once.

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.

Syntax

<metric>{<label>!="<value>"}
none

Parameters

Parameter Required Description

<label>

Required

The label to test.

<value>

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"}
)
Expected output
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.

Syntax

<metric>{<label>!~"<regex>"}
none

Parameters

Parameter Required Description

<label>

Required

The label to test.

<regex>

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"}
)
Expected output
app_kubernetes_io_name Value

envoy-gateway

1,926

zapper

2,570

kfuse-grafana

60,471

trace-transformer

97,843

hydration-service

558

Like =~, the expression is anchored against the whole label value.

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.

Syntax

<metric>{<label>=~"<regex>"}
none

Parameters

Parameter Required Description

<label>

Required

The label to test.

<regex>

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"}
)
Expected output
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, =~"query" matches only the exact value query; use .query. for a contains match.

Prefer = when you know the exact value — equality matchers resolve faster than regex.