Skip to content

Commit 5349a01

Browse files
committed
Add jitter to backoff time
1 parent 13168ae commit 5349a01

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

exporters/otlp/otlphttp/driver.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,17 @@ func (d *driver) getScheme() string {
208208

209209
func getWaitDuration(backoff time.Duration, i int) time.Duration {
210210
// Strategy: after nth failed attempt, attempt resending after
211-
// k * initialBackoff, where k is a random number in range [0,
212-
// 2^n-1).
211+
// k * initialBackoff + jitter, where k is a random number in
212+
// range [0, 2^n-1), and jitter is a random percentage of
213+
// initialBackoff from [-10%, 10%).
213214

214215
// There won't be an overflow, since i is capped to
215216
// DefaultMaxAttempts (5).
216217
upperK := (int64)(1) << (i + 1)
218+
jitterPercent := (rand.Float64() - 0.5) / 10.
219+
jitter := jitterPercent * (float64)(backoff)
217220
k := rand.Int63n(upperK)
218-
return backoff * time.Duration(k)
221+
return (time.Duration)(k)*backoff + (time.Duration)(jitter)
219222
}
220223

221224
func (d *driver) contextWithStop(ctx context.Context) (context.Context, context.CancelFunc) {

0 commit comments

Comments
 (0)