@@ -25,8 +25,8 @@ import (
25
25
"github.com/cortexproject/cortex/pkg/util/spanlogger"
26
26
)
27
27
28
- const retryMinBackoff = 10 * time .Second
29
- const retryMaxBackoff = time .Minute
28
+ const retryMinBackoff = time .Second
29
+ const retryMaxBackoff = 5 * time .Second
30
30
31
31
// Distributor is the read interface to the distributor, made an interface here
32
32
// to reduce package coupling.
@@ -234,13 +234,13 @@ func (q *distributorQuerier) LabelValues(ctx context.Context, name string, hints
234
234
partialDataEnabled := q .partialDataEnabled (ctx )
235
235
236
236
if q .streamingMetadata {
237
- lvs , err = q .labelsWithRetry (func () ([]string , error ) {
237
+ lvs , err = q .labelsWithRetry (ctx , func () ([]string , error ) {
238
238
return q .distributor .LabelValuesForLabelNameStream (ctx , model .Time (q .mint ), model .Time (q .maxt ), model .LabelName (name ), hints , partialDataEnabled , matchers ... )
239
- }, q . ingesterQueryMaxAttempts )
239
+ })
240
240
} else {
241
- lvs , err = q .labelsWithRetry (func () ([]string , error ) {
241
+ lvs , err = q .labelsWithRetry (ctx , func () ([]string , error ) {
242
242
return q .distributor .LabelValuesForLabelName (ctx , model .Time (q .mint ), model .Time (q .maxt ), model .LabelName (name ), hints , partialDataEnabled , matchers ... )
243
- }, q . ingesterQueryMaxAttempts )
243
+ })
244
244
}
245
245
246
246
if partialdata .IsPartialDataError (err ) {
@@ -267,13 +267,13 @@ func (q *distributorQuerier) LabelNames(ctx context.Context, hints *storage.Labe
267
267
)
268
268
269
269
if q .streamingMetadata {
270
- ln , err = q .labelsWithRetry (func () ([]string , error ) {
270
+ ln , err = q .labelsWithRetry (ctx , func () ([]string , error ) {
271
271
return q .distributor .LabelNamesStream (ctx , model .Time (q .mint ), model .Time (q .maxt ), hints , partialDataEnabled , matchers ... )
272
- }, q . ingesterQueryMaxAttempts )
272
+ })
273
273
} else {
274
- ln , err = q .labelsWithRetry (func () ([]string , error ) {
274
+ ln , err = q .labelsWithRetry (ctx , func () ([]string , error ) {
275
275
return q .distributor .LabelNames (ctx , model .Time (q .mint ), model .Time (q .maxt ), hints , partialDataEnabled , matchers ... )
276
- }, q . ingesterQueryMaxAttempts )
276
+ })
277
277
}
278
278
279
279
if partialdata .IsPartialDataError (err ) {
@@ -284,16 +284,24 @@ func (q *distributorQuerier) LabelNames(ctx context.Context, hints *storage.Labe
284
284
return ln , nil , err
285
285
}
286
286
287
- func (q * distributorQuerier ) labelsWithRetry (labelsFunc func () ([]string , error ), retryAttempt int ) ([]string , error ) {
287
+ func (q * distributorQuerier ) labelsWithRetry (ctx context. Context , labelsFunc func () ([]string , error )) ([]string , error ) {
288
288
var result []string
289
289
var err error
290
290
291
- for i := 0 ; i < retryAttempt ; i ++ {
291
+ retries := backoff .New (ctx , backoff.Config {
292
+ MinBackoff : retryMinBackoff ,
293
+ MaxBackoff : retryMaxBackoff ,
294
+ MaxRetries : q .ingesterQueryMaxAttempts ,
295
+ })
296
+
297
+ for retries .Ongoing () {
292
298
result , err = labelsFunc ()
293
299
294
300
if err == nil || ! q .isRetryableError (err ) {
295
301
return result , err
296
302
}
303
+
304
+ retries .Wait ()
297
305
}
298
306
299
307
return result , err
0 commit comments