-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-rate-limitWork related to use of rate limit primitivesWork related to use of rate limit primitives
Description
Background and Motivation
Currently, retrieving RateLimitStatistics from a PartitionedRateLimiter requires specifying the resource for which the statistics are needed. This parameter is used to identify the appropriate rate limiter associated with those resources. However, in certain use cases, it may be desirable to retrieve the statistics for all rate limiters managed by the PartitionedRateLimiter.
Proposed API
namespace System.Threading.RateLimiting;
public abstract class PartitionedRateLimiter<TResource> : IAsyncDisposable, IDisposable
{
+ public abstract RateLimiterStatistics[] GetStatistics();
}
Usage Examples
public class RateLimiterHealthCheck : BackgroundService {
private readonly PartitionedRateLimiter<HttpContext> _partitionedRateLimiter
public RateLimiterHealthCheck(PartitionedRateLimiter<HttpContext> partitionedRateLimiter){
_partitionedRateLimiter = partitionedRateLimiter
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
while(!stoppingToken.IsCancellationRequested) {
foreach(var stats in _partitionedRateLimiter.GetStatistics()){
//Sending measurement
MeasurementSender.Send(stats)
}
}
}
}
Alternative Designs
We attempted to retrieve metrics from metric Microsoft.AspNetCore.RateLimiting
, but found that the provided data is aggregated, which may not satisfy scenarios requiring more detailed or per-partition insights.
Risks
There is a possibility of encountering race conditions when accessing the dictionary that holds rate limiter instances.
kchinburarat
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-rate-limitWork related to use of rate limit primitivesWork related to use of rate limit primitives