Skip to content

Commit

Permalink
don't sort get series in ingesters if one matcher set only (#5372)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 authored May 31, 2023
1 parent 6f355d1 commit f62815f
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -1586,30 +1586,36 @@ func (i *Ingester) metricsForLabelMatchersCommon(ctx context.Context, req *clien
}

// Run a query for each matchers set and collect all the results.
var sets []storage.SeriesSet
var (
sets []storage.SeriesSet
mergedSet storage.SeriesSet
)

for _, matchers := range matchersSet {
// Interrupt if the context has been canceled.
if ctx.Err() != nil {
return nil, cleanup, ctx.Err()
}
hints := &storage.SelectHints{
Start: mint,
End: maxt,
Func: "series", // There is no series function, this token is used for lookups that don't need samples.
}
if len(matchersSet) > 1 {
for _, matchers := range matchersSet {
// Interrupt if the context has been canceled.
if ctx.Err() != nil {
return nil, cleanup, ctx.Err()
}

hints := &storage.SelectHints{
Start: mint,
End: maxt,
Func: "series", // There is no series function, this token is used for lookups that don't need samples.
seriesSet := q.Select(true, hints, matchers...)
sets = append(sets, seriesSet)
}

seriesSet := q.Select(true, hints, matchers...)
sets = append(sets, seriesSet)
mergedSet = storage.NewMergeSeriesSet(sets, storage.ChainedSeriesMerge)
} else {
mergedSet = q.Select(false, hints, matchersSet[0]...)
}

// Generate the response merging all series sets.
result := &client.MetricsForLabelMatchersResponse{
Metric: make([]*cortexpb.Metric, 0),
}

mergedSet := storage.NewMergeSeriesSet(sets, storage.ChainedSeriesMerge)
for mergedSet.Next() {
// Interrupt if the context has been canceled.
if ctx.Err() != nil {
Expand Down

0 comments on commit f62815f

Please sign in to comment.