Prometheus alert evaluation, are they instant queries?

78 views
Skip to first unread message

Andrew Dedesko

unread,
Feb 3, 2024, 11:02:44 AM2/3/24
to Prometheus Users
Hi,

I'm wondering whether prometheus uses instant queries or range queries when evaluating alert expressions?  The context about why I'm asking might help clarify my question.

I'm comparing Grafana Cloud's alerting functionality with prometheus.  From Grafana Cloud we're querying Google Cloud Metrics with PromQL (it's Google's Monarch DB with a PromQL interface).  Grafana Cloud's alerting system takes your PromQL query and performs a range query against Google Cloud Metrics, returning multiple data points over the range you have selected (e.g. 10 minutes ago to now).  Then you need to choose a reducer function to turn the time series into an instant scalar (e.g. min, max, last, mean).

Prometheus alerts don't seem to have an option for specifying a range and also don't have a reducer option.  So this leads me to believe prometheus uses instant queries to evaluate alert expressions.  But I'd like to know for sure.

Thanks for reading!

Here's the Grafana Cloud documentation on alert query ranges and reducers:
https://grafana.com/docs/grafana/latest/alerting/alerting-rules/create-grafana-managed-rule/

Ben Kochie

unread,
Feb 3, 2024, 11:04:56 AM2/3/24
to Andrew Dedesko, Prometheus Users
All rule evaluations are instant queries. You do all the "reducer functions" in PromQL itself.

For example, you can use subquery syntax to do something like `avg_over_time()`.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/ef0e2ee6-a32e-479e-bbe4-10499372715cn%40googlegroups.com.

Brian Candler

unread,
Feb 3, 2024, 11:16:11 AM2/3/24
to Prometheus Users
Even without a subquery, a rule can include a range vector expression and then reduce it to an instant vector, e.g.

expr: avg_over_time(snmp_scrape_duration_seconds[5m]) >= 3

Ben Kochie

unread,
Feb 3, 2024, 11:24:07 AM2/3/24
to Brian Candler, Prometheus Users
Yes, that Grafana API seems to be unnecessary complicated compared to just using PromQL.

Andrew Dedesko

unread,
Feb 6, 2024, 4:18:14 PM2/6/24
to Prometheus Users
That's a good point, Ben and Brian!  And thank you both for clarifying!

Bryan Boreham

unread,
Feb 7, 2024, 8:54:10 AM2/7/24
to Prometheus Users
Grafana can alert off 200 different data sources, most of which do not support PromQL, so it is necessary to offer more features in the client.
Reply all
Reply to author
Forward
0 new messages