@@ -3,15 +3,14 @@ package flagd
33import (
44 "errors"
55 "fmt"
6- "os"
7- "strconv"
8- "strings"
9-
106 "github.com/go-logr/logr"
117 "github.com/open-feature/flagd/core/pkg/sync"
128 "github.com/open-feature/go-sdk-contrib/providers/flagd/internal/cache"
139 "github.com/open-feature/go-sdk-contrib/providers/flagd/internal/logger"
1410 "google.golang.org/grpc"
11+ "os"
12+ "strconv"
13+ "strings"
1514)
1615
1716type ResolverType string
@@ -26,6 +25,7 @@ const (
2625 defaultCache = cache .LRUValue
2726 defaultHost = "localhost"
2827 defaultResolver = rpc
28+ defaultGracePeriod = 5
2929
3030 rpc ResolverType = "rpc"
3131 inProcess ResolverType = "in-process"
@@ -44,6 +44,7 @@ const (
4444 flagdSourceSelectorEnvironmentVariableName = "FLAGD_SOURCE_SELECTOR"
4545 flagdOfflinePathEnvironmentVariableName = "FLAGD_OFFLINE_FLAG_SOURCE_PATH"
4646 flagdTargetUriEnvironmentVariableName = "FLAGD_TARGET_URI"
47+ flagdGracePeriodVariableName = "FLAGD_RETRY_GRACE_PERIOD"
4748)
4849
4950type ProviderConfiguration struct {
@@ -64,6 +65,7 @@ type ProviderConfiguration struct {
6465 CustomSyncProvider sync.ISync
6566 CustomSyncProviderUri string
6667 GrpcDialOptionsOverride []grpc.DialOption
68+ RetryGracePeriod int
6769
6870 log logr.Logger
6971}
@@ -77,6 +79,7 @@ func newDefaultConfiguration(log logr.Logger) *ProviderConfiguration {
7779 MaxCacheSize : defaultMaxCacheSize ,
7880 Resolver : defaultResolver ,
7981 Tls : defaultTLS ,
82+ RetryGracePeriod : defaultGracePeriod ,
8083 }
8184
8285 p .updateFromEnvVar ()
@@ -224,6 +227,14 @@ func (cfg *ProviderConfiguration) updateFromEnvVar() {
224227 if targetUri := os .Getenv (flagdTargetUriEnvironmentVariableName ); targetUri != "" {
225228 cfg .TargetUri = targetUri
226229 }
230+ if gracePeriod := os .Getenv (flagdGracePeriodVariableName ); gracePeriod != "" {
231+ if seconds , err := strconv .Atoi (gracePeriod ); err == nil {
232+ cfg .RetryGracePeriod = seconds
233+ } else {
234+ // Handle parsing error
235+ cfg .log .Error (err , fmt .Sprintf ("invalid grace period '%s'" , gracePeriod ))
236+ }
237+ }
227238
228239}
229240
@@ -397,3 +408,10 @@ func WithGrpcDialOptionsOverride(grpcDialOptionsOverride []grpc.DialOption) Prov
397408 p .GrpcDialOptionsOverride = grpcDialOptionsOverride
398409 }
399410}
411+
412+ // WithRetryGracePeriod allows to set a time window for the transition from stale to error state
413+ func WithRetryGracePeriod (gracePeriod int ) ProviderOption {
414+ return func (p * ProviderConfiguration ) {
415+ p .RetryGracePeriod = gracePeriod
416+ }
417+ }
0 commit comments