Skip to content

Commit

Permalink
pass query context into Queryable's IsApplicable hook (#10451)
Browse files Browse the repository at this point in the history
* pass context into IsApplicable hook

* fill in PR number in Changelog

Signed-off-by: Mauro Stettler <mauro.stettler@gmail.com>

---------

Signed-off-by: Mauro Stettler <mauro.stettler@gmail.com>
  • Loading branch information
replay authored Jan 17, 2025
1 parent a56f564 commit 5769d98
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Grafana Mimir

* [CHANGE] Querier: pass context to queryable `IsApplicable` hook. #10451
* [CHANGE] Distributor: OTLP and push handler replace all non-UTF8 characters with the unicode replacement character `\uFFFD` in error messages before propagating them. #10236
* [CHANGE] Querier: pass query matchers to queryable `IsApplicable` hook. #10256
* [CHANGE] Query-frontend: Add `topic` label to `cortex_ingest_storage_strong_consistency_requests_total`, `cortex_ingest_storage_strong_consistency_failures_total`, and `cortex_ingest_storage_strong_consistency_wait_duration_seconds` metrics. #10220
Expand Down
8 changes: 4 additions & 4 deletions pkg/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, _ ...*labels.Matcher) bool {
IsApplicable: func(_ context.Context, tenantID string, now time.Time, _, queryMaxT int64, _ ...*labels.Matcher) bool {
return ShouldQueryIngesters(limits.QueryIngestersWithin(tenantID), now, queryMaxT)
},
})
Expand Down Expand Up @@ -234,15 +234,15 @@ 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, matchers ...*labels.Matcher) bool
IsApplicable func(ctx context.Context, tenantID string, now time.Time, queryMinT, queryMaxT int64, matchers ...*labels.Matcher) bool
StorageName string
}

func NewStoreGatewayTimeRangeQueryable(q storage.Queryable, querierConfig Config) TimeRangeQueryable {
return TimeRangeQueryable{
Queryable: q,
StorageName: "store-gateway",
IsApplicable: func(_ string, now time.Time, queryMinT, _ int64, _ ...*labels.Matcher) bool {
IsApplicable: func(_ context.Context, _ string, now time.Time, queryMinT, _ int64, _ ...*labels.Matcher) bool {
return ShouldQueryBlockStore(querierConfig.QueryStoreAfter, now, queryMinT)
},
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func (mq multiQuerier) getQueriers(ctx context.Context, matchers ...*labels.Matc

var queriers []storage.Querier
for _, queryable := range mq.queryables {
if queryable.IsApplicable(tenantID, now, mq.minT, mq.maxT, matchers...) {
if queryable.IsApplicable(ctx, tenantID, now, mq.minT, mq.maxT, matchers...) {
q, err := queryable.Querier(mq.minT, mq.maxT)
if err != nil {
return nil, nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, _ ...*labels.Matcher) bool {
IsApplicable: func(_ context.Context, _ string, _ time.Time, _, _ int64, _ ...*labels.Matcher) bool {
return true
},
}
Expand Down

0 comments on commit 5769d98

Please sign in to comment.