Skip to content

Commit 74d2af2

Browse files
committed
add context cancellation checks on GetSeries
Signed-off-by: Erlan Zholdubai uulu <[email protected]>
1 parent 99d8c3e commit 74d2af2

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

pkg/querier/distributor_queryable.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (q *distributorQuerier) Select(ctx context.Context, sortSeries bool, sp *st
136136
if err != nil {
137137
return storage.ErrSeriesSet(err)
138138
}
139-
return series.MetricsToSeriesSet(sortSeries, ms)
139+
return series.MetricsToSeriesSet(ctx, sortSeries, ms)
140140
}
141141

142142
return q.streamingSelect(ctx, sortSeries, minT, maxT, matchers)

pkg/querier/querier.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (q querier) Select(ctx context.Context, sortSeries bool, sp *storage.Select
437437
// we have all the sets from different sources (chunk from store, chunks from ingesters,
438438
// time series from store and time series from ingesters).
439439
// mergeSeriesSets will return sorted set.
440-
return q.mergeSeriesSets(result)
440+
return q.mergeSeriesSets(ctx, result)
441441
}
442442

443443
// LabelValues implements storage.Querier.
@@ -553,7 +553,7 @@ func (querier) Close() error {
553553
return nil
554554
}
555555

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

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

566566
// SeriesSet may have some series backed up by chunks, and some not.
567567
for set.Next() {
568+
if ctx.Err() != nil {
569+
return storage.ErrSeriesSet(ctx.Err())
570+
}
568571
s := set.At()
569572

570573
if sc, ok := s.(SeriesWithChunks); ok {

pkg/querier/series/series_set.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package series
1818

1919
import (
20+
"context"
2021
"sort"
2122

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

169170
// MetricsToSeriesSet creates a storage.SeriesSet from a []metric.Metric
170-
func MetricsToSeriesSet(sortSeries bool, ms []metric.Metric) storage.SeriesSet {
171+
func MetricsToSeriesSet(ctx context.Context, sortSeries bool, ms []metric.Metric) storage.SeriesSet {
171172
series := make([]storage.Series, 0, len(ms))
172173
for _, m := range ms {
174+
if ctx.Err() != nil {
175+
return storage.ErrSeriesSet(ctx.Err())
176+
}
173177
series = append(series, &ConcreteSeries{
174178
labels: metricToLabels(m.Metric),
175179
samples: nil,

0 commit comments

Comments
 (0)