shashwat
shashwat

Reputation: 23

Rate() / Increase() Extrapolation happens for all the data points?

I have done a lot of analysis on rate() function but have not got a perfect answer for the same. Lets Suppose I have set the scraping level as 1m and this is my expression rate(http_request_total[5m])

  1. So Ideally I should get 5 data points at 1m interval scrapping which I am referring as V0,V1,V2,V3,V4,V5 .
  2. Now , when Rate method will get evaluated , I am not sure if I have a correct understanding but I have this formula in mind. Rate()*300=(V5-V0)/(t5-t1)

My question is this how rate will get calculated(my understanding is correct)? and how the extrapolation will be done the rate() in this example? I know for increase() its like the value we get from the above multiplied to the total interval

Upvotes: 1

Views: 2552

Answers (1)

hagen1778
hagen1778

Reputation: 819

My question is this how rate will get calculated(my understanding is correct)?

Theoretically, it is correct (except in your example you have 6 datapoints, not 5). But the "magic" starts happening when you add start and end params to your query. In most cases, these two params will not exactly match t1 and t5 from your example, and Prometheus won't be able to capture one or more data points of yours: enter image description here

In the example above, time window isn't perfectly aligned with real values. In this case, value of v1 will be missed, which would affect the result since increase will be calculated between v5 and v2. Knowing the avg interval between received values, Prometheus could assume that it didn't capture some of the values. So it will try to extrapolate the result by simply multiplying it by coefficient.

I'd recommend reading this great thread https://github.com/prometheus/prometheus/issues/3746.

I'd also recommend reading how alternative rate could work here https://medium.com/@romanhavronenko/victoriametrics-promql-compliance-d4318203f51e in "Better rate" section. Disclosure, I am one of the developers at VictoriaMetrics, so take it with a grain of salt.

Upvotes: 1

Related Questions