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! 😄

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
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
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 :)

README.md Outdated Show resolved Hide resolved
@Kavindu-Dodan
Copy link
Contributor

LGTM 🙌 Thank you again @ssharaev

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.

* @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
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!

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 <sviatoslav.sharaev@gmail.com>
Signed-off-by: Sviatoslav Sharaev <sviatoslav.sharaev@gmail.com>
Co-authored-by: Kavindu Dodanduwa <Kavindu-Dodan@users.noreply.github.com>
Signed-off-by: Sviatoslav Sharaev <sviatoslav.sharaev@gmail.com>
Signed-off-by: Sviatoslav Sharaev <sviatoslav.sharaev@gmail.com>
Copy link

sonarcloud bot commented Mar 28, 2024

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