Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add context cancellation checks on GetSeries #5827

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/querier/distributor_queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (q *distributorQuerier) Select(ctx context.Context, sortSeries bool, sp *st
if err != nil {
return storage.ErrSeriesSet(err)
}
return series.MetricsToSeriesSet(sortSeries, ms)
return series.MetricsToSeriesSet(ctx, sortSeries, ms)
}

return q.streamingSelect(ctx, sortSeries, minT, maxT, matchers)
Expand Down
7 changes: 5 additions & 2 deletions pkg/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (q querier) Select(ctx context.Context, sortSeries bool, sp *storage.Select
// we have all the sets from different sources (chunk from store, chunks from ingesters,
// time series from store and time series from ingesters).
// mergeSeriesSets will return sorted set.
return q.mergeSeriesSets(result)
return q.mergeSeriesSets(ctx, result)
}

// LabelValues implements storage.Querier.
Expand Down Expand Up @@ -553,7 +553,7 @@ func (querier) Close() error {
return nil
}

func (q querier) mergeSeriesSets(sets []storage.SeriesSet) storage.SeriesSet {
func (q querier) mergeSeriesSets(ctx context.Context, sets []storage.SeriesSet) storage.SeriesSet {
// Here we deal with sets that are based on chunks and build single set from them.
// Remaining sets are merged with chunks-based one using storage.NewMergeSeriesSet

Expand All @@ -565,6 +565,9 @@ func (q querier) mergeSeriesSets(sets []storage.SeriesSet) storage.SeriesSet {

// SeriesSet may have some series backed up by chunks, and some not.
for set.Next() {
if ctx.Err() != nil {
return storage.ErrSeriesSet(ctx.Err())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we did something similar and thanos and the perf was ok, right @yeya24 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have something like this when expanding postings. No obvious impact.

s := set.At()

if sc, ok := s.(SeriesWithChunks); ok {
Expand Down
6 changes: 5 additions & 1 deletion pkg/querier/series/series_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package series

import (
"context"
"sort"

"github.com/prometheus/common/model"
Expand Down Expand Up @@ -167,9 +168,12 @@ func MatrixToSeriesSet(sortSeries bool, m model.Matrix) storage.SeriesSet {
}

// MetricsToSeriesSet creates a storage.SeriesSet from a []metric.Metric
func MetricsToSeriesSet(sortSeries bool, ms []metric.Metric) storage.SeriesSet {
func MetricsToSeriesSet(ctx context.Context, sortSeries bool, ms []metric.Metric) storage.SeriesSet {
series := make([]storage.Series, 0, len(ms))
for _, m := range ms {
if ctx.Err() != nil {
return storage.ErrSeriesSet(ctx.Err())
}
series = append(series, &ConcreteSeries{
labels: metricToLabels(m.Metric),
samples: nil,
Expand Down