-
Notifications
You must be signed in to change notification settings - Fork 31
fix: Improved handling within ProviderRegistry #560
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: main
Are you sure you want to change the base?
Conversation
It is incorrect to call `ProviderRegister.set_provider` without a provider AND a domain. A validation check exists for the provider, but none for the domain. In this commit, we introduce that domain validation and introduce tests to capture this expected behavior. Signed-off-by: Matthew Keeler <mkeeler@launchdarkly.com>
If a provider is set for two different domains, it will only be initialized once. However, if a customer were to use a provider as both default and domain specific, it would incorrectly be initialized twice. Signed-off-by: Matthew Keeler <mkeeler@launchdarkly.com>
If a provider is set for two different domains, and then one of them is replaced, it will only be shutdown once. However, if a customer were to use a provider as both default and domain specific, replacing one or the other would incorrectly shutdown both usages. Signed-off-by: Matthew Keeler <mkeeler@launchdarkly.com>
Once a provider has been removed, there is no value in retaining a reference to it in the `_provider_status` dictionary. Instead of explicitly setting the status as `NOT_READY`, we can rely on this being the default status served from the `get_provider_status` method, allowing us to remove the dictionary entry entirely. Signed-off-by: Matthew Keeler <mkeeler@launchdarkly.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #560 +/- ##
==========================================
- Coverage 97.83% 97.74% -0.10%
==========================================
Files 40 41 +1
Lines 1849 1993 +144
==========================================
+ Hits 1809 1948 +139
- Misses 40 45 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
gruebel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks good, but as stated I'm not sure about the shutdown change
| old_provider not in providers.values() | ||
| and old_provider != self._default_provider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you switch the statements, it is faster to check the second one, so if this is false there is not need to check all the providers.
| ): | ||
| self._shutdown_provider(old_provider) | ||
| if provider not in providers.values(): | ||
| if provider not in providers.values() and provider != self._default_provider: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saem here
| if hasattr(provider, "shutdown"): | ||
| provider.shutdown() | ||
| self._provider_status[provider] = ProviderStatus.NOT_READY | ||
| del self._provider_status[provider] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about this change, https://openfeature.dev/specification/sections/providers#requirement-252 states
After a provider's shutdown function has terminated, the provider SHOULD revert to its uninitialized state.
This PR
Introduces the following changes to the
ProviderRegistry.All of this functionality is in this single PR, but this can be split into individual PRs if desired. Each commit contains a singular bit of functionality or change, so reviewing individually might be easier.
Assuming we keep the PR as one, I have provided the changelog override necessary for release please.
BEGIN_COMMIT_OVERRIDE
refactor: Delete provider status instead of marking as NOT_READY
fix: Prevent providers from being shutdown multiple times
fix: Prevent providers from being initialized multiple times
fix: Validate domain is present when calling
set_provideron registryEND_COMMIT_OVERRIDE