Im new to grafana and from what I’ve learned,
when you set an alerting rule(Grafana 9 - unified alerting),
you can set a query(A) and then an expr(B).
I got that the expr is the one to set the threshold based on the query.
(please correct me if this isnt the case)
But what if I dont set any expr, and just set the query, then also define the alert condition as query(A)? what would happen?
The main reason im wondering, is that i think there is nothing i can set as a condition in the query itself when it stands alone.
Also what i dont understand is: why are there two options (query(A), and expr(B)) to choose as an alert condition in the first place? i think there should be only expr(B) as an option.
Any help/answers? Thanks.
Grafana alerting executes an expression and expects a “vector” of outputs to alert on:
Any expression that can produce an output like than can be alerted on. Non-zero values will generate an alert, and zeroes will not alert.
For timeseries data, you can start with a query that returns many series, but then you need to reduce those each of those series into single numbers. A common approach would be to use a “Reduce” step to find a something like the maximum value for each series, followed by a Math expression to compare the value to a threshold.
For some datasources, like SQL databases, you can write a query that directly outputs the format used in alerting and wouldn’t need any additional expressions after the query.
So if query A already outputs a vector of results, then you can alert directly using it. If it produces something else, the alert rule evaluation will fail with an error message, and you would need more steps in your alerting rule expression to format the data properly. You can test this in the alert rule editor using the “run queries” and “preview alerts” buttons.