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
This commit is contained in:
Aliaksandr Valialkin 2022-11-21 16:46:02 +02:00
parent 67c60dbf86
commit 2d361a834d
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
3 changed files with 13 additions and 0 deletions

View file

@ -2291,6 +2291,16 @@ func TestExecSuccess(t *testing.T) {
resultExpected := []netstorage.Result{r} resultExpected := []netstorage.Result{r}
f(q, resultExpected) 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.Run(`limit_offset NaN`, func(t *testing.T) {
t.Parallel() t.Parallel()
// q returns 3 time series, where foo=3 contains only NaN values // q returns 3 time series, where foo=3 contains only NaN values

View file

@ -1943,6 +1943,8 @@ func transformLimitOffset(tfa *transformFuncArg) ([]*timeseries, error) {
rvs := removeEmptySeries(args[2]) rvs := removeEmptySeries(args[2])
if len(rvs) >= offset { if len(rvs) >= offset {
rvs = rvs[offset:] rvs = rvs[offset:]
} else {
rvs = nil
} }
if len(rvs) > limit { if len(rvs) > limit {
rvs = rvs[:limit] rvs = rvs[:limit]

View file

@ -24,6 +24,7 @@ The following tip changes can be tested by building VictoriaMetrics components f
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): add the ability to hide results of a particular query by clicking the `eye` icon. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3359). * FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): add the ability to hide results of a particular query by clicking the `eye` icon. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3359).
* FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert.html): add default alert list for vmalert's metrics. See [alerts-vmalert.yml](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts-vmalert.yml). * FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert.html): add default alert list for vmalert's metrics. See [alerts-vmalert.yml](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts-vmalert.yml).
* 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: [vmui](https://docs.victoriametrics.com/#vmui): properly display the requested graph on the requested time range when navigating from Prometheus URL in Grafana. * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): properly display the requested graph on the requested time range when navigating from Prometheus URL in Grafana.
* BUGFIX: reduce CPU usage spikes and memory usage spikes under high data ingestion rate introduced in [v1.83.0](https://docs.victoriametrics.com/CHANGELOG.html#v1830). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3343). * BUGFIX: reduce CPU usage spikes and memory usage spikes under high data ingestion rate introduced in [v1.83.0](https://docs.victoriametrics.com/CHANGELOG.html#v1830). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3343).