app/vmselect/promql: consistently return the same set of time series from limitk() function

This is the expected behaviour by most users.
This commit is contained in:
Aliaksandr Valialkin 2021-10-08 19:53:50 +03:00
parent a7a1305395
commit f1e1d20ac4
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
4 changed files with 10 additions and 3 deletions

View File

@ -1010,6 +1010,11 @@ func aggrFuncLimitK(afa *aggrFuncArg) ([]*timeseries, error) {
} }
} }
afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries { afe := func(tss []*timeseries, modifier *metricsql.ModifierExpr) []*timeseries {
// Sort series by metricName in order to get consistent set of output series
// across multiple calls to limitk() function.
sort.Slice(tss, func(i, j int) bool {
return metricNameLess(&tss[i].MetricName, &tss[j].MetricName)
})
if len(tss) > maxK { if len(tss) > maxK {
tss = tss[:maxK] tss = tss[:maxK]
} }

View File

@ -5003,7 +5003,7 @@ func TestExecSuccess(t *testing.T) {
}) })
t.Run(`limitk(1)`, func(t *testing.T) { t.Run(`limitk(1)`, func(t *testing.T) {
t.Parallel() t.Parallel()
q := `limitk(1, label_set(10, "foo", "bar") or label_set(time()/150, "baz", "sss"))` q := `limitk(1, label_set(10, "foo", "bar") or label_set(time()/150, "xbaz", "sss"))`
r1 := netstorage.Result{ r1 := netstorage.Result{
MetricName: metricNameExpected, MetricName: metricNameExpected,
Values: []float64{10, 10, 10, 10, 10, 10}, Values: []float64{10, 10, 10, 10, 10, 10},

View File

@ -6,7 +6,9 @@ sort: 15
## tip ## tip
BUGFIX: vmstorage: fix `unaligned 64-bit atomic operation` panic on 32-bit architectures (arm and 386). The panic has been introduced in v1.67.0 * FEATURE: consistently return the same set of time series from [limitk](https://docs.victoriametrics.com/MetricsQL.html#limitk) function. This improves the usability of periodically refreshed graphs.
* BUGFIX: vmstorage: fix `unaligned 64-bit atomic operation` panic on 32-bit architectures (arm and 386). The panic has been introduced in v1.67.0
## [v1.67.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.67.0) ## [v1.67.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.67.0)

View File

@ -762,7 +762,7 @@ See also [implicit query conversions](#implicit-query-conversions).
#### limitk #### limitk
`limitk(k, q) by (group_labels)` returns up to `k` time series per each `group_labels` out of time series returned by `q`. The returned set of time series can change with each call. `limitk(k, q) by (group_labels)` returns up to `k` time series per each `group_labels` out of time series returned by `q`. The returned set of time series remain the same across calls.
#### mad #### mad