From 3d22532bb846fb20ac3b773494c9d4b9caf5af8b Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 11 Jan 2023 00:11:07 -0800 Subject: [PATCH] app/vmselect/promql: make a copy of per-series timestamps before their modification The per-series timestamps are usually shared among series, so it is unsafe modifying them. The issue has been appeared after the optimization at 2f3ddd4884ed9935d2a358c1ab289cd7cabe7a3b --- app/vmselect/prometheus/prometheus.go | 10 ++++++++-- docs/CHANGELOG.md | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index 321f8bad3..dcd54f3f9 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -864,10 +864,14 @@ func QueryHandler(qt *querytracer.Tracer, startTime time.Time, at *auth.Token, w } if queryOffset > 0 { for i := range result { - timestamps := result[i].Timestamps + r := &result[i] + // Do not modify r.Timestamps, since they may be shared among multiple series. + // Make a copy instead. + timestamps := append([]int64{}, r.Timestamps...) for j := range timestamps { timestamps[j] += queryOffset } + r.Timestamps = timestamps } } @@ -1011,7 +1015,9 @@ func removeEmptyValuesAndTimeseries(tss []netstorage.Result) []netstorage.Result // Slow path: remove NaNs. srcTimestamps := ts.Timestamps dstValues := ts.Values[:0] - dstTimestamps := ts.Timestamps[:0] + // Do not re-use ts.Timestamps for dstTimestamps, since ts.Timestamps + // may be shared among multiple time series. + dstTimestamps := make([]int64{}, 0, len(ts.Timestamps)) for j, v := range ts.Values { if math.IsNaN(v) { continue diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 5472452ea..6568f5fe5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -16,6 +16,9 @@ The following tip changes can be tested by building VictoriaMetrics components f ## tip +* BUGFIX: return correct query results over time series with gaps. The issue has been introduced in [v1.86.0](https://docs.victoriametrics.com/CHANGELOG.html#v1860). + + ## [v1.86.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.86.0) Released at 2023-01-10