From add083633222b862e06d8e35ed4166ea816f8ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Ortu=C3=B1o?= Date: Mon, 16 Dec 2024 15:20:05 +0100 Subject: [PATCH] querier: pass matchers to `TimeRangeQueryable.IsApplicable` function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miguel Ángel Ortuño --- pkg/querier/querier.go | 12 ++++++------ pkg/querier/querier_test.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/querier/querier.go b/pkg/querier/querier.go index 8c44c89cf65..e4684888f18 100644 --- a/pkg/querier/querier.go +++ b/pkg/querier/querier.go @@ -138,7 +138,7 @@ func New(cfg Config, limits *validation.Overrides, distributor Distributor, quer queryables = append(queryables, TimeRangeQueryable{ Queryable: NewDistributorQueryable(distributor, limits, queryMetrics, logger), StorageName: "ingester", - IsApplicable: func(tenantID string, now time.Time, _, queryMaxT int64) bool { + IsApplicable: func(tenantID string, now time.Time, _, queryMaxT int64, _ ...*labels.Matcher) bool { return ShouldQueryIngesters(limits.QueryIngestersWithin(tenantID), now, queryMaxT) }, }) @@ -234,7 +234,7 @@ func newQueryable( // TimeRangeQueryable is a Queryable that is aware of when it is applicable. type TimeRangeQueryable struct { storage.Queryable - IsApplicable func(tenantID string, now time.Time, queryMinT, queryMaxT int64) bool + IsApplicable func(tenantID string, now time.Time, queryMinT, queryMaxT int64, matchers ...*labels.Matcher) bool StorageName string } @@ -242,7 +242,7 @@ func NewStoreGatewayTimeRangeQueryable(q storage.Queryable, querierConfig Config return TimeRangeQueryable{ Queryable: q, StorageName: "store-gateway", - IsApplicable: func(_ string, now time.Time, queryMinT, _ int64) bool { + IsApplicable: func(_ string, now time.Time, queryMinT, _ int64, _ ...*labels.Matcher) bool { return ShouldQueryBlockStore(querierConfig.QueryStoreAfter, now, queryMinT) }, } @@ -260,7 +260,7 @@ type multiQuerier struct { logger log.Logger } -func (mq multiQuerier) getQueriers(ctx context.Context) (context.Context, []storage.Querier, error) { +func (mq multiQuerier) getQueriers(ctx context.Context, matchers ...*labels.Matcher) (context.Context, []storage.Querier, error) { now := time.Now() tenantID, err := tenant.TenantID(ctx) @@ -283,7 +283,7 @@ func (mq multiQuerier) getQueriers(ctx context.Context) (context.Context, []stor var queriers []storage.Querier for _, queryable := range mq.queryables { - if queryable.IsApplicable(tenantID, now, mq.minT, mq.maxT) { + if queryable.IsApplicable(tenantID, now, mq.minT, mq.maxT, matchers...) { q, err := queryable.Querier(mq.minT, mq.maxT) if err != nil { return nil, nil, err @@ -303,7 +303,7 @@ func (mq multiQuerier) Select(ctx context.Context, _ bool, sp *storage.SelectHin spanLog, ctx := spanlogger.NewWithLogger(ctx, mq.logger, "querier.Select") defer spanLog.Span.Finish() - ctx, queriers, err := mq.getQueriers(ctx) + ctx, queriers, err := mq.getQueriers(ctx, matchers...) if errors.Is(err, errEmptyTimeRange) { return storage.EmptySeriesSet() } diff --git a/pkg/querier/querier_test.go b/pkg/querier/querier_test.go index 23905d68b1e..35ff3a9b088 100644 --- a/pkg/querier/querier_test.go +++ b/pkg/querier/querier_test.go @@ -231,7 +231,7 @@ func TestQuerier(t *testing.T) { db, through := mockTSDB(t, model.Time(0), int(chunks*samplesPerChunk), sampleRate, chunkOffset, int(samplesPerChunk), q.valueType) dbQueryable := TimeRangeQueryable{ Queryable: db, - IsApplicable: func(_ string, _ time.Time, _, _ int64) bool { + IsApplicable: func(_ string, _ time.Time, _, _ int64, _ ...*labels.Matcher) bool { return true }, }