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

Specify default action generator for hedging #1263

Merged
merged 3 commits into from
Jun 8, 2023
Merged

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented Jun 8, 2023

Details on the issue fix or feature implementation

I was investigating the original hedging engine and standard hedging pipeline to find a ways to simplify the hedging configuration. A lot of boilerplate in hedging is around specifying the hedging action generator.

However, we can actually allow the default for this generator. In this case the hedging just executes the original callback again ( similar to retries). This can be done by providing the original callback to the generator arguments.

Standard hedging handler can seamlessly integrate into this enhancement by:

  • Passing a callback that reads the data from resilience context. (for example cloned request message)
  • Taking advantage of the enhanced HedgingActionGeneratorArguments

The simple API addition above will greatly simplify the code in Microsft.Extensions.Http.Resilience library.

On top of that I have also changed the signature of the generator action from Task<TResult> to Task<Outcome<TResult>>. This plays nicely with the overal infrastructure we have. Hedged actions can be optimized to not throw exceptions.

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build

@martintmk martintmk added the v8 Issues related to the new version 8 of the Polly library. label Jun 8, 2023
@martintmk martintmk added this to the v8.0.0 milestone Jun 8, 2023
@martintmk
Copy link
Contributor Author

In the follow-up i will do some internal cleanup around hedging. As we can cleanup some internals.

@codecov
Copy link

codecov bot commented Jun 8, 2023

Codecov Report

Merging #1263 (d43f755) into main (e3bf107) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1263      +/-   ##
==========================================
+ Coverage   83.31%   83.33%   +0.01%     
==========================================
  Files         270      270              
  Lines        6312     6317       +5     
  Branches      981      981              
==========================================
+ Hits         5259     5264       +5     
  Misses        844      844              
  Partials      209      209              
Flag Coverage Δ
linux ?
macos 83.33% <100.00%> (+0.01%) ⬆️
windows 83.33% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
src/Polly.Core/Outcome.cs 100.00% <ø> (ø)
src/Polly.Core/Hedging/Controller/TaskExecution.cs 100.00% <100.00%> (ø)
...Hedging/HedgingActionGeneratorArguments.TResult.cs 100.00% <100.00%> (ø)
src/Polly.Core/Hedging/HedgingHandler.Handler.cs 100.00% <100.00%> (ø)
src/Polly.Core/Hedging/HedgingHandler.TResult.cs 100.00% <100.00%> (ø)
src/Polly.Core/Hedging/HedgingHandler.cs 100.00% <100.00%> (ø)
...lly.Core/Hedging/HedgingStrategyOptions.TResult.cs 100.00% <100.00%> (ø)
src/Polly.Core/Hedging/VoidHedgingHandler.cs 100.00% <100.00%> (ø)

@martintmk martintmk merged commit 9a3bf0f into main Jun 8, 2023
@martintmk martintmk deleted the mtomka/cleanup-hedging branch June 8, 2023 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 Issues related to the new version 8 of the Polly library.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants