From ee2902ddafaec1e7802369e010ea7c73099c84d7 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 17 Oct 2020 10:39:35 +0300 Subject: [PATCH] app/vmselect/promql: an attempt to improve heuristics for dropping trailing data points in time series Now trailing data points are additionally dropped for time series with a single raw sample Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/748 --- app/vmselect/promql/rollup.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index a9718f008c..41ca13b958 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -519,9 +519,10 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu } rfa.values = values[i:j] rfa.timestamps = timestamps[i:j] - if j == len(timestamps) && i < j && tEnd-timestamps[j-1] > stalenessInterval { - // Do not take into account the last data point in time series if the distance between this data point - // and tEnd exceeds stalenessInterval. + if j == len(timestamps) && j > 0 && (tEnd-timestamps[j-1] > stalenessInterval || i == j && len(timestamps) == 1) { + // Drop trailing data points in the following cases: + // - if the distance between the last raw sample and tEnd exceeds stalenessInterval + // - if time series contains only a single raw sample // This should prevent from double counting when a label changes in time series (for instance, // during new deployment in K8S). See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/748 rfa.prevValue = nan