Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add godo's rate limiter configuration & retryable http client #546 #967

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
configs: completely disable retryable client when max retries is 0
  • Loading branch information
DanielHLelis committed Apr 6, 2023
commit 0bb19f11ff300dbc0f4f9e1d785d36d779cddb1d
27 changes: 17 additions & 10 deletions digitalocean/config/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package config

import (
"context"
"fmt"
"html/template"
"log"
"net/http"
"net/url"
"strings"
"time"
Expand Down Expand Up @@ -72,16 +74,21 @@ func (c *Config) Client() (*CombinedConfig, error) {
})

userAgent := fmt.Sprintf("Terraform/%s", c.TerraformVersion)

retryableClient := retryablehttp.NewClient()
retryableClient.RetryMax = c.HTTPRetryMax
retryableClient.RetryWaitMin = time.Duration(c.HTTPRetryWaitMin * float64(time.Second))
retryableClient.RetryWaitMax = time.Duration(c.HTTPRetryWaitMax * float64(time.Second))

client := retryableClient.StandardClient()
client.Transport = &oauth2.Transport{
Base: client.Transport,
Source: oauth2.ReuseTokenSource(nil, tokenSrc),
var client *http.Client

if c.HTTPRetryMax > 0 {
retryableClient := retryablehttp.NewClient()
retryableClient.RetryMax = c.HTTPRetryMax
retryableClient.RetryWaitMin = time.Duration(c.HTTPRetryWaitMin * float64(time.Second))
retryableClient.RetryWaitMax = time.Duration(c.HTTPRetryWaitMax * float64(time.Second))

client = retryableClient.StandardClient()
client.Transport = &oauth2.Transport{
Base: client.Transport,
Source: oauth2.ReuseTokenSource(nil, tokenSrc),
}
} else {
client = oauth2.NewClient(context.Background(), tokenSrc)
}

client.Transport = logging.NewTransport("DigitalOcean", client.Transport)
Expand Down