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

Introduce API for Circuit Breaker Strategy #1145

Merged
merged 8 commits into from
Apr 19, 2023
Merged

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented Apr 19, 2023

The issue or feature being addressed

Contributes to #1098

Details on the issue fix or feature implementation

This PR adds the public API for the circuit breaker strategy.

Usage:

// Advanced Circuit Breaker
builder
    .AddAdvancedCircuitBreaker(new AdvancedCircuitBreakerStrategyOptions
    {
        BreakDuration = TimeSpan.FromSeconds(10),
        FailureThreshold = 0.4,
        OnOpened = new OutcomeEvent<OnCircuitOpenedArguments>().Register<double>(() => Console.WriteLine("Circuit opened!"))
    });

// Simple Circuit Breaker
builder
    .AddCircuitBreaker(new CircuitBreakerStrategyOptions
    {
        BreakDuration = TimeSpan.FromSeconds(10),
        FailureThreshold = 90,
        OnOpened = new OutcomeEvent<OnCircuitOpenedArguments>().Register<double>(() => Console.WriteLine("Circuit opened!"))
    });

// Access control of Circuit Breaker
var manualControl = new CircuitBreakerManualControl();
var stateProvider = new CircuitBreakerStateProvider();

builder
    .AddAdvancedCircuitBreaker(new AdvancedCircuitBreakerStrategyOptions
    {
        BreakDuration = TimeSpan.FromSeconds(10),
        FailureThreshold = 0.4,
        ManualControl = manualControl,
        StateProvider = stateProvider
    });

builder.Build();

await manualControl.IsolateAsync(CancellationToken.None);
var state = stateProvider.CircuitState;

No implementation yet, to be done in follow-up PRs. Some mutants to be killed but the API shape is ready for review.

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 Apr 19, 2023
@martintmk martintmk added this to the v8.0.0 milestone Apr 19, 2023
@martintmk martintmk self-assigned this Apr 19, 2023
@martintmk martintmk marked this pull request as ready for review April 19, 2023 12:03
@martintmk martintmk changed the title Introduce Circuit Breaker Strategy Introduce API for Circuit Breaker Strategy Apr 19, 2023
@codecov-commenter
Copy link

codecov-commenter commented Apr 19, 2023

Codecov Report

Merging #1145 (5233ef6) into main (cec36cb) will increase coverage by 0.64%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #1145      +/-   ##
==========================================
+ Coverage   79.16%   79.81%   +0.64%     
==========================================
  Files         213      229      +16     
  Lines        5084     5198     +114     
  Branches      882      888       +6     
==========================================
+ Hits         4025     4149     +124     
+ Misses        854      844      -10     
  Partials      205      205              
Flag Coverage Δ
linux 79.81% <100.00%> (+0.64%) ⬆️
macos 79.81% <100.00%> (?)
windows 79.81% <100.00%> (+0.64%) ⬆️

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

Impacted Files Coverage Δ
...r/AdvancedCircuitBreakerStrategyOptions.TResult.cs 100.00% <100.00%> (ø)
...itBreaker/AdvancedCircuitBreakerStrategyOptions.cs 100.00% <100.00%> (ø)
...eaker/BaseCircuitBreakerStrategyOptions.TResult.cs 100.00% <100.00%> (ø)
...ircuitBreaker/BaseCircuitBreakerStrategyOptions.cs 100.00% <100.00%> (ø)
...e/CircuitBreaker/BrokenCircuitException.TResult.cs 100.00% <100.00%> (ø)
...olly.Core/CircuitBreaker/BrokenCircuitException.cs 100.00% <100.00%> (ø)
...lly.Core/CircuitBreaker/CircuitBreakerConstants.cs 100.00% <100.00%> (ø)
...Core/CircuitBreaker/CircuitBreakerManualControl.cs 100.00% <100.00%> (ø)
...CircuitBreaker/CircuitBreakerPredicateArguments.cs 100.00% <100.00%> (ø)
...CircuitBreaker/CircuitBreakerResilienceStrategy.cs 100.00% <100.00%> (ø)
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@martintmk martintmk mentioned this pull request Apr 19, 2023
4 tasks
Copy link
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

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

Nice work.

@martintmk martintmk enabled auto-merge (squash) April 19, 2023 15:18
@martintmk martintmk merged commit 5bf2239 into main Apr 19, 2023
@martintmk martintmk deleted the mtomka/circuit-breaker branch April 19, 2023 15:55
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.

3 participants