diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 8ed198353..f12fbbda0 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -2757,6 +2757,26 @@ func TestExecSuccess(t *testing.T) { resultExpected := []netstorage.Result{} f(q, resultExpected) }) + t.Run(`histogram_quantile(single-value-inf-le)`, func(t *testing.T) { + t.Parallel() + q := `histogram_quantile(0.6, label_set(100, "le", "+Inf"))` + resultExpected := []netstorage.Result{} + f(q, resultExpected) + }) + t.Run(`histogram_quantile(single-value-inf-le)`, func(t *testing.T) { + t.Parallel() + q := `histogram_quantile(0.6, ( + label_set(100, "le", "+Inf"), + label_set(0, "le", "42"), + ))` + r := netstorage.Result{ + MetricName: metricNameExpected, + Values: []float64{42, 42, 42, 42, 42, 42}, + Timestamps: timestampsExpected, + } + resultExpected := []netstorage.Result{r} + f(q, resultExpected) + }) t.Run(`histogram_quantile(single-value-valid-le)`, func(t *testing.T) { t.Parallel() q := `histogram_quantile(0.6, label_set(100, "le", "200"))` diff --git a/app/vmselect/promql/transform.go b/app/vmselect/promql/transform.go index 6d1b01cbd..20961e409 100644 --- a/app/vmselect/promql/transform.go +++ b/app/vmselect/promql/transform.go @@ -649,14 +649,9 @@ func transformHistogramQuantile(tfa *transformFuncArg) ([]*timeseries, error) { m := groupLeTimeseries(tss) // Calculate quantile for each group in m - lastNonInf := func(i int, xss []leTimeseries) float64 { for len(xss) > 0 { xsLast := xss[len(xss)-1] - v := xsLast.ts.Values[i] - if v == 0 { - return nan - } if !math.IsInf(xsLast.le, 0) { return xsLast.le } @@ -700,8 +695,7 @@ func transformHistogramQuantile(tfa *transformFuncArg) ([]*timeseries, error) { continue } if math.IsInf(le, 0) { - vv := lastNonInf(i, xss) - return vv, vv, inf + break } if v == vPrev { return lePrev, lePrev, v diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a8ddf8c3e..663f6cbed 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -17,6 +17,7 @@ * BUGFIX: vmagent: properly perform graceful shutdown on `SIGINT` and `SIGTERM` signals. The graceful shutdown has been broken in `v1.54.0`. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1065 * BUGFIX: reduce the probability of `duplicate time series` errors when querying Kubernetes metrics. +* BUGFIX: properly calculate `histogram_quantile()` over time series with only a single non-zero bucket with `{le="+Inf"}`. Previously `NaN` was returned, now the value for the last bucket before `{le="+Inf"}` is returned like Prometheus does. # [v1.54.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.54.1)