|
|
|
@ -84,7 +84,7 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Final step value for prometheus
|
|
|
|
|
calculatedMinStep, err := calculatePrometheusInterval(model.Interval, dsScrapeInterval, model.IntervalMs, model.IntervalFactor, query, intervalCalculator) |
|
|
|
|
calculatedStep, err := calculatePrometheusInterval(model.Interval, dsScrapeInterval, model.IntervalMs, model.IntervalFactor, query, intervalCalculator) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
@ -94,7 +94,7 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator |
|
|
|
|
expr := interpolateVariables( |
|
|
|
|
model.Expr, |
|
|
|
|
query.Interval, |
|
|
|
|
calculatedMinStep, |
|
|
|
|
calculatedStep, |
|
|
|
|
model.Interval, |
|
|
|
|
dsScrapeInterval, |
|
|
|
|
timeRange, |
|
|
|
@ -126,7 +126,7 @@ func Parse(query backend.DataQuery, dsScrapeInterval string, intervalCalculator |
|
|
|
|
|
|
|
|
|
return &Query{ |
|
|
|
|
Expr: expr, |
|
|
|
|
Step: calculatedMinStep, |
|
|
|
|
Step: calculatedStep, |
|
|
|
|
LegendFormat: model.LegendFormat, |
|
|
|
|
Start: query.TimeRange.From, |
|
|
|
|
End: query.TimeRange.To, |
|
|
|
@ -226,14 +226,14 @@ func calculateRateInterval( |
|
|
|
|
// interpolateVariables interpolates built-in variables
|
|
|
|
|
// expr PromQL query
|
|
|
|
|
// 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
|
|
|
|
|
// calculatedStep 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, |
|
|
|
|
calculatedStep time.Duration, |
|
|
|
|
requestedMinStep string, |
|
|
|
|
dsScrapeInterval string, |
|
|
|
|
timeRange time.Duration, |
|
|
|
@ -243,10 +243,10 @@ func interpolateVariables( |
|
|
|
|
|
|
|
|
|
var rateInterval time.Duration |
|
|
|
|
if requestedMinStep == varRateInterval || requestedMinStep == varRateIntervalAlt { |
|
|
|
|
rateInterval = calculatedMinStep |
|
|
|
|
rateInterval = calculatedStep |
|
|
|
|
} else { |
|
|
|
|
if requestedMinStep == varInterval || requestedMinStep == varIntervalAlt { |
|
|
|
|
requestedMinStep = calculatedMinStep.String() |
|
|
|
|
requestedMinStep = calculatedStep.String() |
|
|
|
|
} |
|
|
|
|
if requestedMinStep == "" { |
|
|
|
|
requestedMinStep = dsScrapeInterval |
|
|
|
@ -254,8 +254,8 @@ func interpolateVariables( |
|
|
|
|
rateInterval = calculateRateInterval(queryInterval, requestedMinStep) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
expr = strings.ReplaceAll(expr, varIntervalMs, strconv.FormatInt(int64(queryInterval/time.Millisecond), 10)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varInterval, intervalv2.FormatDuration(queryInterval)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varIntervalMs, strconv.FormatInt(int64(calculatedStep/time.Millisecond), 10)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varInterval, intervalv2.FormatDuration(calculatedStep)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varRangeMs, strconv.FormatInt(rangeMs, 10)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varRangeS, strconv.FormatInt(rangeSRounded, 10)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varRange, strconv.FormatInt(rangeSRounded, 10)+"s") |
|
|
|
@ -263,8 +263,8 @@ func interpolateVariables( |
|
|
|
|
expr = strings.ReplaceAll(expr, varRateInterval, rateInterval.String()) |
|
|
|
|
|
|
|
|
|
// Repetitive code, we should have functionality to unify these
|
|
|
|
|
expr = strings.ReplaceAll(expr, varIntervalMsAlt, strconv.FormatInt(int64(queryInterval/time.Millisecond), 10)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varIntervalAlt, intervalv2.FormatDuration(queryInterval)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varIntervalMsAlt, strconv.FormatInt(int64(calculatedStep/time.Millisecond), 10)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varIntervalAlt, intervalv2.FormatDuration(calculatedStep)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varRangeMsAlt, strconv.FormatInt(rangeMs, 10)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varRangeSAlt, strconv.FormatInt(rangeSRounded, 10)) |
|
|
|
|
expr = strings.ReplaceAll(expr, varRangeAlt, strconv.FormatInt(rangeSRounded, 10)+"s") |
|
|
|
|