Skip to content

Conversation

mdxabu
Copy link

@mdxabu mdxabu commented Jul 6, 2025

This PR

Added the Hook Data

  • adds this new feature

Related Issues

Fixes #1472

@beeme1mr, Please review this if there is any problem or if I did anything wrong, ping me!

@mdxabu mdxabu requested review from a team as code owners July 6, 2025 11:07
@mdxabu mdxabu changed the title Added hook data feat: Added hook data Jul 6, 2025
* Default thread-safe implementation of HookData.
*/
public class DefaultHookData implements HookData {
private final Map<String, Object> data = Collections.synchronizedMap(new HashMap<>());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a thread safe implementation? If the hook data only lives for the duraion of a flag evalution, there will probably not be concurrent access to this object. IIRC, a flag evaluation happens synchronously.

Copy link
Member

Choose a reason for hiding this comment

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

Ya I think somebody would have to really try to create a concurrency issue here, because of the nature of hooks. I agree this seems un-needed.

<T> T get(String key, Class<T> type);

/**
* Default implementation using ConcurrentHashMap for thread safety.
Copy link
Contributor

Choose a reason for hiding this comment

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

DefaultHookData uses a Collections.synchronizedMap(new HashMap<>()), not a ConcurrentHashMap

* Hook data provides a way for hooks to maintain state across their execution stages.
* Each hook instance gets its own isolated data store.
*/
HookData hookData;
Copy link
Contributor

Choose a reason for hiding this comment

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

With this addition, the Constructor of the HookContext changes, which may be a breaking change @toddbaert

Copy link
Member

Choose a reason for hiding this comment

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

That's certainly a breaking change, yep. @mdxabu you can add new constructors, but you'll have to preserve any old ones. Please add unit tests to confirm this.

@chrfwow
Copy link
Contributor

chrfwow commented Jul 7, 2025

@mdxabu you will need to force push a commit that is signed off, otherwise the DCO check will not succeed

@mdxabu
Copy link
Author

mdxabu commented Jul 7, 2025

@mdxabu you will need to force push a commit that is signed off, otherwise the DCO check will not succeed

Can I squash those commits into one commit, and then I will sign off?

@chrfwow
Copy link
Contributor

chrfwow commented Jul 7, 2025

Can I squash those commits into one commit, and then I will sign off?

Yes, you could do that. If you click on the failed DCO action, you schould see a short explanation

mdxabu added 2 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]>
@mdxabu
Copy link
Author

mdxabu commented Jul 7, 2025

@chrfwow, I force push the commits! Now DCO action runs successfully.

@mdxabu mdxabu requested a review from chrfwow July 8, 2025 04:54
@chrfwow
Copy link
Contributor

chrfwow commented Jul 8, 2025

The build currently fails because of formatting issues. You can resolve them automatically by running the spotless plugin

Copy link

codecov bot commented Jul 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.35%. Comparing base (907b75d) to head (e0ad9d9).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1506      +/-   ##
============================================
+ Coverage     92.82%   93.35%   +0.53%     
- Complexity      487      492       +5     
============================================
  Files            46       47       +1     
  Lines          1170     1189      +19     
  Branches        103      107       +4     
============================================
+ Hits           1086     1110      +24     
+ Misses           54       49       -5     
  Partials         30       30              
Flag Coverage Δ
unittests 93.35% <100.00%> (+0.53%) ⬆️

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.

Copy link

sonarqubecloud bot commented Jul 8, 2025

* Each hook instance gets its own isolated data store that persists only for the duration
* of a single flag evaluation.
*/
public interface HookData {
Copy link
Member

Choose a reason for hiding this comment

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

We may be able to use some of the functionality in Structure or it's implementations to do this. We don't need all of those methods, but some wouldn't hurt, I think, and it would reduce duplication and promote consistency.

@alexandraoberaigner
Copy link

@mdxabu how is it going? We do have an internal dependency on this. Can we support somehow? :)

@mdxabu
Copy link
Author

mdxabu commented Sep 1, 2025

Yeah, Sure!

@alexandraoberaigner
Copy link

Yeah, Sure!

Great, let me know how I can support :)

Copy link

sonarqubecloud bot commented Sep 1, 2025

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