Skip to content

Commit 979b398

Browse files
fix: return fatal on certain error codes during first stream cycle
Signed-off-by: Alexandra Oberaigner <[email protected]>
1 parent d2d49b1 commit 979b398

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

providers/flagd/pkg/configuration.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const (
2727
defaultHost = "localhost"
2828
defaultResolver = rpc
2929
defaultGracePeriod = 5
30+
defaultRetryBackoffMs = 1000
31+
defaultRetryBackoffMaxMs = 120000
3032
defaultFatalStatusCodes = ""
3133

3234
rpc ResolverType = "rpc"
@@ -69,6 +71,8 @@ type ProviderConfiguration struct {
6971
CustomSyncProviderUri string
7072
GrpcDialOptionsOverride []grpc.DialOption
7173
RetryGracePeriod int
74+
RetryBackoffMs int
75+
RetryBackoffMaxMs int
7276
FatalStatusCodes []string
7377

7478
log logr.Logger
@@ -212,12 +216,8 @@ func (cfg *ProviderConfiguration) updateFromEnvVar() {
212216
if targetUri := os.Getenv(flagdTargetUriEnvironmentVariableName); targetUri != "" {
213217
cfg.TargetUri = targetUri
214218
}
215-
if gracePeriod := os.Getenv(flagdGracePeriodVariableName); gracePeriod != "" {
216-
if seconds, err := strconv.Atoi(gracePeriod); err == nil {
217-
cfg.RetryGracePeriod = seconds
218-
cfg.RetryGracePeriod = getIntFromEnvVarOrDefault(flagdGracePeriodVariableName, defaultGracePeriod, cfg.log)
219-
}
220-
}
219+
220+
cfg.RetryGracePeriod = getIntFromEnvVarOrDefault(flagdGracePeriodVariableName, defaultGracePeriod, cfg.log)
221221

222222
var fatalStatusCodes string
223223
if envVal := os.Getenv(flagdFatalStatusCodesVariableName); envVal != "" {
@@ -431,6 +431,20 @@ func WithRetryGracePeriod(gracePeriod int) ProviderOption {
431431
}
432432
}
433433

434+
// WithRetryBackoffMs sets the initial backoff duration (in milliseconds) for retrying failed connections
435+
func WithRetryBackoffMs(retryBackoffMs int) ProviderOption {
436+
return func(p *ProviderConfiguration) {
437+
p.RetryBackoffMs = retryBackoffMs
438+
}
439+
}
440+
441+
// WithRetryBackoffMaxMs sets the maximum backoff duration (in milliseconds) for retrying failed connections
442+
func WithRetryBackoffMaxMs(retryBackoffMaxMs int) ProviderOption {
443+
return func(p *ProviderConfiguration) {
444+
p.RetryBackoffMaxMs = retryBackoffMaxMs
445+
}
446+
}
447+
434448
// WithFatalStatusCodes allows to set a list of gRPC status codes, which will cause streams to give up
435449
// and put the provider in a PROVIDER_FATAL state
436450
func WithFatalStatusCodes(fatalStatusCodes []string) ProviderOption {

providers/flagd/pkg/service/in_process/service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ type Configuration struct {
112112
GrpcDialOptionsOverride []googlegrpc.DialOption
113113
CertificatePath string
114114
RetryGracePeriod int
115+
RetryBackOffMs int
116+
RetryBackOffMaxMs int
115117
FatalStatusCodes []string
116118
}
117119

0 commit comments

Comments
 (0)