From 3e304890a685515c4231b37f0b4404e59d3226dc Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 27 Jan 2020 18:03:43 +0200 Subject: [PATCH] app/vmselect/promql: fix panic on a single zero vmrange bucket in prometheus_buckets() function Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/296 --- app/vmselect/promql/exec_test.go | 17 +++++++++++++++++ app/vmselect/promql/transform.go | 1 + 2 files changed, 18 insertions(+) diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 0ddb46d6b5..35d3cdde71 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -2964,6 +2964,23 @@ func TestExecSuccess(t *testing.T) { resultExpected := []netstorage.Result{r1, r2, r3, r4, r5, r6} f(q, resultExpected) }) + t.Run(`prometheus_buckets(zero-vmrange-value)`, func(t *testing.T) { + t.Parallel() + q := `sort(prometheus_buckets(label_set(0, "vmrange", "0...0")))` + r1 := netstorage.Result{ + MetricName: metricNameExpected, + Values: []float64{0, 0, 0, 0, 0, 0}, + Timestamps: timestampsExpected, + } + r1.MetricName.Tags = []storage.Tag{ + { + Key: []byte("le"), + Value: []byte("+Inf"), + }, + } + resultsExpected := []netstorage.Result{r1} + f(q, resultsExpected) + }) t.Run(`prometheus_buckets(valid)`, func(t *testing.T) { t.Parallel() q := `sort(prometheus_buckets(( diff --git a/app/vmselect/promql/transform.go b/app/vmselect/promql/transform.go index 9801e757c0..065b521f63 100644 --- a/app/vmselect/promql/transform.go +++ b/app/vmselect/promql/transform.go @@ -363,6 +363,7 @@ func vmrangeBucketsToLE(tss []*timeseries) []*timeseries { ts := xs.ts if isZeroTS(ts) { // Skip time series with zeros. They are substituted by xssNew below. + xsPrev = xs continue } if xs.start != xsPrev.end {