Skip to content
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

feat: add initialize and shutdown behavior #456

Merged
merged 21 commits into from
Jun 7, 2023

Conversation

lopitz
Copy link
Contributor

@lopitz lopitz commented May 28, 2023

Add initialize and shutdown behavior

This PR adds the behavior of the feature provider mutator of the OpenFeatureAPI class to call initialize() and shutdown() of the set/replaced feature provider. It provides the implementation for the requirements 1.1.2.2 and 1.1.2.3.

Related Issues

Fixes #449

Notes

I chose option 3 as described in #449, the asynchronous option to be implemented. This makes sure, there are no nasty delays in the application startup.
I also chose to provider empty default implementations for initialize() and shutdown() in the FeatureProvider interface, to be as backward compatible as possible.

Follow-up Tasks

This PR doesn't implement the client events as described in #440. Depending on the implementation, the tests might need be changed. Hence, I created a helper class FeatureProviderTestUtils which encapsulates the new async nature of the provider mutator.

How to test

Unit and spec tests are provided.

lopitz added 3 commits May 27, 2023 21:07
- adds call to provider's `initialize()` method when provider is changed

Signed-off-by: Lars Opitz <[email protected]>
- adds call to provider's `shutdown()` method when provider is changed

Signed-off-by: Lars Opitz <[email protected]>
@lopitz lopitz requested a review from a team as a code owner May 28, 2023 16:19
@codecov
Copy link

codecov bot commented May 28, 2023

Codecov Report

Merging #456 (4437b89) into main (24f0923) will increase coverage by 0.89%.
The diff coverage is 100.00%.

❗ Current head 4437b89 differs from pull request most recent head 24b7e98. Consider uploading reports for the commit 24b7e98 to get more accurate results

@@             Coverage Diff              @@
##               main     #456      +/-   ##
============================================
+ Coverage     93.20%   94.09%   +0.89%     
- Complexity      220      257      +37     
============================================
  Files            23       24       +1     
  Lines           500      576      +76     
  Branches         32       35       +3     
============================================
+ Hits            466      542      +76     
  Misses           17       17              
  Partials         17       17              
Flag Coverage Δ
unittests 94.09% <100.00%> (+0.89%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...main/java/dev/openfeature/sdk/FeatureProvider.java 100.00% <100.00%> (ø)
.../main/java/dev/openfeature/sdk/OpenFeatureAPI.java 100.00% <100.00%> (ø)
...n/java/dev/openfeature/sdk/ProviderRepository.java 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@toddbaert
Copy link
Member

I think we need a API shutdown method: as specified in 1.6.1. This method would basically just call shutdown on all providers to cleanly exit for a graceful shutdown.

@toddbaert
Copy link
Member

This looks good to me. I think this needs to be added. Though it could be done in a separate PR, it's related-enough to be worth implementing here. The testing looks good.

I'd like your insight on this. The same thing came up in the JS-SDK implementation and I'm wondering if we don't need to slightly tighten the spec requirement here. Not a blocker for this PR but very interested in your opinion.

@toddbaert
Copy link
Member

@open-feature/sdk-java-approvers @open-feature/sdk-java-maintainers

lopitz and others added 5 commits May 31, 2023 21:24
- makes API using old provider while initialization of replacement not completed

Signed-off-by: Lars Opitz <[email protected]>
- doesn't call shutdown of replaced provider if it is bound multiple times

Signed-off-by: Lars Opitz <[email protected]>
…ure#457)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Signed-off-by: Lars Opitz <[email protected]>
@lopitz
Copy link
Contributor Author

lopitz commented May 31, 2023

I addressed the comments of the PR:

  • updated JavaDoc comment for FeatureProvider
  • changed provider mutator behavior to use old one while new one is not yet implemented
  • fixed the bug, that provider would be shut down even if bound to multple names/default

The API level shutdown method is not yet implemented, as Spec PR#193 is not yet implemented.

@lopitz
Copy link
Contributor Author

lopitz commented May 31, 2023

@toddbaert , how can i retrigger the build. it failed, as it didn't find the api key for codecov for whatever reason... 🤔

@Kavindu-Dodan
Copy link
Contributor

@toddbaert , how can i retrigger the build. it failed, as it didn't find the api key for codecov for whatever reason... 🤔

Retriggered and seems a GH glitch

@Kavindu-Dodan
Copy link
Contributor

Had an initial look and implementation and especially the tests are inspiring to review :)

Left one remark to follow-up

@toddbaert
Copy link
Member

toddbaert commented Jun 1, 2023

@toddbaert , how can i retrigger the build. it failed, as it didn't find the api key for codecov for whatever reason... thinking

Retriggered and seems a GH glitch

Ya it's very annoying but sometimes when codecov gets busy it throws this error, which is a total red herring. @Kavindu-Dodan @lopitz

@toddbaert toddbaert mentioned this pull request Jun 1, 2023
lopitz and others added 6 commits June 1, 2023 22:36
- moves handling of providers out of OpenFeatureAPI into dedicated ProviderRepository
- cleans up temp map for named providers/member for default provider on successful initialization
- prepares API shutdown method by creating one in the Provider Repository

Signed-off-by: Lars Opitz <[email protected]>
- simplifies code
- increases coverage

Signed-off-by: Lars Opitz <[email protected]>
- removes faulty locking code
- clears all named providers on shutdown
- sets NoOpProvider on shutdown

Signed-off-by: Lars Opitz <[email protected]>
- avoids calling initialize on already initialized providers

Signed-off-by: Lars Opitz <[email protected]>
@lopitz lopitz requested review from toddbaert and Kavindu-Dodan June 4, 2023 12:14
Copy link
Contributor

@Kavindu-Dodan Kavindu-Dodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with several minor open discussions. They are not blockers and the implementation looks good.

@toddbaert
Copy link
Member

toddbaert commented Jun 6, 2023

I think this is good to merge after this, and considering @Kavindu-Dodan 's optional suggestions.

@lopitz
Copy link
Contributor Author

lopitz commented Jun 6, 2023

@toddbaert, @Kavindu-Dodan i addressed the comments, pls re-review

/**
* This method is only here for testing as otherwise all tests after the API shutdown test would fail.
*/
final void resetProviderRepository() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me since it's package private.

@toddbaert toddbaert self-requested a review June 7, 2023 01:32
@toddbaert toddbaert merged commit 5f173ff into open-feature:main Jun 7, 2023
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 7, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@lopitz lopitz deleted the java-sdk-449 branch June 10, 2023 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Initialize/Shutdown on provider registration
3 participants