[v10.2.x] Prometheus: Fix $__rate_interval calculation (#84063)

Prometheus: Fix $__rate_interval calculation (#77234)

* Remove unused param

* simple unit test

* rename

* rename

* add some comments

* Update values

* refactor

* rename

* always calculate rate interval

* fix unit tests

* Fix indentation

* linter fix

* update test

* Fixing issues with the calculation

* new test

* fix $__interval interpolation

* fix test

* add comment

(cherry picked from commit b607a4e0a2)

Co-authored-by: ismail simsek <ismailsimsek09@gmail.com>
This commit is contained in:
Timur Olzhabayev
2024-03-07 18:00:59 +01:00
committed by GitHub
co-authored by ismail simsek
parent b76b2cf7f5
commit e6f7a39824
2 changed files with 2 additions and 77 deletions
-6
View File
@@ -96,7 +96,6 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator
query.Interval,
calculatedMinStep,
model.Interval,
dsScrapeInterval,
timeRange,
)
var rangeQuery, instantQuery bool
@@ -228,14 +227,12 @@ func calculateRateInterval(
// queryInterval Requested interval in milliseconds. This value may be overridden by MinStep in query options
// calculatedMinStep Calculated final step value. It was calculated in calculatePrometheusInterval
// requestedMinStep Requested minimum step value. QueryModel.interval
// dsScrapeInterval Data source scrape interval in the config
// timeRange Requested time range for query
func interpolateVariables(
expr string,
queryInterval time.Duration,
calculatedMinStep time.Duration,
requestedMinStep string,
dsScrapeInterval string,
timeRange time.Duration,
) string {
rangeMs := timeRange.Milliseconds()
@@ -248,9 +245,6 @@ func interpolateVariables(
if requestedMinStep == varInterval || requestedMinStep == varIntervalAlt {
requestedMinStep = calculatedMinStep.String()
}
if requestedMinStep == "" {
requestedMinStep = dsScrapeInterval
}
rateInterval = calculateRateInterval(queryInterval, requestedMinStep)
}