Prometheus: Fix regression for $__rate_interval comparison (#67460)

* fix ,  comparison regression

* intervalMs was not pressent before the regression and this value changes the adjusted interval calculating giving a false positive in favor of the regression
pull/67507/head
Brendan O'Handley 2 years ago committed by GitHub
parent 7a3f7e26ce
commit d4a22cff0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      pkg/tsdb/prometheus/models/query.go
  2. 1
      pkg/tsdb/prometheus/models/query_test.go

@ -156,6 +156,10 @@ func calculatePrometheusInterval(
query backend.DataQuery,
intervalCalculator intervalv2.Calculator,
) (time.Duration, error) {
// we need to compare the original query model after it is overwritten below to variables so that we can
// calculate the rateInterval if it is equal to $__rate_interval or ${__rate_interval}
originalQueryInterval := queryInterval
// If we are using variable for interval/step, we will replace it with calculated interval
if isVariableInterval(queryInterval) {
queryInterval = ""
@ -173,7 +177,8 @@ func calculatePrometheusInterval(
adjustedInterval = calculatedInterval.Value
}
if queryInterval == varRateInterval || queryInterval == varRateIntervalAlt {
// here is where we compare for $__rate_interval or ${__rate_interval}
if originalQueryInterval == varRateInterval || originalQueryInterval == varRateIntervalAlt {
// Rate interval is final and is not affected by resolution
return calculateRateInterval(adjustedInterval, timeInterval, intervalCalculator), nil
} else {

@ -376,7 +376,6 @@ func TestParse(t *testing.T) {
"format": "time_series",
"intervalFactor": 1,
"interval": "$__rate_interval",
"intervalMs": 60000,
"refId": "A"
}`, timeRange)

Loading…
Cancel
Save