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 RateLimiterResilienceStrategy #1103

Merged
merged 4 commits into from
Apr 11, 2023
Merged

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented Apr 11, 2023

The issue or feature being addressed

Closes #1086

Details on the issue fix or feature implementation

The Polly.RateLimiting adopts the .NET Rate Limiting APIs for Polly scenarios.

  • It exposes the AddRateLimiter extension methods for ResiliencePipelineBuilder.
  • It exposes the AddConcurrencyLimiter convenience extension methods for ResiliencePipelineBuilder.
  • It exposes the RateLimiterRejectedException to notify the caller that the operation was rate limited.

Example:

// Convenience extension method for ConcurrencyLimiter
builder.AddConcurrencyLimiter(
    new ConcurrencyLimiterOptions
    {
        PermitLimit = 10,
        QueueLimit = 10
    },
    () => Console.WriteLine("Rate limiter rejected!"));

// Convenience extension method
builder.AddRateLimiter(
    new ConcurrencyLimiter(new ConcurrencyLimiterOptions
    {
        PermitLimit = 10,
        QueueLimit = 10
    }),
    onRejected => onRejected.Add(() => Console.WriteLine("Rate limiter rejected!")));

// Add rate limiter using the RateLimiterStrategyOptions
builder.AddRateLimiter(new RateLimiterStrategyOptions
{
    RateLimiter = new ConcurrencyLimiter(new ConcurrencyLimiterOptions
    {
        PermitLimit = 10,
        QueueLimit = 10
    }),
    OnRejected = new OnRateLimiterRejectedEvent().Add(() => Console.WriteLine("Rate limiter rejected!"))
});

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 11, 2023
@martintmk martintmk added this to the v8.0.0 milestone Apr 11, 2023
@martintmk martintmk self-assigned this Apr 11, 2023
src/Directory.Packages.props Show resolved Hide resolved
src/Polly.RateLimiting/README.md Outdated Show resolved Hide resolved
src/Polly.RateLimiting/README.md Outdated Show resolved Hide resolved
src/Polly.RateLimiting/RateLimiterConstants.cs Outdated Show resolved Hide resolved
src/Polly.RateLimiting/RateLimiterRejectedException.cs Outdated Show resolved Hide resolved
src/Polly.RateLimiting/RateLimiterRejectedException.cs Outdated Show resolved Hide resolved
@martintmk martintmk enabled auto-merge (squash) April 11, 2023 11:24
@martintmk martintmk disabled auto-merge April 11, 2023 11:24
@codecov-commenter
Copy link

codecov-commenter commented Apr 11, 2023

Codecov Report

Merging #1103 (d8fc102) into main (2627c45) will increase coverage by 0.73%.
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    #1103      +/-   ##
==========================================
+ Coverage   76.96%   77.69%   +0.73%     
==========================================
  Files         191      199       +8     
  Lines        4597     4748     +151     
  Branches      838      846       +8     
==========================================
+ Hits         3538     3689     +151     
  Misses        854      854              
  Partials      205      205              
Flag Coverage Δ
linux 77.69% <100.00%> (+0.73%) ⬆️
macos 77.69% <100.00%> (+0.73%) ⬆️
windows 77.69% <100.00%> (+0.73%) ⬆️

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

Impacted Files Coverage Δ
.../Retry/RetryResilienceStrategyBuilderExtensions.cs 100.00% <ø> (ø)
src/Polly.Core/Strategy/SimpleEvent.cs 100.00% <ø> (ø)
...eout/TimeoutResilienceStrategyBuilderExtensions.cs 100.00% <ø> (ø)
src/Polly.Core/Utils/SynchronousExecutionHelper.cs 100.00% <100.00%> (ø)
...lly.RateLimiting/OnRateLimiterRejectedArguments.cs 100.00% <100.00%> (ø)
...c/Polly.RateLimiting/OnRateLimiterRejectedEvent.cs 100.00% <100.00%> (ø)
...Polly.RateLimiting/RateLimiterRejectedException.cs 100.00% <100.00%> (ø)
...olly.RateLimiting/RateLimiterResilienceStrategy.cs 100.00% <100.00%> (ø)
.../RateLimiterResilienceStrategyBuilderExtensions.cs 100.00% <100.00%> (ø)
...c/Polly.RateLimiting/RateLimiterStrategyOptions.cs 100.00% <100.00%> (ø)

... and 6 files with indirect coverage changes

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

@martintmk martintmk merged commit 23c427e into main Apr 11, 2023
@martintmk martintmk deleted the mtomka/rate-limiting branch April 11, 2023 12:07
@martintmk martintmk mentioned this pull request Apr 11, 2023
4 tasks
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.

Introduce Polly.RateLimiting project
3 participants