Closed
Description
Background and Motivation
Addresses the rate limiting part of dotnet/runtime#79459
Microsoft.AspNetCore.RateLimiting
is new in .NET 7. It currently doesn't have event counters or metrics counters. This PR adds metrics counters, making rate limiting in ASP.NET Core apps more observable.
Notes:
Microsoft.AspNetCore.RateLimiting
meter is created by metrics DI integration.- These counters are in the middleware layer and focus on how requests are impacted by rate limiting. They don't provide low-level counter information.
- Rate-limiting middleware supports partitioning. The partition isn't added to rate-limiting counter tags. This is for a couple of reasons:
- Primary reason is the partition is defined by the app could be high-cardinality. For example, a common partition is the authenticated user name. The system could have thousands of users, creating a metrics tag cardinality explosion.
- It's possible to have a global and endpoint policy for a request. They could have different partition values. Which value to use? Or change counters to measure policies separately? Simpler not to include it.
Proposed API
Microsoft.AspNetCore.RateLimiting
current-lease-requests
Name | Instrument Type | Unit | Description |
---|---|---|---|
current-lease-requests |
UpDownCounter | {request} |
Number of HTTP requests that are currently active on the server that hold a rate limiting lease. |
Attribute | Type | Description | Examples | Presence |
---|---|---|---|---|
policy |
string | Rate limiting policy name for this request. | MyPolicyName |
Added if the matched route has a rate limiting policy name. |
method |
string | HTTP request method. | GET ; POST ; HEAD |
Added if route endpoint set |
route |
string | The matched route | {controller}/{action}/{id?} |
Added if route endpoint set |
lease-request-duration
Name | Instrument Type | Unit | Description |
---|---|---|---|
lease-request-duration |
Histogram | s |
The duration of rate limiting leases held by HTTP requests on the server. |
Attribute | Type | Description | Examples | Presence |
---|---|---|---|---|
policy |
string | Rate limiting policy name for this request. | MyPolicyName |
Added if the matched route has a rate limiting policy name. |
method |
string | HTTP request method. | GET ; POST ; HEAD |
Added if route endpoint set |
route |
string | The matched route | {controller}/{action}/{id?} |
Added if route endpoint set |
current-requests-queued
Name | Instrument Type | Unit | Description |
---|---|---|---|
current-requests-queued |
UpDownCounter | {request} |
Number of HTTP requests that are currently queued, waiting to acquire a rate limiting lease. |
Attribute | Type | Description | Examples | Presence |
---|---|---|---|---|
policy |
string | Rate limiting policy name for this request. | MyPolicyName |
Added if the matched route has a rate limiting policy name. |
method |
string | HTTP request method. | GET ; POST ; HEAD |
Added if route endpoint set |
route |
string | The matched route | {controller}/{action}/{id?} |
Added if route endpoint set |
queued-request-duration
Name | Instrument Type | Unit | Description |
---|---|---|---|
queued-request-duration |
Histogram | s |
The duration of requests in a queue, waiting to acquire a rate limiting lease. |
Attribute | Type | Description | Examples | Presence |
---|---|---|---|---|
policy |
string | Rate limiting policy name for this request. | MyPolicyName |
Added if the matched route has a rate limiting policy name. |
method |
string | HTTP request method. | GET ; POST ; HEAD |
Added if route endpoint set |
route |
string | The matched route | {controller}/{action}/{id?} |
Added if route endpoint set |
lease-failed-requests
Name | Instrument Type | Unit | Description |
---|---|---|---|
lease-failed-requests |
Counter | {request} |
Number of HTTP requests that failed to acquire a rate limiting lease. Requests could be rejected by global or endpoint rate limiting policies. Or the request could be canceled while waiting for the lease. |
Attribute | Type | Description | Examples | Presence |
---|---|---|---|---|
reason |
string | Reason why acquiring the lease failed. | GlobalLimiter ; EndpointLimiter ; RequestCanceled |
Always. |
policy |
string | Rate limiting policy name for this request. | MyPolicyName |
Added if the matched route has a rate limiting policy name. |
method |
string | HTTP request method. | GET ; POST ; HEAD |
Added if route endpoint set |
route |
string | The matched route | {controller}/{action}/{id?} |
Added if route endpoint set |