From c826f0636631088a552629e804ea3c2628a54eeb Mon Sep 17 00:00:00 2001 From: Alan Liang <32037815+Buddruggy@users.noreply.github.com> Date: Mon, 25 Jul 2022 15:49:48 +0800 Subject: [PATCH] vmselect: fix vmrangeBucketsToLE func may panic when ts value equal zero (#2902) Co-authored-by: alanwzliang --- app/vmselect/promql/transform.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/vmselect/promql/transform.go b/app/vmselect/promql/transform.go index c83616dd1..02257cc5c 100644 --- a/app/vmselect/promql/transform.go +++ b/app/vmselect/promql/transform.go @@ -572,19 +572,21 @@ func vmrangeBucketsToLE(tss []*timeseries) []*timeseries { }) } xss = xssNew - for i := range xss[0].ts.Values { - count := float64(0) - for _, xs := range xss { - ts := xs.ts - v := ts.Values[i] - if !math.IsNaN(v) && v > 0 { - count += v + if len(xss) > 0 { + for i := range xss[0].ts.Values { + count := float64(0) + for _, xs := range xss { + ts := xs.ts + v := ts.Values[i] + if !math.IsNaN(v) && v > 0 { + count += v + } + ts.Values[i] = count } - ts.Values[i] = count } - } - for _, xs := range xss { - rvs = append(rvs, xs.ts) + for _, xs := range xss { + rvs = append(rvs, xs.ts) + } } } return rvs