@@ -37,13 +37,14 @@ type Distributor interface {
37
37
MetricsMetadata (ctx context.Context ) ([]scrape.MetricMetadata , error )
38
38
}
39
39
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 {
41
41
return distributorQueryable {
42
42
distributor : distributor ,
43
43
streaming : streaming ,
44
44
streamingMetdata : streamingMetdata ,
45
45
iteratorFn : iteratorFn ,
46
46
queryIngestersWithin : queryIngestersWithin ,
47
+ queryStoreForLabels : queryStoreForLabels ,
47
48
}
48
49
}
49
50
@@ -53,6 +54,7 @@ type distributorQueryable struct {
53
54
streamingMetdata bool
54
55
iteratorFn chunkIteratorFunc
55
56
queryIngestersWithin time.Duration
57
+ queryStoreForLabels bool
56
58
}
57
59
58
60
func (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
65
67
streamingMetadata : d .streamingMetdata ,
66
68
chunkIterFn : d .iteratorFn ,
67
69
queryIngestersWithin : d .queryIngestersWithin ,
70
+ queryStoreForLabels : d .queryStoreForLabels ,
68
71
}, nil
69
72
}
70
73
@@ -81,6 +84,7 @@ type distributorQuerier struct {
81
84
streamingMetadata bool
82
85
chunkIterFn chunkIteratorFunc
83
86
queryIngestersWithin time.Duration
87
+ queryStoreForLabels bool
84
88
}
85
89
86
90
// Select implements storage.Querier interface.
@@ -94,36 +98,20 @@ func (q *distributorQuerier) Select(sortSeries bool, sp *storage.SelectHints, ma
94
98
minT , maxT = sp .Start , sp .End
95
99
}
96
100
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
-
122
101
// If queryIngestersWithin is enabled, we do manipulate the query mint to query samples up until
123
102
// now - queryIngestersWithin, because older time ranges are covered by the storage. This
124
103
// optimization is particularly important for the blocks storage where the blocks retention in the
125
104
// ingesters could be way higher than queryIngestersWithin.
126
105
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
+ }
127
115
now := time .Now ()
128
116
origMinT := minT
129
117
minT = math .Max64 (minT , util .TimeToMillis (now .Add (- q .queryIngestersWithin )))
@@ -138,6 +126,27 @@ func (q *distributorQuerier) Select(sortSeries bool, sp *storage.SelectHints, ma
138
126
}
139
127
}
140
128
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
+
141
150
if q .streaming {
142
151
return q .streamingSelect (ctx , sortSeries , minT , maxT , matchers )
143
152
}
0 commit comments