I have these two recording rules, which work:
- record: job:sum_rate
expr: sum(rate(promhttp_metric_handler_requests_total[5m]))
- record: job:sum_rate:avg_over_time
expr: avg_over_time(job:sum_rate[10m])
When I try to enter the same expression into Prometheus directly though (e.g. in Grafana), meaning I enter avg_over_time(sum(rate(promhttp_metric_handler_requests_total[5m]))[10m])
, Prometheus tells me:
Error executing query: invalid parameter "query": 1:68: parse error: ranges only allowed for vector selectors
Why is that? Where is my misunderstanding? For testing purposes, I'd like to enter the given expression directly without a recording rule, since I need data of the last three weeks and a recording rule would start collecting data from scratch, though the data has already been monitored.
I found a solution by trial and error. To my understanding, a recording rule saves the data as a range vector, which avg_over_time() and rate() need as data type. The statements I entered in Grafana yield instant vectors though, so there is a mismatch. Entering avg_over_time(sum(rate(promhttp_metric_handler_requests_total[5m:15s]))[10m:15s]) solved the problem, because now these are range vectors