-
Notifications
You must be signed in to change notification settings - Fork 10k
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 IRateLimiterStatisticsFeature with default implementation and tests #46028
base: main
Are you sure you want to change the base?
Add IRateLimiterStatisticsFeature with default implementation and tests #46028
Conversation
Thanks for your PR, @MadL1me. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
src/Middleware/RateLimiting/src/Features/IRateLimiterStatisticsFeature.cs
Outdated
Show resolved
Hide resolved
src/Middleware/RateLimiting/src/Features/IRateLimiterStatisticsFeature.cs
Outdated
Show resolved
Hide resolved
src/Middleware/RateLimiting/src/Features/DefaultRateLimiterStatisticsFeature.cs
Outdated
Show resolved
Hide resolved
src/Middleware/RateLimiting/src/Features/IRateLimiterStatisticsFeature.cs
Outdated
Show resolved
Hide resolved
src/Middleware/RateLimiting/src/Features/IRateLimiterStatisticsFeature.cs
Outdated
Show resolved
Hide resolved
src/Middleware/RateLimiting/src/Features/IRateLimiterStatisticsFeature.cs
Outdated
Show resolved
Hide resolved
src/Middleware/RateLimiting/src/Features/IRateLimiterStatisticsFeature.cs
Outdated
Show resolved
Hide resolved
src/Middleware/RateLimiting/src/Features/IRateLimiterStatisticsFeature.cs
Outdated
Show resolved
Hide resolved
@@ -242,6 +251,11 @@ private PartitionedRateLimiter<HttpContext> CreateEndpointLimiter() | |||
}, new DefaultKeyTypeEqualityComparer()); | |||
} | |||
|
|||
private void AddRateLimiterStatisticsFeature(HttpContext context) | |||
{ | |||
context.Features.Set<IRateLimiterStatisticsFeature>(new DefaultRateLimiterStatisticsFeature(_globalLimiter, _endpointLimiter, context)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we can allocate this once and reuse it
@@ -242,6 +255,12 @@ private PartitionedRateLimiter<HttpContext> CreateEndpointLimiter() | |||
}, new DefaultKeyTypeEqualityComparer()); | |||
} | |||
|
|||
private void AddRateLimiterStatisticsFeature(HttpContext context) | |||
{ | |||
_statisticsFeature?.SetHttpContext(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this stores the HttpContext, we need to allocate it every time then. You can't reuse it because parallel requests will end up accessing someone else's HttpContext.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the extra work, my bad 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks really good so far. We just need to finish discussion in #45658 and nail down the final API. We should do that later today. Thanks for your patience.
We're still working on getting the right API for this. We will revisit the API again on Monday. |
@halter73 no problem, take as much time as you need - its better to ship well designed API than poorly designed, and I appreciate your time and work for this |
@dotnet-policy-service agree |
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
@MadL1me can you change this PR to a Draft PR for now? Hopefully we can figure something out for this soon. |
Yeah, sure |
Add IRateLimiterStatisticsFeature with default implementation and tests
This PR implements first half of this proposed API for RateLimiterMiddleware. Relates to: #44140.
Description
Based on 1 of 2 parts from this API proposal: #45658.
In this PR:
RateLimiterOptions.TrackStatistics