Skip to content

Conversation

alexandraoberaigner
Copy link

@alexandraoberaigner alexandraoberaigner commented Sep 10, 2025

This PR

improves PR #1506 from @mdxabu who started the work on adding hook data

Related Issues

Fixes #1472

Notes

Tests & Impl are still WIP:

  • HookData isolation might not fully work yet (not sure if the test is setup incorrectly or we need to adapt the implementation still)
  • pls let me know if you see any edge cases that I didn't think of yet 🙏

mdxabu and others added 13 commits July 7, 2025 21:23
Signed-off-by: mdxabu <[email protected]>
…d ConcurrentHashMap and use a synchronized HashMap instead

Signed-off-by: mdxabu <[email protected]>
Co-authored-by: alexandraoberaigner <[email protected]>
Signed-off-by: Simon Schrottner <[email protected]>
Co-authored-by: alexandraoberaigner <[email protected]>
Signed-off-by: Simon Schrottner <[email protected]>
Signed-off-by: Simon Schrottner <[email protected]>
Signed-off-by: Simon Schrottner <[email protected]>
Signed-off-by: Simon Schrottner <[email protected]>
Copy link
Contributor

@chrfwow chrfwow left a comment

Choose a reason for hiding this comment

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

Nice

Copy link

codecov bot commented Sep 11, 2025

Codecov Report

❌ Patch coverage is 91.11111% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.00%. Comparing base (ca72b19) to head (88afd35).

Files with missing lines Patch % Lines
.../java/dev/openfeature/sdk/HookContextWithData.java 58.33% 5 Missing ⚠️
src/main/java/dev/openfeature/sdk/HookSupport.java 94.28% 0 Missing and 2 partials ⚠️
src/main/java/dev/openfeature/sdk/Pair.java 87.50% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1587      +/-   ##
============================================
+ Coverage     92.82%   93.00%   +0.18%     
- Complexity      487      504      +17     
============================================
  Files            46       50       +4     
  Lines          1170     1215      +45     
  Branches        103      106       +3     
============================================
+ Hits           1086     1130      +44     
- Misses           54       55       +1     
  Partials         30       30              
Flag Coverage Δ
unittests 93.00% <91.11%> (+0.18%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Simon Schrottner <[email protected]>
Signed-off-by: Simon Schrottner <[email protected]>
Signed-off-by: Simon Schrottner <[email protected]>
@aepfli aepfli marked this pull request as ready for review September 11, 2025 12:10
@aepfli aepfli requested review from a team as code owners September 11, 2025 12:10
@aepfli
Copy link
Member

aepfli commented Sep 11, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces HookData to allow hooks to maintain state across execution stages, which is a significant and valuable feature. The implementation refactors HookContext into an interface with different implementations for contexts with and without hook data, updates HookSupport to manage data isolation, and adds comprehensive tests. The changes are well-structured and thoughtful. I've provided a few suggestions to improve API design and test robustness. Overall, this is a solid contribution towards the feature, acknowledging its work-in-progress status.

Signed-off-by: Simon Schrottner <[email protected]>
@@ -54,6 +54,30 @@ public Optional<EvaluationContext> before(HookContext<Object> ctx, Map<String, O
return Optional.ofNullable(new ImmutableContext());
}
});
client.addHooks(new Hook<String>() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this have to be a StringHook for the filter to work?

Signed-off-by: Simon Schrottner <[email protected]>
@aepfli
Copy link
Member

aepfli commented Sep 11, 2025

/Gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a HookData mechanism, allowing hooks to maintain state across execution stages for a single flag evaluation. This is a significant and well-implemented feature. The changes involve refactoring HookContext into an interface and providing implementations for contexts with and without hook-specific data. The core logic in HookSupport and OpenFeatureClient is updated to manage and pass this data correctly, ensuring isolation between hooks and evaluations. The addition of a Pair utility class and new tests are also noted.

My review focuses on improving code clarity and robustness. I've suggested a change to the Pair class for naming consistency and a modification to HookData's default implementation to make it simpler and safer. Overall, this is a great contribution that enhances the hook system's capabilities.

Copy link

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.

Add Hook Data
6 participants