Skip to content

Commit 9cdcd16

Browse files
committed
honor mint,maxt if sp is null for other querier implementations
Signed-off-by: Abdurrahman J. Allawala <aallawala1@gmail.com>
1 parent 87d72f1 commit 9cdcd16

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

pkg/querier/chunk_store_queryable.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@ func (q *chunkStoreQuerier) Select(_ bool, sp *storage.SelectHints, matchers ...
4444
return storage.ErrSeriesSet(err)
4545
}
4646

47+
minT, maxT := q.mint, q.maxt
48+
if sp != nil {
49+
minT, maxT = sp.Start, sp.End
50+
}
51+
4752
// We will hit this for /series lookup when -querier.query-store-for-labels-enabled is set.
4853
// If we don't skip here, it'll make /series lookups extremely slow as all the chunks will be loaded.
4954
// That flag is only to be set with blocks storage engine, and this is a protective measure.
50-
if sp == nil || sp.Func == "series" {
55+
if sp != nil && sp.Func == "series" {
5156
return storage.EmptySeriesSet()
5257
}
5358

54-
chunks, err := q.store.Get(q.ctx, userID, model.Time(sp.Start), model.Time(sp.End), matchers...)
59+
chunks, err := q.store.Get(q.ctx, userID, model.Time(minT), model.Time(maxT), matchers...)
5560
if err != nil {
5661
return storage.ErrSeriesSet(err)
5762
}

pkg/querier/distributor_queryable.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,26 @@ func (q *distributorQuerier) Select(_ bool, sp *storage.SelectHints, matchers ..
8383
log, ctx := spanlogger.New(q.ctx, "distributorQuerier.Select")
8484
defer log.Span.Finish()
8585

86-
// Kludge: Prometheus passes nil SelectParams if it is doing a 'series' operation,
87-
// which needs only metadata. For this specific case we shouldn't apply the queryIngestersWithin
86+
minT, maxT := q.mint, q.maxt
87+
if sp != nil {
88+
minT, maxT = sp.Start, sp.End
89+
}
90+
91+
// If the querier receives a 'series' query, it means only metadata is needed.
92+
// For this specific case we shouldn't apply the queryIngestersWithin
8893
// time range manipulation, otherwise we'll end up returning no series at all for
8994
// older time ranges (while in Cortex we do ignore the start/end and always return
9095
// series in ingesters).
9196
// Also, in the recent versions of Prometheus, we pass in the hint but with Func set to "series".
9297
// See: https://github.com/prometheus/prometheus/pull/8050
93-
if sp == nil || sp.Func == "series" {
98+
if sp != nil && sp.Func == "series" {
9499
ms, err := q.distributor.MetricsForLabelMatchers(ctx, model.Time(q.mint), model.Time(q.maxt), matchers...)
95100
if err != nil {
96101
return storage.ErrSeriesSet(err)
97102
}
98103
return series.MetricsToSeriesSet(ms)
99104
}
100105

101-
minT, maxT := sp.Start, sp.End
102-
103106
// If queryIngestersWithin is enabled, we do manipulate the query mint to query samples up until
104107
// now - queryIngestersWithin, because older time ranges are covered by the storage. This
105108
// optimization is particularly important for the blocks storage where the blocks retention in the

pkg/querier/distributor_queryable_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ func TestDistributorQuerier_SelectShouldHonorQueryIngestersWithin(t *testing.T)
126126
querier, err := queryable.Querier(ctx, testData.queryMinT, testData.queryMaxT)
127127
require.NoError(t, err)
128128

129-
// Select hints are not passed by Prometheus when querying /series.
129+
// Select hints are passed by Prometheus when querying /series.
130130
var hints *storage.SelectHints
131-
if !testData.querySeries {
132-
hints = &storage.SelectHints{Start: testData.queryMinT, End: testData.queryMaxT}
131+
if testData.querySeries {
132+
hints = &storage.SelectHints{Func: "series"}
133133
}
134134

135135
seriesSet := querier.Select(true, hints)

pkg/querier/querier.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,18 @@ func (q querier) Select(_ bool, sp *storage.SelectHints, matchers ...*labels.Mat
300300
level.Debug(log).Log("start", util.TimeFromMillis(sp.Start).UTC().String(), "end", util.TimeFromMillis(sp.End).UTC().String(), "step", sp.Step, "matchers", matchers)
301301
}
302302

303-
// If the querier receives a 'series' query, it means only metadata is needed.
304-
// Here we expect that metadataQuerier querier will handle that.
305-
// Also, in the recent versions of Prometheus, we pass in the hint but with Func set to "series".
306-
// See: https://github.com/prometheus/prometheus/pull/8050
307-
if sp != nil && sp.Func == "series" && !q.queryStoreForLabels {
303+
if sp == nil {
304+
// if SelectHints is null, rely on minT, maxT of querier to scope in range for Select stmt
305+
sp = &storage.SelectHints{Start: q.mint, End: q.maxt}
306+
} else if sp.Func == "series" && !q.queryStoreForLabels {
307+
// Else if the querier receives a 'series' query, it means only metadata is needed.
308+
// Here we expect that metadataQuerier querier will handle that.
309+
// Also, in the recent versions of Prometheus, we pass in the hint but with Func set to "series".
310+
// See: https://github.com/prometheus/prometheus/pull/8050
311+
308312
// In this case, the query time range has already been validated when the querier has been
309313
// created.
310314
return q.metadataQuerier.Select(true, sp, matchers...)
311-
} else if sp == nil {
312-
// if SelectHints is null, rely on minT, maxT of querier to scope in range for Select stmt
313-
sp = &storage.SelectHints{Start: q.mint, End: q.maxt}
314315
}
315316

316317
userID, err := tenant.TenantID(ctx)

0 commit comments

Comments
 (0)