Skip to content

Commit

Permalink
Querier: pass query matchers to TimeRangeQueryable.IsApplicable fun…
Browse files Browse the repository at this point in the history
…ction (#10256)

Signed-off-by: Miguel Ángel Ortuño <ortuman@gmail.com>
  • Loading branch information
ortuman authored Dec 16, 2024
1 parent a979e2b commit 9b6bc36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.15.0-rc.0

* [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
* [ENHANCEMENT] Distributor: OTLP receiver now converts also metric metadata. See also https://github.com/prometheus/prometheus/pull/15416. #10168
* [ENHANCEMENT] Distributor: discard float and histogram samples with duplicated timestamps from each timeseries in a request before the request is forwarded to ingesters. Discarded samples are tracked by the `cortex_discarded_samples_total` metrics with reason `sample_duplicate_timestamp`. #10145

Expand Down
16 changes: 8 additions & 8 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) bool {
IsApplicable: func(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) bool
IsApplicable func(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) bool {
IsApplicable: func(_ string, now time.Time, queryMinT, _ int64, _ ...*labels.Matcher) bool {
return ShouldQueryBlockStore(querierConfig.QueryStoreAfter, now, queryMinT)
},
}
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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()
}
Expand Down Expand Up @@ -427,7 +427,7 @@ func clampToMaxLabelQueryLength(spanLog *spanlogger.SpanLogger, startMs, endMs,

// LabelValues implements storage.Querier.
func (mq multiQuerier) LabelValues(ctx context.Context, name string, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
ctx, queriers, err := mq.getQueriers(ctx)
ctx, queriers, err := mq.getQueriers(ctx, matchers...)
if errors.Is(err, errEmptyTimeRange) {
return nil, nil, nil
}
Expand Down Expand Up @@ -472,7 +472,7 @@ func (mq multiQuerier) LabelValues(ctx context.Context, name string, hints *stor
}

func (mq multiQuerier) LabelNames(ctx context.Context, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
ctx, queriers, err := mq.getQueriers(ctx)
ctx, queriers, err := mq.getQueriers(ctx, matchers...)
if errors.Is(err, errEmptyTimeRange) {
return nil, nil, nil
}
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) bool {
IsApplicable: func(_ string, _ time.Time, _, _ int64, _ ...*labels.Matcher) bool {
return true
},
}
Expand Down

0 comments on commit 9b6bc36

Please sign in to comment.