From aa31cc85f5817d78ae41eaa2a70fdc987c71ef37 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 21 Nov 2022 16:46:02 +0200 Subject: [PATCH] app/vmselect/promql: properly return an empty result from limit_offset() if offset exceeds the number of inner time series Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3312 --- app/vmselect/promql/exec_test.go | 10 ++++++++++ app/vmselect/promql/transform.go | 2 ++ docs/CHANGELOG.md | 1 + 3 files changed, 13 insertions(+) diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 8ab1ae8df..6c85d4cfb 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -2290,6 +2290,16 @@ func TestExecSuccess(t *testing.T) { resultExpected := []netstorage.Result{r} f(q, resultExpected) }) + t.Run(`limit_offset(too-big-offset)`, func(t *testing.T) { + t.Parallel() + q := `limit_offset(1, 10, sort_by_label(( + label_set(time()*1, "foo", "y"), + label_set(time()*2, "foo", "a"), + label_set(time()*3, "foo", "x"), + ), "foo"))` + resultExpected := []netstorage.Result{} + f(q, resultExpected) + }) t.Run(`limit_offset NaN`, func(t *testing.T) { t.Parallel() // q returns 3 time series, where foo=3 contains only NaN values diff --git a/app/vmselect/promql/transform.go b/app/vmselect/promql/transform.go index ea87225aa..cec3aac5a 100644 --- a/app/vmselect/promql/transform.go +++ b/app/vmselect/promql/transform.go @@ -1878,6 +1878,8 @@ func transformLimitOffset(tfa *transformFuncArg) ([]*timeseries, error) { rvs := removeEmptySeries(args[2]) if len(rvs) >= offset { rvs = rvs[offset:] + } else { + rvs = nil } if len(rvs) > limit { rvs = rvs[:limit] diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4eac7246f..51464a961 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -15,6 +15,7 @@ The following tip changes can be tested by building VictoriaMetrics components f ## v1.79.x long-time support release (LTS) +* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly return an empty result from [limit_offset](https://docs.victoriametrics.com/MetricsQL.html#limit_offset) if the `offset` arg exceeds the number of inner time series. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3312). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly discover GCE zones when `filter` option is set at [gce_sd_configs](https://docs.victoriametrics.com/sd_configs.html#gce_sd_configs). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3202). ## [v1.79.5](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.79.5)