We have a rate limit of 500 fetches per second from an external API. I want to track how close are we to this limit as the user base grows on a scale of weeks. I don't need the exact rate every second, I need the maximum 1-second-rate in a 1 hour window. The fetches are in bursts so the rate over 1 second can be much higher than the average rate over 1 hour or even 1 minute.
I have a Prometheus counter on the fetches and can use this query:
max_over_time(sum(rate(fetches_counter_total{namespace="$namespace"}[1m]))[1h:1m])
This does the max-in-window correctly but only on 1-minute-average-rate and not 1-second-rate. When I change the ending to [1s]))[1h:1s]) Grafana says "No Data" and no plot is shown.
I thought that maybe Prometheus is not fast enough so I added to the code a log every time a fetch happens and I can get the rate of logs from Loki using this query:
sum(count_over_time({namespace="$namespace"} |= "Fetch happened log text" [1s]))
This gives the 1-second-rate accurately but when I set the range to a week there are much less points than seconds in a week and refreshing shows a different subset of points each time. To get the max-in-window I tried this query:
max_over_time(sum(count_over_time({namespace="$namespace"} |= "Fetch happened log text" [1s]))[5m:1s])
But it throws an error:
parse error at line 1, col 15: syntax error: unexpected SUM, expecting NUMBER or { or (
Now I'm stuck. From the documentation, seems that unwraping the logs might help but I don't have any labels and don't understand how to apply unwrap to this situation.
In summary, is it possible to get 1-second-rate from Prometheus or max_over_time of number of logs from Loki?