Skip to content

Commit ab5f25e

Browse files
ctrombleysgap
andauthored
chore: future-proof min and max function names (#1068)
Co-authored-by: Stephen Gappinger <[email protected]>
1 parent 03bee70 commit ab5f25e

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

logreader.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ func (r *LogReader) read(l []byte) (int, error) {
136136
}
137137

138138
// backoff will perform exponential backoff based on the iteration and
139-
// limited by the provided min and max (in milliseconds) durations.
140-
func backoff(min, max float64, iter int) time.Duration {
141-
backoff := math.Pow(2, float64(iter)/5) * min
142-
if backoff > max {
143-
backoff = max
139+
// limited by the provided minimum and maximum (in milliseconds) durations.
140+
func backoff(minimum, maximum float64, iter int) time.Duration {
141+
backoff := math.Pow(2, float64(iter)/5) * minimum
142+
if backoff > maximum {
143+
backoff = maximum
144144
}
145145
return time.Duration(backoff) * time.Millisecond
146146
}

tfe.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -617,36 +617,36 @@ func (c *Client) retryHTTPCheck(ctx context.Context, resp *http.Response, err er
617617

618618
// retryHTTPBackoff provides a generic callback for Client.Backoff which
619619
// will pass through all calls based on the status code of the response.
620-
func (c *Client) retryHTTPBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
620+
func (c *Client) retryHTTPBackoff(minimum, maximum time.Duration, attemptNum int, resp *http.Response) time.Duration {
621621
if c.retryLogHook != nil {
622622
c.retryLogHook(attemptNum, resp)
623623
}
624624

625625
// Use the rate limit backoff function when we are rate limited.
626626
if resp != nil && resp.StatusCode == 429 {
627-
return rateLimitBackoff(min, max, resp)
627+
return rateLimitBackoff(minimum, maximum, resp)
628628
}
629629

630630
// Set custom duration's when we experience a service interruption.
631-
min = 700 * time.Millisecond
632-
max = 900 * time.Millisecond
631+
minimum = 700 * time.Millisecond
632+
maximum = 900 * time.Millisecond
633633

634-
return retryablehttp.LinearJitterBackoff(min, max, attemptNum, resp)
634+
return retryablehttp.LinearJitterBackoff(minimum, maximum, attemptNum, resp)
635635
}
636636

637637
// rateLimitBackoff provides a callback for Client.Backoff which will use the
638638
// X-RateLimit_Reset header to determine the time to wait. We add some jitter
639639
// to prevent a thundering herd.
640640
//
641-
// min and max are mainly used for bounding the jitter that will be added to
641+
// minimum and maximum are mainly used for bounding the jitter that will be added to
642642
// the reset time retrieved from the headers. But if the final wait time is
643-
// less than min, min will be used instead.
644-
func rateLimitBackoff(min, max time.Duration, resp *http.Response) time.Duration {
643+
// less than minimum, minimum will be used instead.
644+
func rateLimitBackoff(minimum, maximum time.Duration, resp *http.Response) time.Duration {
645645
// rnd is used to generate pseudo-random numbers.
646646
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
647647

648648
// First create some jitter bounded by the min and max durations.
649-
jitter := time.Duration(rnd.Float64() * float64(max-min))
649+
jitter := time.Duration(rnd.Float64() * float64(maximum-minimum))
650650

651651
if resp != nil && resp.Header.Get(_headerRateReset) != "" {
652652
v := resp.Header.Get(_headerRateReset)
@@ -655,12 +655,12 @@ func rateLimitBackoff(min, max time.Duration, resp *http.Response) time.Duration
655655
log.Fatal(err)
656656
}
657657
// Only update min if the given time to wait is longer
658-
if reset > 0 && time.Duration(reset*1e9) > min {
659-
min = time.Duration(reset * 1e9)
658+
if reset > 0 && time.Duration(reset*1e9) > minimum {
659+
minimum = time.Duration(reset * 1e9)
660660
}
661661
}
662662

663-
return min + jitter
663+
return minimum + jitter
664664
}
665665

666666
type rawAPIMetadata struct {

0 commit comments

Comments
 (0)