@@ -37,13 +37,14 @@ type Distributor interface {
3737 MetricsMetadata (ctx context.Context ) ([]scrape.MetricMetadata , error )
3838}
3939
40- func newDistributorQueryable (distributor Distributor , streaming bool , streamingMetdata bool , iteratorFn chunkIteratorFunc , queryIngestersWithin time.Duration ) QueryableWithFilter {
40+ func newDistributorQueryable (distributor Distributor , streaming bool , streamingMetdata bool , iteratorFn chunkIteratorFunc , queryIngestersWithin time.Duration , queryStoreForLabels bool ) QueryableWithFilter {
4141 return distributorQueryable {
4242 distributor : distributor ,
4343 streaming : streaming ,
4444 streamingMetdata : streamingMetdata ,
4545 iteratorFn : iteratorFn ,
4646 queryIngestersWithin : queryIngestersWithin ,
47+ queryStoreForLabels : queryStoreForLabels ,
4748 }
4849}
4950
@@ -53,6 +54,7 @@ type distributorQueryable struct {
5354 streamingMetdata bool
5455 iteratorFn chunkIteratorFunc
5556 queryIngestersWithin time.Duration
57+ queryStoreForLabels bool
5658}
5759
5860func (d distributorQueryable ) Querier (ctx context.Context , mint , maxt int64 ) (storage.Querier , error ) {
@@ -65,6 +67,7 @@ func (d distributorQueryable) Querier(ctx context.Context, mint, maxt int64) (st
6567 streamingMetadata : d .streamingMetdata ,
6668 chunkIterFn : d .iteratorFn ,
6769 queryIngestersWithin : d .queryIngestersWithin ,
70+ queryStoreForLabels : d .queryStoreForLabels ,
6871 }, nil
6972}
7073
@@ -81,6 +84,7 @@ type distributorQuerier struct {
8184 streamingMetadata bool
8285 chunkIterFn chunkIteratorFunc
8386 queryIngestersWithin time.Duration
87+ queryStoreForLabels bool
8488}
8589
8690// Select implements storage.Querier interface.
@@ -94,36 +98,20 @@ func (q *distributorQuerier) Select(sortSeries bool, sp *storage.SelectHints, ma
9498 minT , maxT = sp .Start , sp .End
9599 }
96100
97- // If the querier receives a 'series' query, it means only metadata is needed.
98- // For this specific case we shouldn't apply the queryIngestersWithin
99- // time range manipulation, otherwise we'll end up returning no series at all for
100- // older time ranges (while in Cortex we do ignore the start/end and always return
101- // series in ingesters).
102- // Also, in the recent versions of Prometheus, we pass in the hint but with Func set to "series".
103- // See: https://github.com/prometheus/prometheus/pull/8050
104- if sp != nil && sp .Func == "series" {
105- var (
106- ms []metric.Metric
107- err error
108- )
109-
110- if q .streamingMetadata {
111- ms , err = q .distributor .MetricsForLabelMatchersStream (ctx , model .Time (minT ), model .Time (maxT ), matchers ... )
112- } else {
113- ms , err = q .distributor .MetricsForLabelMatchers (ctx , model .Time (minT ), model .Time (maxT ), matchers ... )
114- }
115-
116- if err != nil {
117- return storage .ErrSeriesSet (err )
118- }
119- return series .MetricsToSeriesSet (sortSeries , ms )
120- }
121-
122101 // If queryIngestersWithin is enabled, we do manipulate the query mint to query samples up until
123102 // now - queryIngestersWithin, because older time ranges are covered by the storage. This
124103 // optimization is particularly important for the blocks storage where the blocks retention in the
125104 // ingesters could be way higher than queryIngestersWithin.
126105 if q .queryIngestersWithin > 0 {
106+ if sp != nil && sp .Func == "series" && ! q .queryStoreForLabels {
107+ // If the querier receives a 'series' query, it means only metadata is needed.
108+ // For this specific case where we don't query the store for labels
109+ // we shouldn't apply the queryIngestersWithin time range manipulation.
110+ // Otherwise we'll end up returning no series at all for
111+ // older time ranges (while in Cortex we do ignore the start/end and always return
112+ // series in ingesters).
113+ goto SKIP_MINT_MANIPULATION
114+ }
127115 now := time .Now ()
128116 origMinT := minT
129117 minT = math .Max64 (minT , util .TimeToMillis (now .Add (- q .queryIngestersWithin )))
@@ -138,6 +126,27 @@ func (q *distributorQuerier) Select(sortSeries bool, sp *storage.SelectHints, ma
138126 }
139127 }
140128
129+ SKIP_MINT_MANIPULATION:
130+ // In the recent versions of Prometheus, we pass in the hint but with Func set to "series".
131+ // See: https://github.com/prometheus/prometheus/pull/8050
132+ if sp != nil && sp .Func == "series" {
133+ var (
134+ ms []metric.Metric
135+ err error
136+ )
137+
138+ if q .streamingMetadata {
139+ ms , err = q .distributor .MetricsForLabelMatchersStream (ctx , model .Time (minT ), model .Time (maxT ), matchers ... )
140+ } else {
141+ ms , err = q .distributor .MetricsForLabelMatchers (ctx , model .Time (minT ), model .Time (maxT ), matchers ... )
142+ }
143+
144+ if err != nil {
145+ return storage .ErrSeriesSet (err )
146+ }
147+ return series .MetricsToSeriesSet (sortSeries , ms )
148+ }
149+
141150 if q .streaming {
142151 return q .streamingSelect (ctx , sortSeries , minT , maxT , matchers )
143152 }
0 commit comments