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

Add Outcome to the BreakDurationGeneratorArguments #2200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

peter-csala
Copy link
Contributor

Pull Request

The issue or feature being addressed

  • Currently the Circuit Breaker could not take advantage of the RetryAfter header to dynamically set its break duration

Details on the issue fix or feature implementation

  • Extended the BreakDurationGeneratorArguments with Outcome

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

Copy link
Member

@martincostello martincostello Jul 16, 2024

Choose a reason for hiding this comment

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

New entries should go in the Unshipped file. What you're doing here is effectively "tricking" the Public API analyser into thinking breaking changes aren't.

Copy link
Contributor Author

@peter-csala peter-csala Jul 16, 2024

Choose a reason for hiding this comment

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

Well, that's quite unfortunate. :(

That would require me to create a BreakDurationGeneratorArguments.TResult.cs. Which is fine but inside the CircuitBreakerStrategyOptions.TResult.cs I have to create a new generator to make this change backward compatible.

 public Func<BreakDurationGeneratorArguments, ValueTask<TimeSpan>>? BreakDurationGenerator { get; set; }

 public Func<BreakDurationGeneratorArguments<TResult>, ValueTask<TimeSpan>>? NewBreakDurationGenerator { get; set; }

Do you have any idea how to solve this problem?

Copy link
Member

Choose a reason for hiding this comment

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

Not easily, no - is what you're trying to do achievable via storing the result in the context?

Copy link
Contributor Author

@peter-csala peter-csala Jul 16, 2024

Choose a reason for hiding this comment

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

The OnOpened is called after the break duration calculation, because the OnCircuitOpenedArguments contains the break duration as well.

So, I can't set the context from the OnOpened that's why I have to set it inside the user callback. Which is not possible if I decorate my HttpClient via the AddResilienceHandler. :(

Copy link
Member

Choose a reason for hiding this comment

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

Maybe @martintmk has some ideas.

If the type was a class we could just inherit from it and add a generic version, the we wouldn't need to touch the generator but you'd need to do a cast /as to get the generic version. As it's a struct we can't do that.

I don't think introducing a "NewBreakDurationGenerator" parallel dimension would be a good move and I don't think we'd want to go down the route of a v9 to make this kind of breaking change any time soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this NewBreakDurationGenerator idea is non-sense. I've just used it to illustrate the problem.

If my memory serves well this is the 3rd or 4th time when we do not fix something on the API due to backward compatibility. Would it make sense to collect these under a ticket and label it with v9?

Copy link
Member

Choose a reason for hiding this comment

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

We could maybe use the existing breaking change label and park an issues that would be nice to have but would be breaking there.

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.87%. Comparing base (1eb48d7) to head (3bdcafb).
Report is 142 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2200      +/-   ##
==========================================
- Coverage   83.88%   83.87%   -0.01%     
==========================================
  Files         313      313              
  Lines        7172     7171       -1     
  Branches     1060     1060              
==========================================
- Hits         6016     6015       -1     
  Misses        785      785              
  Partials      371      371              
Flag Coverage Δ
linux 83.87% <100.00%> (-0.01%) ⬇️
macos 83.87% <100.00%> (-0.01%) ⬇️
windows 83.87% <100.00%> (-0.01%) ⬇️

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.

@martintmk
Copy link
Contributor

I am thinking, how about we add a Outcome<object> Outcome field to existing BreakDurationGeneratorArguments?

@peter-csala
Copy link
Contributor Author

I am thinking, how about we add a Outcome<object> Outcome field to existing BreakDurationGeneratorArguments?

That could solve the breaking change problem.

But the usage of the Outcome would be inconsistent with the rest of the argument structures/classes.

Copy link
Contributor

This pull request is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further changes are made.

@github-actions github-actions bot added stale Stale issues or pull requests and removed stale Stale issues or pull requests labels Sep 15, 2024
Copy link
Contributor

This pull request is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further changes are made.

@github-actions github-actions bot added stale Stale issues or pull requests and removed stale Stale issues or pull requests labels Nov 15, 2024
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.

3 participants