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

Fix the behavior of OnHedging event #1625

Merged
merged 7 commits into from
Sep 26, 2023
Merged

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented Sep 25, 2023

Details on the issue fix or feature implementation

  • OnHedging was called even for last attempt, it caused that additional event to be reported.
  • Now the OnHedging is called consistently just before the hedged task starts executing.
  • Made changes to OnHedgingArguments<T>
    • Dropped Outcome and Duration properties as these are giving non-deterministic results based on what previous task finished first. If someone needs these we can add it later, however, with different API that allows deterministic results, for example access by attempt number.
    • Added ActionContext property to be consistent with HedgingActionGeneratorArguments<T>

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 Sep 25, 2023
@martintmk martintmk added this to the v8.0.0 milestone Sep 25, 2023
@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (45b0bde) 84.65% compared to head (9b2c8c4) 84.63%.
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1625      +/-   ##
==========================================
- Coverage   84.65%   84.63%   -0.03%     
==========================================
  Files         306      306              
  Lines        6829     6819      -10     
  Branches     1045     1045              
==========================================
- Hits         5781     5771      -10     
  Misses        839      839              
  Partials      209      209              
Flag Coverage Δ
linux ?
macos 84.63% <100.00%> (-0.03%) ⬇️
windows 84.63% <100.00%> (-0.03%) ⬇️

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

Files Coverage Δ
...rc/Polly.Core/Hedging/Controller/HedgingHandler.cs 100.00% <100.00%> (ø)
src/Polly.Core/Hedging/Controller/TaskExecution.cs 100.00% <100.00%> (ø)
...ly.Core/Hedging/HedgingActionGeneratorArguments.cs 100.00% <ø> (ø)
...ging/HedgingResiliencePipelineBuilderExtensions.cs 100.00% <100.00%> (ø)
...rc/Polly.Core/Hedging/HedgingResilienceStrategy.cs 100.00% <ø> (ø)
src/Polly.Core/Hedging/OnHedgingArguments.cs 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@martintmk martintmk marked this pull request as ready for review September 26, 2023 05:30
src/Polly.Core/Hedging/Controller/TaskExecution.cs Outdated Show resolved Hide resolved
src/Polly.Core/Hedging/OnHedgingArguments.cs Outdated Show resolved Hide resolved
/// <remarks>
/// This context is cloned from <see cref="PrimaryContext"/>.
/// </remarks>
public ResilienceContext ActionContext { get; }

/// <summary>
/// Gets the zero-based hedging attempt number.
Copy link
Member

Choose a reason for hiding this comment

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

Is this the correct explanation? Looking at this fresh, if this is zero-based shouldn't we call it an index rather than a number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IF you don't mind i'll leave it as it is because we agreed on this in the API review and to me it sounds nicer that AttemptIndex.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, but I would expect the first value to be one if it's a number. I remember discussing calling it Number but I thought that was in the context of retries and it wasn't zero-based.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For retries it's also called AttemptNumber and it's also zero-based. It's just the name we agreed on. Docs make it clear it starts from zero.

src/Polly.Core/Hedging/HedgingActionGeneratorArguments.cs Outdated Show resolved Hide resolved
Comment on lines 22 to 23
/// <param name="primaryContext">The primary context received by hedging strategy.</param>
/// <param name="actionContext">The action context. cloned from the primary context.</param>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// <param name="primaryContext">The primary context received by hedging strategy.</param>
/// <param name="actionContext">The action context. cloned from the primary context.</param>
/// <param name="primaryContext">The primary context received by the hedging strategy.</param>
/// <param name="actionContext">The action context cloned from the primary context.</param>

src/Polly.Core/Hedging/HedgingActionGeneratorArguments.cs Outdated Show resolved Hide resolved
src/Polly.Core/Hedging/OnHedgingArguments.cs Outdated Show resolved Hide resolved
src/Polly.Core/Hedging/OnHedgingArguments.cs Outdated Show resolved Hide resolved
src/Polly.Core/Hedging/OnHedgingArguments.cs Outdated Show resolved Hide resolved
/// <remarks>
/// This context is cloned from <see cref="PrimaryContext"/>.
/// </remarks>
public ResilienceContext ActionContext { get; }

/// <summary>
/// Gets the zero-based hedging attempt number.
Copy link
Member

Choose a reason for hiding this comment

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

Ok, but I would expect the first value to be one if it's a number. I remember discussing calling it Number but I thought that was in the context of retries and it wasn't zero-based.

@martintmk martintmk merged commit 4759183 into main Sep 26, 2023
17 of 18 checks passed
@martintmk martintmk deleted the mtomka/fix-onhedging-event branch September 26, 2023 09:32
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.

None yet

2 participants