But when there is no 200|400|401|403|429|404 of /api/a the return of sum(count_over_time({app="xxx"}|="{"|json|route="POST /api/a" , status=~200|400|401|403|429|404 [1m])) is no data ,and i wanna turn it to zero. So the total result can be 0%
It’d be really helpful to get an answer on this. Now that we can alert based on Loki LogQL metric queries, sending alerts based on error logs seems like a common use case. But if your query returns no data when there are no error logs, it’s impossible to get your alert to work properly.
Came up with kinda ugly solution. Basic idea is that you should negate your regexp first, and than subtract this value from sum without conditions. Something like this:
sum(x) - sum ( x | code !~"^5…")
I agree that this is a useful feature.
For example if I display graph line of number of errors in logs - if there are none I want it to be displayed as 0 and that it won’t disappear from the graph.