Course outline

Prometheus / Basic: collection and time-series meaning / Lesson 7

PromQL comparisons and boolean results

Distinguish filtering comparisons from bool results and test their effect on alert instances.

About 4 min readContent reviewed
On this page

Lesson goals

  • Explain vector comparison filtering and bool.
  • Compare synthetic values with a scalar threshold.
  • Recognize why zero-valued alert results can still be active.

Read comparison results carefully

PromQL comparisons can filter an instant vector by a condition. A filtering comparison retains matching elements with their values; elements that fail are omitted. With the bool modifier, eligible matched elements instead produce 0 or 1 values. This difference matters when a downstream expression or alert consumes the result. Evaluate at a fixed time with known synthetic series before interpreting a dashboard or rule.

Filter a synthetic gauge

The first expression selects synthetic temperature series above a threshold. The metric and threshold are examples, not a recommended operational limit. If a series has a sample below the threshold, that series is filtered from this result rather than represented as zero. Missing data also produces no matching result, so investigate target health and expected labels separately before interpreting absence.

promql Filter above a synthetic threshold
lab_temperature_celsius > 5

The expression is illustrative. It keeps matching input elements and their values rather than producing a universal alert threshold.

Return a boolean-valued vector

The second expression uses bool to return 1 for a true comparison and 0 for a false one for eligible input elements. It does not invent an element for an absent input series. Metric-name and matching details depend on the expression and operator, so inspect the actual output labels in the installed Prometheus version. A 0 result is a present series, not an absent series.

promql Produce boolean-valued elements
lab_temperature_celsius > bool 5

The bool modifier yields 0 or 1 for eligible inputs. A zero-valued element remains present.

Avoid an alerting trap

An alerting rule creates an active alert instance for each resulting vector element under its rule semantics; a present element with value 0 is still an element. Therefore a bool comparison used directly as an alert expression may produce an alert for a false condition. Use a filtering expression when that is the intended rule, and test pending, firing, absence and recovery with synthetic samples.

Verify at fixed times

In a disposable Prometheus or promtool fixture, include a value below, above and exactly at the chosen threshold, plus a missing series. Compare values and label sets for both expressions at fixed evaluation times. Test the actual alert rule separately, including its for duration and receiver path. The displayed fragments are illustrative and have not been executed against Prometheus in this course.

Common errors and fixes

A false comparison still activates an alert

Why it happens
A bool result of zero remained a vector element.
How to fix it
Use an expression that returns elements only for the intended alert condition.
Prevent it next time
Test false, true and missing samples in a rule fixture.

An absent target is interpreted as a zero value

Why it happens
No series was returned for the missing input.
How to fix it
Check target health and design an explicit absence rule where needed.
Prevent it next time
Test missing and zero-valued series separately.

A threshold is copied into production unchanged

Why it happens
A synthetic example was treated as a universal limit.
How to fix it
Choose a threshold from the service objective and measured behavior.
Prevent it next time
Review units, workload and ownership before deployment.

2 practice exercises

1. A gauge value is 3 and the threshold is 5. How do the two examples differ?

Show worked solution

The filtering comparison omits that series because the condition is false. The bool form returns a present element with value 0. An alert directly consuming the bool vector can therefore still have an active element.

2. What does either expression return for a completely absent input series?

Show worked solution

Neither comparison creates a matching input element merely because it is absent. Diagnose collection and expected labels, and use an explicit absence strategy if the operational contract requires one.

Key takeaways

  • Filtering removes false elements; bool preserves eligible elements as 0 or 1.
  • Alerting depends on vector presence, so test false and missing cases.

Official references