-
Notifications
You must be signed in to change notification settings - Fork 22
fix: Honor x-ld-fd-fallback header in fdv2 initializer phase (SDK-2203) #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v7
Are you sure you want to change the base?
Changes from 2 commits
4a1a319
79549e3
b62ac91
cf13c46
65901be
1aec421
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -205,7 +205,17 @@ func (f *FDv2) launchTask(task func()) { | |
| func (f *FDv2) run(ctx context.Context, closeWhenReady chan struct{}) { | ||
| f.UpdateStatus(interfaces.DataSourceStateInitializing, interfaces.DataSourceErrorInfo{}) | ||
|
|
||
| f.runInitializers(ctx, closeWhenReady) | ||
| if f.runInitializers(ctx, closeWhenReady) { | ||
| if f.fdv1FallbackBuilder != nil { | ||
| f.loggers.Warn("Reverting to FDv1 protocol") | ||
| f.synchronizerBuilders = []func() (subsystems.DataSynchronizer, error){f.fdv1FallbackBuilder} | ||
| f.currentSyncIndex = 0 | ||
| } else { | ||
| f.loggers.Warn("Initializer requested FDv1 fallback but none configured") | ||
| f.synchronizerBuilders = nil | ||
| f.UpdateStatus(interfaces.DataSourceStateOff, f.getStatus().LastError) | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if f.configuredWithDataSources && f.dataStoreStatusProvider.IsStatusMonitoringEnabled() { | ||
| f.launchTask(func() { | ||
|
|
@@ -235,12 +245,33 @@ func (f *FDv2) runPersistentStoreOutageRecovery(ctx context.Context, statuses <- | |
| } | ||
| } | ||
|
|
||
| func (f *FDv2) runInitializers(ctx context.Context, closeWhenReady chan struct{}) { | ||
| // runInitializers runs each configured initializer in order until one succeeds, the context is | ||
| // cancelled, or an initializer signals a revert to FDv1. Returns true if an initializer signalled | ||
| // a revert to FDv1. If fallback is signalled alongside a valid Basis, that Basis is applied before | ||
| // returning so evaluations can serve the server-provided data while the FDv1 synchronizer spins up. | ||
| func (f *FDv2) runInitializers(ctx context.Context, closeWhenReady chan struct{}) (fallbackToFDv1 bool) { | ||
| for _, initializer := range f.initializers { | ||
| f.loggers.Infof("Attempting to initialize via %s", initializer.Name()) | ||
| basis, err := initializer.Fetch(f.store, ctx) | ||
| basis, fallback, err := initializer.Fetch(f.store, ctx) | ||
| if errors.Is(err, context.Canceled) { | ||
| return | ||
| return false | ||
| } | ||
| if fallback { | ||
| if err != nil { | ||
| f.loggers.Warnf("Initializer %s requested fallback to FDv1 protocol: %v", initializer.Name(), err) | ||
| } else { | ||
| f.loggers.Warnf("Initializer %s requested fallback to FDv1 protocol", initializer.Name()) | ||
| } | ||
| if basis != nil { | ||
| f.environmentIDProvider.SetEnvironmentID(basis.EnvironmentID) | ||
| f.store.Apply(basis.ChangeSet, basis.Persist) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feels like there could be a way to set this up such that the same apply block down below could be reused, but also not gonna hold up the PR on this. This block of code will probably go away long term. Do you want |
||
| if basis.ChangeSet.Selector().IsDefined() { | ||
| f.readyOnce.Do(func() { | ||
| close(closeWhenReady) | ||
| }) | ||
| } | ||
| } | ||
| return true | ||
| } | ||
| if err != nil { | ||
| f.loggers.Warnf("Initializer %s failed: %v", initializer.Name(), err) | ||
|
|
@@ -253,9 +284,10 @@ func (f *FDv2) runInitializers(ctx context.Context, closeWhenReady chan struct{} | |
| f.readyOnce.Do(func() { | ||
| close(closeWhenReady) | ||
| }) | ||
| return | ||
| return false | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func (f *FDv2) runSynchronizers(ctx context.Context, closeWhenReady chan struct{}) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.