@@ -68,6 +68,7 @@ func TestDistributorQuerier_SelectShouldHonorQueryIngestersWithin(t *testing.T)
6868 now := time .Now ()
6969
7070 tests := map [string ]struct {
71+ querySeries bool
7172 queryIngestersWithin time.Duration
7273 queryMinT int64
7374 queryMaxT int64
@@ -102,6 +103,14 @@ func TestDistributorQuerier_SelectShouldHonorQueryIngestersWithin(t *testing.T)
102103 expectedMinT : 0 ,
103104 expectedMaxT : 0 ,
104105 },
106+ "should not manipulate query time range if queryIngestersWithin is enabled and query max time is older, but the query is for /series" : {
107+ querySeries : true ,
108+ queryIngestersWithin : time .Hour ,
109+ queryMinT : util .TimeToMillis (now .Add (- 100 * time .Minute )),
110+ queryMaxT : util .TimeToMillis (now .Add (- 90 * time .Minute )),
111+ expectedMinT : util .TimeToMillis (now .Add (- 100 * time .Minute )),
112+ expectedMaxT : util .TimeToMillis (now .Add (- 90 * time .Minute )),
113+ },
105114 }
106115
107116 for _ , streamingEnabled := range []bool {false , true } {
@@ -110,13 +119,20 @@ func TestDistributorQuerier_SelectShouldHonorQueryIngestersWithin(t *testing.T)
110119 distributor := & mockDistributor {}
111120 distributor .On ("Query" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (model.Matrix {}, nil )
112121 distributor .On ("QueryStream" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (& client.QueryStreamResponse {}, nil )
122+ distributor .On ("MetricsForLabelMatchers" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return ([]metric.Metric {}, nil )
113123
114124 ctx := user .InjectOrgID (context .Background (), "test" )
115125 queryable := newDistributorQueryable (distributor , streamingEnabled , nil , testData .queryIngestersWithin )
116126 querier , err := queryable .Querier (ctx , testData .queryMinT , testData .queryMaxT )
117127 require .NoError (t , err )
118128
119- seriesSet := querier .Select (true , & storage.SelectHints {Start : testData .queryMinT , End : testData .queryMaxT })
129+ // Select hints are not passed by Prometheus when querying /series.
130+ var hints * storage.SelectHints
131+ if ! testData .querySeries {
132+ hints = & storage.SelectHints {Start : testData .queryMinT , End : testData .queryMaxT }
133+ }
134+
135+ seriesSet := querier .Select (true , hints )
120136 require .NoError (t , seriesSet .Err ())
121137
122138 if testData .expectedMinT == 0 && testData .expectedMaxT == 0 {
@@ -216,8 +232,9 @@ func (m *mockDistributor) LabelValuesForLabelName(context.Context, model.LabelNa
216232func (m * mockDistributor ) LabelNames (context.Context ) ([]string , error ) {
217233 return nil , nil
218234}
219- func (m * mockDistributor ) MetricsForLabelMatchers (ctx context.Context , from , through model.Time , matchers ... * labels.Matcher ) ([]metric.Metric , error ) {
220- return nil , nil
235+ func (m * mockDistributor ) MetricsForLabelMatchers (ctx context.Context , from , to model.Time , matchers ... * labels.Matcher ) ([]metric.Metric , error ) {
236+ args := m .Called (ctx , from , to , matchers )
237+ return args .Get (0 ).([]metric.Metric ), args .Error (1 )
221238}
222239
223240func (m * mockDistributor ) MetricsMetadata (ctx context.Context ) ([]scrape.MetricMetadata , error ) {
0 commit comments