From ff18101d305e976b10b32c2d278d3816e8f8a200 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 24 Dec 2019 22:44:24 +0200 Subject: [PATCH] app/vmselect/promql: make sure AdjustStartEnd returns time range covering the same number of points as the initial time range This should prevent from the following panic at app/vmselect/promql/binary_op.go:255: BUG: len(leftVaues) must match len(rightValues) and len(dstValues) --- app/vmselect/promql/eval.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/vmselect/promql/eval.go b/app/vmselect/promql/eval.go index 1c385bc179..3f916be1aa 100644 --- a/app/vmselect/promql/eval.go +++ b/app/vmselect/promql/eval.go @@ -58,6 +58,14 @@ func AdjustStartEnd(start, end, step int64) (int64, int64) { if adjust > 0 { end += step - adjust } + + // Make sure that the new number of points is the same as the initial number of points. + newPoints := (end-start)/step + 1 + for newPoints > points { + end -= step + newPoints-- + } + return start, end } @@ -412,7 +420,12 @@ func evalRollupFunc(ec *EvalConfig, name string, rf rollupFunc, re *rollupExpr, ecNew = newEvalConfig(ec) ecNew.Start -= offset ecNew.End -= offset - ecNew.Start, ecNew.End = AdjustStartEnd(ecNew.Start, ecNew.End, ecNew.Step) + if ecNew.MayCache { + start, end := AdjustStartEnd(ecNew.Start, ecNew.End, ecNew.Step) + offset += ecNew.Start - start + ecNew.Start = start + ecNew.End = end + } } var rvs []*timeseries var err error