-
Notifications
You must be signed in to change notification settings - Fork 50
feat: add hook data support #1620
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?
feat: add hook data support #1620
Conversation
Summary of ChangesHello @alexandraoberaigner, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request reintroduces and refines the support for Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request re-introduces hook data support, which is a great addition for allowing hooks to maintain state across execution stages. The implementation is solid, with good test coverage for the new functionality. I've identified a few areas for improvement, mainly concerning code clarity, consistency, and a potential thread-safety issue in the HookData
implementation. My detailed comments and suggestions are provided below.
src/test/java/dev/openfeature/sdk/benchmark/AllocationBenchmark.java
Outdated
Show resolved
Hide resolved
9d41b69
to
0761dd1
Compare
0761dd1
to
84124f8
Compare
Signed-off-by: Alexandra Oberaigner <[email protected]>
84124f8
to
269dfe4
Compare
Signed-off-by: Alexandra Oberaigner <[email protected]>
a4f18c3
to
3b113c1
Compare
Signed-off-by: Alexandra Oberaigner <[email protected]>
Signed-off-by: Guido Breitenhuber <[email protected]>
Signed-off-by: Guido Breitenhuber <[email protected]>
Signed-off-by: Guido Breitenhuber <[email protected]>
Signed-off-by: Guido Breitenhuber <[email protected]>
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.
I do like the object based approach, but i have a hard time supporting the changes how hooksupport/hookexecutor is created for each execution. We are bound now for testing, and have no easy way to replace this implementation with a different one.
new SharedHookContext(key, type, this.getMetadata(), provider.getMetadata(), defaultValue); | ||
|
||
var evalContext = mergeEvaluationContext(ctx); | ||
hookExecutor = HookExecutor.create(mergedHooks, sharedHookContext, evalContext, hints); |
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.
[issue] Static constructors for object regularly used adds a lot of complexity for testing, we are now heavily bound during the testing of the OpenFeatureClient to the hookExecutor, mocking is only possible with advanced tooling manipulating the bytecode heavily. Although i like the idea of creating one executor per evaluation, i think this adds more complexity to the code now, and maintainability is decreased. Especially our hotpath should be easy to test without dependencies. Hence for clarity i am oppose introducing static creator methods for logic related objects.
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.
Pls let me know if the current changes are going into the direction you had in mind :)
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.
it is going into the direction, but does not solve the issue, that our logic is still tightly coupled. We should keep the initialization within the constructor of our openFeatureClient, and split logic and data into two separate objects.
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.
pls rereview
…tic factory method to ctor Signed-off-by: Alexandra Oberaigner <[email protected]>
Signed-off-by: Alexandra Oberaigner <[email protected]>
Signed-off-by: Alexandra Oberaigner <[email protected]>
Optional.ofNullable(hook.before(hookContext, hints)).orElse(Optional.empty()); | ||
if (returnedEvalContext.isPresent()) { | ||
// update shared evaluation context for all hooks | ||
setEvaluationContext(evaluationContext.merge(returnedEvalContext.get())); |
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.
I wonder if we should collect all hook contexts in a list and merge them only after the loop. This would mean that the context changes of a hook cannot be read by another hook. Not sure if this would be spec compliant though
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.
I couldn't find something in the spec right away, but with merging it right away we will be at least consistent with what is implemented in dotnet
details.setErrorMessage(e.getMessage()); | ||
enrichDetailsWithErrorDefaults(defaultValue, details); | ||
hookSupport.errorHooks(type, afterHookContext, e, mergedHooks, hints); | ||
hookSupport.executeErrorHooks(e); |
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.
add non null check to hookSupport
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.
does this still apply? & if so, can you elaborate how/why you would add the null check?
return sharedContext.getProviderMetadata(); | ||
} | ||
|
||
@SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Intentional exposure of hookData") |
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.
I wonder why this is needed. HookData
is already public
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.
spotbugs complained... 🤔
* Encapsulates data for hook execution per flag evaluation | ||
*/ | ||
@Getter | ||
class HookSupportData { |
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.
I don't see the value of separating HookSupport
and HookSupportData
. We need to create a new object for every flag evaluation anyway
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.
This was my solution to @aepfli's comment here. It should simplify testing
Signed-off-by: Alexandra Oberaigner <[email protected]>
011a6e4
to
21d8b12
Compare
Signed-off-by: Alexandra Oberaigner <[email protected]>
21d8b12
to
4ab14bf
Compare
Signed-off-by: Alexandra Oberaigner <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1620 +/- ##
============================================
+ Coverage 92.06% 92.37% +0.31%
- Complexity 488 519 +31
============================================
Files 46 51 +5
Lines 1184 1272 +88
Branches 105 114 +9
============================================
+ Hits 1090 1175 +85
- Misses 62 63 +1
- Partials 32 34 +2
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:
|
Signed-off-by: Alexandra Oberaigner <[email protected]>
|
This PR
this re-adds hook data support avoiding breaking changes in the binary (we introduced with v1.18.0)
Related Issues
#1472
###Notes
With v1.18.1 we reverted the hook data feature: