Skip to content

Commit 35df002

Browse files
committed
fix: back to retryablehttp lib for http client
1 parent 98e2530 commit 35df002

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.1
1111
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.4
1212
github.com/google/go-cmp v0.7.0
13+
github.com/hashicorp/go-retryablehttp v0.7.8
1314
github.com/p2p-b2b/httpretrier v0.0.3
1415
github.com/pkg/errors v0.9.1
1516
github.com/spf13/cobra v1.10.1
@@ -50,6 +51,7 @@ require (
5051
github.com/google/uuid v1.6.0 // indirect
5152
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
5253
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
54+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
5355
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5456
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
5557
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect

go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ github.com/aws/smithy-go v1.23.0/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp
4747
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
4848
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
4949
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
50+
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
51+
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
5052
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
5153
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
5254
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
@@ -72,12 +74,22 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.6 h1:GW/XbdyBFQ8Qe+YAmFU
7274
github.com/googleapis/enterprise-certificate-proxy v0.3.6/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA=
7375
github.com/googleapis/gax-go/v2 v2.15.0 h1:SyjDc1mGgZU5LncH8gimWo9lW1DtIfPibOG81vgd/bo=
7476
github.com/googleapis/gax-go/v2 v2.15.0/go.mod h1:zVVkkxAQHa1RQpg9z2AUCMnKhi0Qld9rcmyfL1OZhoc=
77+
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
78+
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
79+
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
80+
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
81+
github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48=
82+
github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw=
7583
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
7684
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
7785
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
7886
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
7987
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
8088
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
89+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
90+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
91+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
92+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
8193
github.com/p2p-b2b/httpretrier v0.0.3 h1:6Udp+5zuzgBZ6Hu5Es4/dKWHv8pzRSvXCHXRjYJTgNU=
8294
github.com/p2p-b2b/httpretrier v0.0.3/go.mod h1:J/aV00SornLs70X/DY3B4IPkDjICynXLfA/TWpAlErw=
8395
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=

internal/scim/scim.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ func (s *Provider) GetGroupsMembersBruteForce(ctx context.Context, gr *model.Gro
533533
user := user
534534

535535
g.Go(func() error {
536-
// add random delay between 10-200 milliseconds to gap API calls
537-
delay := time.Duration(rand.Intn(190)+10) * time.Millisecond
536+
// add random delay between 10-150 milliseconds to gap API calls
537+
delay := time.Duration(rand.Intn(140)+10) * time.Millisecond
538538
time.Sleep(delay)
539539

540540
// https://docs.aws.amazon.com/singlesignon/latest/developerguide/listgroups.html

internal/setup/setup.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/aws/aws-sdk-go-v2/service/s3"
1313
"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
14-
"github.com/p2p-b2b/httpretrier"
14+
"github.com/hashicorp/go-retryablehttp"
1515
"github.com/pkg/errors"
1616
"github.com/slashdevops/idp-scim-sync/internal/config"
1717
"github.com/slashdevops/idp-scim-sync/internal/core"
@@ -216,16 +216,15 @@ func SyncService(ctx context.Context, cfg *config.Config) (*core.SyncService, er
216216
gwsServiceAccountContent = gwsServiceAccount
217217
}
218218

219-
idpClient := httpretrier.NewClientBuilder().
220-
WithTimeout(30 * time.Second). // Overall request timeout
221-
WithMaxRetries(5). // Retry up to 3 times
222-
WithRetryStrategy(httpretrier.JitterBackoffStrategy). // Use jitter backoff to avoid thundering herd
223-
WithRetryBaseDelay(500 * time.Millisecond). // Start with 500ms delay (httpretrier default)
224-
WithRetryMaxDelay(5 * time.Second). // Cap at 5 seconds
225-
WithMaxIdleConns(10). // Max idle connections
226-
WithMaxIdleConnsPerHost(10). // Max idle connections per host
227-
WithIdleConnTimeout(90 * time.Second). // Idle connection timeout
228-
Build()
219+
idpClient := retryablehttp.NewClient()
220+
idpClient.RetryMax = 5
221+
idpClient.RetryWaitMin = time.Millisecond * 200
222+
// set the logger only in debug mode
223+
if cfg.Debug {
224+
idpClient.Logger = slog.Default()
225+
} else {
226+
idpClient.Logger = nil
227+
}
229228

230229
userAgent := fmt.Sprintf("idp-scim-sync/%s", version.Version)
231230

@@ -234,7 +233,7 @@ func SyncService(ctx context.Context, cfg *config.Config) (*core.SyncService, er
234233
ServiceAccount: gwsServiceAccountContent,
235234
Scopes: cfg.GWSServiceAccountScopes,
236235
UserAgent: userAgent,
237-
Client: idpClient,
236+
Client: idpClient.StandardClient(),
238237
}
239238

240239
// Google Client Service
@@ -257,18 +256,19 @@ func SyncService(ctx context.Context, cfg *config.Config) (*core.SyncService, er
257256

258257
// AWS SCIM Service
259258

260-
scimClient := httpretrier.NewClientBuilder().
261-
WithTimeout(30 * time.Second). // Overall request timeout
262-
WithMaxRetries(10). // Retry up to 3 times
263-
WithRetryStrategy(httpretrier.JitterBackoffStrategy). // Use jitter backoff to avoid thundering herd
264-
WithRetryBaseDelay(500 * time.Millisecond). // Start with 500ms delay (httpretrier default)
265-
WithRetryMaxDelay(10 * time.Second). // Cap at 5 seconds
266-
WithMaxIdleConns(10). // Max idle connections
267-
WithMaxIdleConnsPerHost(10). // Max idle connections per host
268-
WithIdleConnTimeout(90 * time.Second). // Idle connection timeout
269-
Build()
270-
271-
awsSCIM, err := aws.NewSCIMService(scimClient, cfg.AWSSCIMEndpoint, cfg.AWSSCIMAccessToken)
259+
// httpClient
260+
scimClient := retryablehttp.NewClient()
261+
scimClient.RetryMax = 10
262+
scimClient.RetryWaitMin = time.Millisecond * 100
263+
264+
// set the logger only in debug mode
265+
if cfg.Debug {
266+
scimClient.Logger = slog.Default()
267+
} else {
268+
scimClient.Logger = nil
269+
}
270+
271+
awsSCIM, err := aws.NewSCIMService(scimClient.StandardClient(), cfg.AWSSCIMEndpoint, cfg.AWSSCIMAccessToken)
272272
if err != nil {
273273
return nil, errors.Wrap(err, "cannot create aws scim service")
274274
}

0 commit comments

Comments
 (0)