-
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
Microsoft.AspNetCore.RateLimiting metrics #47745
Comments
@Tratcher @davidfowl @noahfalk @tarekgh @samsp-msft @joperezr Metrics counters for |
Shouldn't the route template be a dimension? |
If an endpoint has a policy name then that could be used to identify the endpoint. But yes, |
Feels like that would be a useful thing to add for any meter in the pipeline that is endpoint aware. |
If we add the ability for multiple leases to be acquired by a single request, how will that be displayed by the metrics? Similarly with |
A single request can already acquire multiple leases because of global + endpoint limiters both being acquired. Also, The counters specifically focus on requests rather than leases. Perhaps if lower-level rate limiting adds metrics then it could record that level of information. One potential area of confusion is Maybe the |
That's not what I meant. A potential future feature in the middleware could be to add "costs" to endpoints, so instead of |
Is that Do you imagine that an endpoint could specify a number? e.g. It could get added as a tag to all the counters like the policy name. |
Yeah, something like that. Although, I think there is someone asking to add additional permit cost after the request is done being processed. Which would be problematic since the tags need to match for start and end?
Would that start getting close to cardinality explosion? Now you can have any combination of policy and permit count cost. |
We're adding the route as tag, so there is a separate value per route already. Each route only has one policy and permit count. "route + policy + permit count" will almost always line up so including the policy and permit count doesn't make it any worse. |
API Review Notes
Microsoft.AspNetCore.RateLimiting
|
Name | Instrument Type | Unit | Description |
---|---|---|---|
current-acquired-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 |
acquired-lease-request-duration
Name | Instrument Type | Unit | Description |
---|---|---|---|
acquired-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 |
reason |
string | Reason why acquiring the lease failed. | GlobalLimiter ; EndpointLimiter ; RequestCanceled |
If failed. |
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 |
Here is the final set of names after an email suggestion from @Tratcher. It's a subtle variation on the original proposal which used "lease-requests" instead of "leased-requests". Moving "requests" to the end of "current-queued-requests" also sounds more consistent. Microsoft.AspNetCore.RateLimiting
|
Name | Instrument Type | Unit | Description |
---|---|---|---|
current-leased-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 |
leased-request-duration
Name | Instrument Type | Unit | Description |
---|---|---|---|
leased-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-queued-requests
Name | Instrument Type | Unit | Description |
---|---|---|---|
current-queued-requests |
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 |
reason |
string | Reason why acquiring the lease failed. | GlobalLimiter ; EndpointLimiter ; RequestCanceled |
If failed. |
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 |
API approved!
Done with #47758 |
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.Proposed API
Microsoft.AspNetCore.RateLimiting
current-lease-requests
current-lease-requests
{request}
policy
MyPolicyName
method
GET
;POST
;HEAD
route
{controller}/{action}/{id?}
lease-request-duration
lease-request-duration
s
policy
MyPolicyName
method
GET
;POST
;HEAD
route
{controller}/{action}/{id?}
current-requests-queued
current-requests-queued
{request}
policy
MyPolicyName
method
GET
;POST
;HEAD
route
{controller}/{action}/{id?}
queued-request-duration
queued-request-duration
s
policy
MyPolicyName
method
GET
;POST
;HEAD
route
{controller}/{action}/{id?}
lease-failed-requests
lease-failed-requests
{request}
reason
GlobalLimiter
;EndpointLimiter
;RequestCanceled
policy
MyPolicyName
method
GET
;POST
;HEAD
route
{controller}/{action}/{id?}
Usage Examples
Alternative Designs
Risks
The text was updated successfully, but these errors were encountered: