GetSeries should Select sorted results only if more than one matcher is requested (#11313)

Signed-off-by: Alan Protasio <approtas@amazon.com>

Signed-off-by: Alan Protasio <approtas@amazon.com>
This commit is contained in:
Alan Protasio 2022-09-16 00:40:41 -07:00 committed by GitHub
parent 35d6813963
commit f1a3dbbb6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -768,15 +768,21 @@ func (api *API) series(r *http.Request) (result apiFuncResult) {
End: timestamp.FromTime(end),
Func: "series", // There is no series function, this token is used for lookups that don't need samples.
}
var set storage.SeriesSet
var sets []storage.SeriesSet
for _, mset := range matcherSets {
// We need to sort this select results to merge (deduplicate) the series sets later.
s := q.Select(true, hints, mset...)
sets = append(sets, s)
if len(matcherSets) > 1 {
var sets []storage.SeriesSet
for _, mset := range matcherSets {
// We need to sort this select results to merge (deduplicate) the series sets later.
s := q.Select(true, hints, mset...)
sets = append(sets, s)
}
set = storage.NewMergeSeriesSet(sets, storage.ChainedSeriesMerge)
} else {
// At this point at least one match exists.
set = q.Select(false, hints, matcherSets[0]...)
}
set := storage.NewMergeSeriesSet(sets, storage.ChainedSeriesMerge)
metrics := []labels.Labels{}
for set.Next() {
metrics = append(metrics, set.At().Labels())