Skip to content

Commit 7ac6274

Browse files
committed
Merge remote-tracking branch 'remotes/origin/master' into gcp_typo
2 parents 7cb0279 + 327851d commit 7ac6274

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ BUG FIXES:
55
* sumologic_cse_log_mapping split_index as int (GH-333)
66
* Gcp Metrics Source (GH-329, 332)
77

8+
ENHANCEMENTS:
9+
10+
* Add backoff on http 429s (GH-338)
11+
812
## 2.11.5 (December 14, 2021)
913

1014
BUG FIXES:

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/go-errors/errors v1.4.0
1010
github.com/go-test/deep v1.0.7 // indirect
1111
github.com/hashicorp/go-hclog v0.16.2 // indirect
12+
github.com/hashicorp/go-retryablehttp v0.7.0
1213
github.com/hashicorp/go-uuid v1.0.2 // indirect
1314
github.com/hashicorp/hcl v1.0.0 // indirect
1415
github.com/hashicorp/terraform-config-inspect v0.0.0-20210625153042-09f34846faab // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uP
224224
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
225225
github.com/hashicorp/go-plugin v1.3.0 h1:4d/wJojzvHV1I4i/rrjVaeuyxWrLzDE1mDCyDy8fXS8=
226226
github.com/hashicorp/go-plugin v1.3.0/go.mod h1:F9eH4LrE/ZsRdbwhfjs9k9HoDUwAHnYtXdgmf1AVNs0=
227+
github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4=
228+
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
227229
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
228230
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
229231
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=

sumologic/sumologic_client.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sumologic
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/json"
67
"errors"
78
"fmt"
@@ -10,6 +11,8 @@ import (
1011
"net/http"
1112
"net/url"
1213
"time"
14+
15+
"github.com/hashicorp/go-retryablehttp"
1316
)
1417

1518
type HttpClient interface {
@@ -298,12 +301,24 @@ func (s *Client) Delete(urlPath string) ([]byte, error) {
298301
return d, nil
299302
}
300303

304+
func checkRetry(ctx context.Context, resp *http.Response, err error) (bool, error) {
305+
// only retry on 429
306+
if err == nil && resp.StatusCode == http.StatusTooManyRequests {
307+
return true, nil
308+
}
309+
return false, nil
310+
}
311+
301312
func NewClient(accessID, accessKey, authJwt, environment, base_url string, admin bool) (*Client, error) {
313+
retryClient := retryablehttp.NewClient()
314+
retryClient.RetryMax = 10
315+
retryClient.CheckRetry = checkRetry
316+
302317
client := Client{
303318
AccessID: accessID,
304319
AccessKey: accessKey,
305320
AuthJwt: authJwt,
306-
httpClient: http.DefaultClient,
321+
httpClient: retryClient.StandardClient(),
307322
Environment: environment,
308323
IsInAdminMode: admin,
309324
}

0 commit comments

Comments
 (0)