Skip to content

Commit 56aa6f4

Browse files
committed
fixup: improve code
Signed-off-by: Simon Schrottner <[email protected]>
1 parent 6bc47d2 commit 56aa6f4

File tree

8 files changed

+666
-312
lines changed

8 files changed

+666
-312
lines changed

providers/flagd/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ require (
1515
github.com/open-feature/flagd/core v0.12.1
1616
github.com/open-feature/go-sdk v1.15.1
1717
github.com/open-feature/go-sdk-contrib/tests/flagd v0.0.0
18-
github.com/testcontainers/testcontainers-go v0.32.0
1918
go.uber.org/mock v0.5.2
2019
go.uber.org/zap v1.27.0
2120
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b

providers/flagd/pkg/configuration.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"os"
1212
"strconv"
1313
"strings"
14-
"time"
1514
)
1615

1716
type ResolverType string
@@ -26,7 +25,7 @@ const (
2625
defaultCache = cache.LRUValue
2726
defaultHost = "localhost"
2827
defaultResolver = rpc
29-
defaultGracePeriod = 5 * time.Second
28+
defaultGracePeriod = 5
3029

3130
rpc ResolverType = "rpc"
3231
inProcess ResolverType = "in-process"
@@ -45,7 +44,7 @@ const (
4544
flagdSourceSelectorEnvironmentVariableName = "FLAGD_SOURCE_SELECTOR"
4645
flagdOfflinePathEnvironmentVariableName = "FLAGD_OFFLINE_FLAG_SOURCE_PATH"
4746
flagdTargetUriEnvironmentVariableName = "FLAGD_TARGET_URI"
48-
flagdGracePeriodVariableName = "FLAGD_GRACE_PERIOD"
47+
flagdGracePeriodVariableName = "FLAGD_RETRY_GRACE_PERIOD"
4948
)
5049

5150
type ProviderConfiguration struct {
@@ -66,7 +65,7 @@ type ProviderConfiguration struct {
6665
CustomSyncProvider sync.ISync
6766
CustomSyncProviderUri string
6867
GrpcDialOptionsOverride []grpc.DialOption
69-
GracePeriod time.Duration
68+
RetryGracePeriod int
7069

7170
log logr.Logger
7271
}
@@ -80,7 +79,7 @@ func newDefaultConfiguration(log logr.Logger) *ProviderConfiguration {
8079
MaxCacheSize: defaultMaxCacheSize,
8180
Resolver: defaultResolver,
8281
Tls: defaultTLS,
83-
GracePeriod: defaultGracePeriod,
82+
RetryGracePeriod: defaultGracePeriod,
8483
}
8584

8685
p.updateFromEnvVar()
@@ -230,7 +229,7 @@ func (cfg *ProviderConfiguration) updateFromEnvVar() {
230229
}
231230
if gracePeriod := os.Getenv(flagdGracePeriodVariableName); gracePeriod != "" {
232231
if seconds, err := strconv.Atoi(gracePeriod); err == nil {
233-
cfg.GracePeriod = time.Duration(seconds) * time.Second
232+
cfg.RetryGracePeriod = seconds
234233
} else {
235234
// Handle parsing error
236235
cfg.log.Error(err, fmt.Sprintf("invalid grace period '%s'", gracePeriod))
@@ -410,9 +409,9 @@ func WithGrpcDialOptionsOverride(grpcDialOptionsOverride []grpc.DialOption) Prov
410409
}
411410
}
412411

413-
// WithGracePeriod allows to set a time window for the transition from stale to error state
414-
func WithGracePeriod(gracePeriod time.Duration) ProviderOption {
412+
// WithRetryGracePeriod allows to set a time window for the transition from stale to error state
413+
func WithRetryGracePeriod(gracePeriod int) ProviderOption {
415414
return func(p *ProviderConfiguration) {
416-
p.GracePeriod = gracePeriod
415+
p.RetryGracePeriod = gracePeriod
417416
}
418417
}

providers/flagd/pkg/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func NewProvider(opts ...ProviderOption) (*Provider, error) {
7272
CustomSyncProvider: provider.providerConfiguration.CustomSyncProvider,
7373
CustomSyncProviderUri: provider.providerConfiguration.CustomSyncProviderUri,
7474
GrpcDialOptionsOverride: provider.providerConfiguration.GrpcDialOptionsOverride,
75+
RetryGracePeriod: provider.providerConfiguration.RetryGracePeriod,
7576
})
7677
} else {
7778
service = process.NewInProcessService(process.Configuration{

0 commit comments

Comments
 (0)