From 38065bec7b1f7d5880f9e0080093cdee6778013b Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 17 Aug 2021 11:00:17 +0300 Subject: [PATCH] app/vmselect/promql: move common condition to dropStaleNaNs in order to improve code maintainability --- app/vmselect/promql/eval.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/vmselect/promql/eval.go b/app/vmselect/promql/eval.go index 041a66f01c..5a4a83b0fe 100644 --- a/app/vmselect/promql/eval.go +++ b/app/vmselect/promql/eval.go @@ -786,10 +786,7 @@ func getRollupMemoryLimiter() *memoryLimiter { func evalRollupWithIncrementalAggregate(name string, iafc *incrementalAggrFuncContext, rss *netstorage.Results, rcs []*rollupConfig, preFunc func(values []float64, timestamps []int64), sharedTimestamps []int64, removeMetricGroup bool) ([]*timeseries, error) { err := rss.RunParallel(func(rs *netstorage.Result, workerID uint) error { - if name != "default_rollup" { - // Remove Prometheus staleness marks, so non-default rollup functions don't hit NaN values. - rs.Values, rs.Timestamps = dropStaleNaNs(rs.Values, rs.Timestamps) - } + rs.Values, rs.Timestamps = dropStaleNaNs(name, rs.Values, rs.Timestamps) preFunc(rs.Values, rs.Timestamps) ts := getTimeseries() defer putTimeseries(ts) @@ -823,10 +820,7 @@ func evalRollupNoIncrementalAggregate(name string, rss *netstorage.Results, rcs tss := make([]*timeseries, 0, rss.Len()*len(rcs)) var tssLock sync.Mutex err := rss.RunParallel(func(rs *netstorage.Result, workerID uint) error { - if name != "default_rollup" { - // Remove Prometheus staleness marks, so non-default rollup functions don't hit NaN values. - rs.Values, rs.Timestamps = dropStaleNaNs(rs.Values, rs.Timestamps) - } + rs.Values, rs.Timestamps = dropStaleNaNs(name, rs.Values, rs.Timestamps) preFunc(rs.Values, rs.Timestamps) for _, rc := range rcs { if tsm := newTimeseriesMap(name, sharedTimestamps, &rs.MetricName); tsm != nil { @@ -925,7 +919,13 @@ func toTagFilter(dst *storage.TagFilter, src *metricsql.LabelFilter) { dst.IsNegative = src.IsNegative } -func dropStaleNaNs(values []float64, timestamps []int64) ([]float64, []int64) { +func dropStaleNaNs(name string, values []float64, timestamps []int64) ([]float64, []int64) { + if name == "default_rollup" { + // Do not drop Prometheus staleness marks (aka stale NaNs) for default_rollup() function, + // since it uses them for Prometheus-style staleness detection. + return values, timestamps + } + // Remove Prometheus staleness marks, so non-default rollup functions don't hit NaN values. hasStaleSamples := false for _, v := range values { if decimal.IsStaleNaN(v) {