Write OR conditions in PromQL
Use regex alternatives for label values and vector set operators for query results, with explicit matching when needed.
For several values of one label, use a regex matcher such as status=~"500|502|503". To combine the results of two expressions, use the instant-vector set operator or. It selects series by label matching; it does not add their values or test whether a sample is nonzero.
Match several values of one label
http_requests_total{status=~"500|502|503"}
Prometheus regex label matchers are fully anchored, so these alternatives match those complete status values. This is a concise selector for a single label, without claiming that one syntax is always the fastest for every dataset.
Combine two result sets
up{job="app"} or up{job="db"}
The result contains every left-hand series plus right-hand series with no matching left-hand series. When both sides match, the left-hand value wins, including when it is zero. Default vector matching uses ordinary labels and ignores the metric name. on(...) or ignoring(...) can change the matching keys.
A high-error or missing-metric condition can be written as:
(error_rate{job="app"} > 0.05)
or absent(http_requests_total{job="app"})
This assumes error_rate already represents the intended fraction. absent() detects that the selector has no series at all; it does not automatically identify each missing instance in a previously larger fleet. The two branches can also produce different alert labels. Design routing and annotations for those differences, or use separate alerts.
Use and and unless for presence-based filtering
(cpu_usage > 0.8) and on (instance) (memory_usage > 0.9)
With these example metrics expressed as fractions, this retains CPU samples whose instance also has a memory sample above the threshold. Add job, cluster, or other identity labels if instance alone is not unique in your data.
To exclude instances with an error rate above a threshold:
(rate(http_requests_total[5m]) > 10)
unless on (job, instance) (rate(http_errors_total[5m]) > 1)
The thresholds are illustrative. The comparison removes nonmatching samples before the set operation. Without > 1, even an error-rate series with value zero is present and can exclude a request series. unless means “no matching series on the right,” not “the right side has a low value.”
Common questions
What happens when labels differ? The series may not match, so or retains both. Inspect labels and deliberately select matching keys rather than changing labels just to make a graph look consistent.
Can I combine different metric names? Yes. For matching ordinary labels, the left metric takes precedence. Use or on (...) for a deliberately keyed fallback. Group modifiers such as group_left are for arithmetic/comparison matching and cannot be used with set operators.
References
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan