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: context propagation #848

Merged
merged 4 commits into from
Mar 29, 2024

Conversation

ssharaev
Copy link
Member

This PR

  • adds transactional context support

Related Issues

Fixes #819

Notes

  • This is my first PR here, so I'll appreciate any feedback you can provide!
  • I'm not sure if OpenFeatureAPI should use NoOpTransactionContextPropagator as a default TransactionContextPropagator, or if it can simply be null.
  • I assume there was a mistake in the test FlagEvaluationSpecTest.multi_layer_context_merges_correctly() - attributes were put in the same HashMap twice. Have a look at it, please, and if I'm mistaken, I'll revert the changes.

@ssharaev ssharaev requested a review from a team as a code owner March 16, 2024 15:37
@toddbaert
Copy link
Member

Wow thanks @ssharaev !

We'll get this reviewed ASAP, but it's KubeCon this week so many maintainers are traveling or will be soon, so patience is appreciated!

I'm adding @beeme1mr and @lukas-reining even though they aren't Java maintainers, because they both worked on the context propagation spec.

@ssharaev
Copy link
Member Author

Wow thanks @ssharaev !

We'll get this reviewed ASAP, but it's KubeCon this week so many maintainers are traveling or will be soon, so patience is appreciated!

I'm adding @beeme1mr and @lukas-reining even though they aren't Java maintainers, because they both worked on the context propagation spec.

@toddbaert , thank you!
No problem, I'll be patient! 😄

@toddbaert toddbaert requested a review from Kavindu-Dodan March 16, 2024 16:03
@Kavindu-Dodan Kavindu-Dodan force-pushed the feat/transaction-context branch from cdf2f6f to d8c39f8 Compare March 18, 2024 18:25
Copy link

codecov bot commented Mar 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.64%. Comparing base (46d04fe) to head (8c5ee7e).

❗ Current head 8c5ee7e differs from pull request most recent head c33f668. Consider uploading reports for the commit c33f668 to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #848      +/-   ##
============================================
+ Coverage     95.30%   95.64%   +0.34%     
- Complexity      370      384      +14     
============================================
  Files            34       36       +2     
  Lines           852      873      +21     
  Branches         52       52              
============================================
+ Hits            812      835      +23     
+ Misses           21       20       -1     
+ Partials         19       18       -1     
Flag Coverage Δ
unittests 95.64% <100.00%> (+0.34%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Kavindu-Dodan
Copy link
Contributor

@ssharaev great work 👏

I'm not sure if OpenFeatureAPI should use NoOpTransactionContextPropagator as a default

I think this is the right choice. But we should document this fact as well as show how to register TransactionContextPropagator as well as ability to register a custom implementation.

I assume there was a mistake in the test FlagEvaluationSpecTest.multi_layer_context_merges_correctly()

Yes, this is the wrong setup of the test. Thank you for seeing this and fixing it.

I left some review comments, please check them. Once done, I can approve this :)

@Kavindu-Dodan Kavindu-Dodan force-pushed the feat/transaction-context branch from 5394cf4 to 7b96c2f Compare March 20, 2024 15:27
@Kavindu-Dodan
Copy link
Contributor

@ssharaev could you please check the check style failure [1]

You can execute them locally with mvn org.apache.maven.plugins:maven-checkstyle-plugin:3.3.1:check

[1] - https://github.com/open-feature/java-sdk/actions/runs/8361375008/job/22889438838?pr=848#step:6:66

@ssharaev ssharaev force-pushed the feat/transaction-context branch from 7b96c2f to 0af8a3e Compare March 20, 2024 16:32
@ssharaev
Copy link
Member Author

@ssharaev could you please check the check style failure [1]

You can execute them locally with mvn org.apache.maven.plugins:maven-checkstyle-plugin:3.3.1:check

[1] - https://github.com/open-feature/java-sdk/actions/runs/8361375008/job/22889438838?pr=848#step:6:66

Yes, of course!
Fixed :)

@ssharaev ssharaev requested a review from Kavindu-Dodan March 21, 2024 12:02
@Kavindu-Dodan Kavindu-Dodan force-pushed the feat/transaction-context branch from 0af8a3e to cf87999 Compare March 21, 2024 13:57
README.md Outdated Show resolved Hide resolved
@Kavindu-Dodan
Copy link
Contributor

LGTM 🙌 Thank you again @ssharaev

@Kavindu-Dodan Kavindu-Dodan force-pushed the feat/transaction-context branch from 2629d21 to c888563 Compare March 22, 2024 18:15
Copy link
Member

@lukas-reining lukas-reining left a comment

Choose a reason for hiding this comment

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

This looks great to me, thanks @ssharaev!
The only thing I would like to change is the test that verifies that the values are actually thread independent.

Comment on lines 45 to 55
contextPropagator.setTransactionContext(firstContext);
EvaluationContext firstThreadContext = contextPropagator.getTransactionContext();
assertSame(firstContext, firstThreadContext);

FutureTask<EvaluationContext> futureTask = new FutureTask<>(callable);
Thread thread = new Thread(futureTask);
thread.start();
EvaluationContext secondThreadContext = futureTask.get();

assertSame(secondContext, secondThreadContext);
assertSame(firstContext, firstThreadContext);
Copy link
Member

Choose a reason for hiding this comment

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

Here we should also get and assert the value of the firstThreadContext after line 52.
Currently as far as I can tell the test does not verify that firstThreadContext is not changed by the callable in the second thread, as the value of firstThreadContext is read before (line 46) the second thread is started (line 51)

Copy link
Member

Choose a reason for hiding this comment

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

Agreed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you're right, line 55 checked nothing. Thank you for finding this!
Replaced it with assertSame(firstContext, contextPropagator.getTransactionContext());

@toddbaert
Copy link
Member

@ssharaev I'll give this a thorough review tomorrow.

@Kavindu-Dodan Kavindu-Dodan force-pushed the feat/transaction-context branch from c888563 to 8c5ee7e Compare March 25, 2024 20:52
* @param invocationContext invocation context
* @return merged evaluation context
*/
private EvaluationContext mergeEvaluationContext(
Copy link
Member

Choose a reason for hiding this comment

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

Nice idea to extract this.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks! :)

Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

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

I spent time looking through this, and besides the minor point @lukas-reining brought up, it looks very good. Very nice to have this done, thanks so much!

Would you like an invite to the OpenFeature org @ssharaev ? There's no obligation, but it allows us to ping you, etc.

@ssharaev ssharaev force-pushed the feat/transaction-context branch from 8c5ee7e to a7f2af9 Compare March 27, 2024 17:14
@ssharaev
Copy link
Member Author

ssharaev commented Mar 27, 2024

@toddbaert , thank you for your review!

Would you like an invite to the OpenFeature org @ssharaev ? There's no obligation, but it allows us to ping you, etc.

Wow, I would be happy to join OpenFeature org, I really love, what you're doing!

@ssharaev ssharaev requested a review from lukas-reining March 27, 2024 17:22
Copy link
Member

@lukas-reining lukas-reining left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you @ssharaev :)

ssharaev and others added 4 commits March 28, 2024 07:01
Signed-off-by: Sviatoslav Sharaev <[email protected]>
Signed-off-by: Sviatoslav Sharaev <[email protected]>
Co-authored-by: Kavindu Dodanduwa <[email protected]>
Signed-off-by: Sviatoslav Sharaev <[email protected]>
Signed-off-by: Sviatoslav Sharaev <[email protected]>
@Kavindu-Dodan Kavindu-Dodan force-pushed the feat/transaction-context branch from a7f2af9 to c33f668 Compare March 28, 2024 14:01
Copy link

Quality Gate Passed Quality Gate passed

Issues
9 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@beeme1mr beeme1mr merged commit de5aa64 into open-feature:main Mar 29, 2024
6 checks passed
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.

[FEATURE] Implement transaction context
5 participants