Skip to content

Commit 761741f

Browse files
committed
Fix test
Signed-off-by: Justin Jung <[email protected]>
1 parent 23cf005 commit 761741f

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

pkg/querier/distributor_queryable.go

+20-12
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
"github.com/cortexproject/cortex/pkg/util/spanlogger"
2626
)
2727

28-
const retryMinBackoff = 10 * time.Second
29-
const retryMaxBackoff = time.Minute
28+
const retryMinBackoff = time.Second
29+
const retryMaxBackoff = 5 * time.Second
3030

3131
// Distributor is the read interface to the distributor, made an interface here
3232
// to reduce package coupling.
@@ -234,13 +234,13 @@ func (q *distributorQuerier) LabelValues(ctx context.Context, name string, hints
234234
partialDataEnabled := q.partialDataEnabled(ctx)
235235

236236
if q.streamingMetadata {
237-
lvs, err = q.labelsWithRetry(func() ([]string, error) {
237+
lvs, err = q.labelsWithRetry(ctx, func() ([]string, error) {
238238
return q.distributor.LabelValuesForLabelNameStream(ctx, model.Time(q.mint), model.Time(q.maxt), model.LabelName(name), hints, partialDataEnabled, matchers...)
239-
}, q.ingesterQueryMaxAttempts)
239+
})
240240
} else {
241-
lvs, err = q.labelsWithRetry(func() ([]string, error) {
241+
lvs, err = q.labelsWithRetry(ctx, func() ([]string, error) {
242242
return q.distributor.LabelValuesForLabelName(ctx, model.Time(q.mint), model.Time(q.maxt), model.LabelName(name), hints, partialDataEnabled, matchers...)
243-
}, q.ingesterQueryMaxAttempts)
243+
})
244244
}
245245

246246
if partialdata.IsPartialDataError(err) {
@@ -267,13 +267,13 @@ func (q *distributorQuerier) LabelNames(ctx context.Context, hints *storage.Labe
267267
)
268268

269269
if q.streamingMetadata {
270-
ln, err = q.labelsWithRetry(func() ([]string, error) {
270+
ln, err = q.labelsWithRetry(ctx, func() ([]string, error) {
271271
return q.distributor.LabelNamesStream(ctx, model.Time(q.mint), model.Time(q.maxt), hints, partialDataEnabled, matchers...)
272-
}, q.ingesterQueryMaxAttempts)
272+
})
273273
} else {
274-
ln, err = q.labelsWithRetry(func() ([]string, error) {
274+
ln, err = q.labelsWithRetry(ctx, func() ([]string, error) {
275275
return q.distributor.LabelNames(ctx, model.Time(q.mint), model.Time(q.maxt), hints, partialDataEnabled, matchers...)
276-
}, q.ingesterQueryMaxAttempts)
276+
})
277277
}
278278

279279
if partialdata.IsPartialDataError(err) {
@@ -284,16 +284,24 @@ func (q *distributorQuerier) LabelNames(ctx context.Context, hints *storage.Labe
284284
return ln, nil, err
285285
}
286286

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) {
288288
var result []string
289289
var err error
290290

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() {
292298
result, err = labelsFunc()
293299

294300
if err == nil || !q.isRetryableError(err) {
295301
return result, err
296302
}
303+
304+
retries.Wait()
297305
}
298306

299307
return result, err

0 commit comments

Comments
 (0)