@@ -4,14 +4,29 @@ import (
44 "context"
55 "fmt"
66 "net/http"
7+ "time"
78
9+ "github.com/hashicorp/go-retryablehttp"
810 "github.com/overmindtech/cli/auth"
911 "github.com/overmindtech/cli/sdp-go"
1012 "github.com/overmindtech/cli/sdp-go/sdpconnect"
1113 log "github.com/sirupsen/logrus"
1214 "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
1315)
1416
17+ // newRetryableHTTPClient creates a new HTTP client that uses standard retryablehttp settings
18+ func newRetryableHTTPClient () * http.Client {
19+ retryableClient := & retryablehttp.Client {
20+ HTTPClient : otelhttp .DefaultClient ,
21+ RetryWaitMin : 1 * time .Second ,
22+ RetryWaitMax : 10 * time .Second ,
23+ RetryMax : 5 ,
24+ CheckRetry : retryablehttp .DefaultRetryPolicy ,
25+ Backoff : retryablehttp .DefaultBackoff ,
26+ }
27+ return retryableClient .StandardClient ()
28+ }
29+
1530// UnauthenticatedApiKeyClient Returns an apikey client with otel instrumentation
1631// but no authentication. Can only be used for ExchangeKeyForToken
1732func UnauthenticatedApiKeyClient (ctx context.Context , oi sdp.OvermindInstance ) sdpconnect.ApiKeyServiceClient {
@@ -22,53 +37,53 @@ func UnauthenticatedApiKeyClient(ctx context.Context, oi sdp.OvermindInstance) s
2237// AuthenticatedBookmarkClient Returns a bookmark client that uses the auth
2338// embedded in the context and otel instrumentation
2439func AuthenticatedBookmarkClient (ctx context.Context , oi sdp.OvermindInstance ) sdpconnect.BookmarksServiceClient {
25- httpClient := NewAuthenticatedClient (ctx , otelhttp . DefaultClient )
40+ httpClient := NewAuthenticatedClient (ctx , newRetryableHTTPClient () )
2641 log .WithContext (ctx ).WithField ("apiUrl" , oi .ApiUrl ).Debug ("Connecting to overmind bookmark API" )
2742 return sdpconnect .NewBookmarksServiceClient (httpClient , oi .ApiUrl .String ())
2843}
2944
3045// AuthenticatedChangesClient Returns a changes client that uses the auth
3146// embedded in the context and otel instrumentation
3247func AuthenticatedChangesClient (ctx context.Context , oi sdp.OvermindInstance ) sdpconnect.ChangesServiceClient {
33- httpClient := NewAuthenticatedClient (ctx , otelhttp . DefaultClient )
48+ httpClient := NewAuthenticatedClient (ctx , newRetryableHTTPClient () )
3449 log .WithContext (ctx ).WithField ("apiUrl" , oi .ApiUrl ).Debug ("Connecting to overmind changes API" )
3550 return sdpconnect .NewChangesServiceClient (httpClient , oi .ApiUrl .String ())
3651}
3752
3853// AuthenticatedConfigurationClient Returns a config client that uses the auth
3954// embedded in the context and otel instrumentation
4055func AuthenticatedConfigurationClient (ctx context.Context , oi sdp.OvermindInstance ) sdpconnect.ConfigurationServiceClient {
41- httpClient := NewAuthenticatedClient (ctx , otelhttp . DefaultClient )
56+ httpClient := NewAuthenticatedClient (ctx , newRetryableHTTPClient () )
4257 log .WithContext (ctx ).WithField ("apiUrl" , oi .ApiUrl ).Debug ("Connecting to overmind configuration API" )
4358 return sdpconnect .NewConfigurationServiceClient (httpClient , oi .ApiUrl .String ())
4459}
4560
4661// AuthenticatedManagementClient Returns a management client that uses the auth
4762// embedded in the context and otel instrumentation
4863func AuthenticatedManagementClient (ctx context.Context , oi sdp.OvermindInstance ) sdpconnect.ManagementServiceClient {
49- httpClient := NewAuthenticatedClient (ctx , otelhttp . DefaultClient )
64+ httpClient := NewAuthenticatedClient (ctx , newRetryableHTTPClient () )
5065 log .WithContext (ctx ).WithField ("apiUrl" , oi .ApiUrl ).Debug ("Connecting to overmind management API" )
5166 return sdpconnect .NewManagementServiceClient (httpClient , oi .ApiUrl .String ())
5267}
5368
5469// AuthenticatedSnapshotsClient Returns a Snapshots client that uses the auth
5570// embedded in the context and otel instrumentation
5671func AuthenticatedSnapshotsClient (ctx context.Context , oi sdp.OvermindInstance ) sdpconnect.SnapshotsServiceClient {
57- httpClient := NewAuthenticatedClient (ctx , otelhttp . DefaultClient )
72+ httpClient := NewAuthenticatedClient (ctx , newRetryableHTTPClient () )
5873 log .WithContext (ctx ).WithField ("apiUrl" , oi .ApiUrl ).Debug ("Connecting to overmind snapshot API" )
5974 return sdpconnect .NewSnapshotsServiceClient (httpClient , oi .ApiUrl .String ())
6075}
6176
6277// AuthenticatedInviteClient Returns a Invite client that uses the auth
6378// embedded in the context and otel instrumentation
6479func AuthenticatedInviteClient (ctx context.Context , oi sdp.OvermindInstance ) sdpconnect.InviteServiceClient {
65- httpClient := NewAuthenticatedClient (ctx , otelhttp . DefaultClient )
80+ httpClient := NewAuthenticatedClient (ctx , newRetryableHTTPClient () )
6681 log .WithContext (ctx ).WithField ("apiUrl" , oi .ApiUrl ).Debug ("Connecting to overmind invite API" )
6782 return sdpconnect .NewInviteServiceClient (httpClient , oi .ApiUrl .String ())
6883}
6984
7085func AuthenticatedSignalsClient (ctx context.Context , oi sdp.OvermindInstance ) sdpconnect.SignalServiceClient {
71- httpClient := NewAuthenticatedClient (ctx , otelhttp . DefaultClient )
86+ httpClient := NewAuthenticatedClient (ctx , newRetryableHTTPClient () )
7287 log .WithContext (ctx ).WithField ("apiUrl" , oi .ApiUrl ).Debug ("Connecting to overmind signals API" )
7388 return sdpconnect .NewSignalServiceClient (httpClient , oi .ApiUrl .String ())
7489}
0 commit comments