From 47390d89475eb510a5cb8a851cdf7584ce3488a9 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 10 Nov 2020 14:51:13 +0200 Subject: [PATCH] app/vmselect/promql: do not return data points in the end of the selected time range for time series ending in the middle of the selected time range Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/887 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/845 --- app/vmselect/promql/rollup.go | 7 ++++--- docs/CHANGELOG.md | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 5c5f6904d..bf92351f0 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -507,7 +507,9 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu ni := 0 nj := 0 stalenessInterval := int64(float64(scrapeInterval) * 0.9) - canDropLastSample := rc.CanDropLastSample + // Do not drop trailing data points for queries, which return 2 or 1 point (aka instant queries). + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/845 + canDropLastSample := rc.CanDropLastSample && len(rc.Timestamps) > 2 for _, tEnd := range rc.Timestamps { tStart := tEnd - window ni = seekFirstTimestampIdxAfter(timestamps[i:], tStart, ni) @@ -526,13 +528,12 @@ func (rc *rollupConfig) doInternal(dstValues []float64, tsm *timeseriesMap, valu } rfa.values = values[i:j] rfa.timestamps = timestamps[i:j] - if canDropLastSample && j == len(timestamps) && j > 0 && (tEnd-timestamps[j-1] > stalenessInterval || i == j && len(timestamps) == 1) && rc.End-tEnd >= 2*rc.Step { + if canDropLastSample && 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 - // Do not drop trailing data points for instant queries. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/845 rfa.prevValue = nan rfa.values = nil rfa.timestamps = nil diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0eb065b44..07b827338 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,9 @@ See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/825#issuecomment-724308361 for details. * FEATURE: vmalert: explicitly set extra labels to alert entities. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/870 +* BUGFIX: do not return data points in the end of the selected time range for time series ending in the middle of the selected time range. + See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/887 and https://github.com/VictoriaMetrics/VictoriaMetrics/issues/845 + # [v1.46.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.46.0)