-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add routing metrics #48637
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 routing metrics #48637
Changes from all commits
2f4574f
327983b
0b040cb
e820c6e
d626403
47c95d3
80cc820
94cc768
d7765a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.Metrics; | ||
using Microsoft.Extensions.Diagnostics.Metrics; | ||
|
||
namespace Microsoft.AspNetCore.Routing; | ||
|
||
internal sealed class RoutingMetrics | ||
{ | ||
public const string MeterName = "Microsoft.AspNetCore.Routing"; | ||
|
||
private readonly Meter _meter; | ||
private readonly Counter<long> _matchSuccessCounter; | ||
private readonly Counter<long> _matchFailureCounter; | ||
|
||
public RoutingMetrics(IMeterFactory meterFactory) | ||
{ | ||
_meter = meterFactory.Create(MeterName); | ||
|
||
_matchSuccessCounter = _meter.CreateCounter<long>( | ||
"routing-match-success", | ||
description: "Number of requests that successfully matched to an endpoint."); | ||
|
||
_matchFailureCounter = _meter.CreateCounter<long>( | ||
"routing-match-failure", | ||
description: "Number of requests that failed to match to an endpoint. An unmatched request may be handled by later middleware, such as the static files or authentication middleware."); | ||
} | ||
|
||
public bool MatchSuccessCounterEnabled => _matchSuccessCounter.Enabled; | ||
|
||
public void MatchSuccess(string route, bool isFallback) | ||
{ | ||
_matchSuccessCounter.Add(1, | ||
new KeyValuePair<string, object?>("route", route), | ||
new KeyValuePair<string, object?>("fallback", isFallback)); | ||
} | ||
JamesNK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public void MatchFailure() | ||
{ | ||
_matchFailureCounter.Add(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to be clear in the docs that there are lots of requests handled by middleware that will be reported as route match failures. E.g. static files, auth callbacks, etc. I wonder if that will make this counter more noise than value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tekian ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can you show an example of this? I'm not sure how desirable this is. We need to verify this for all sorts of applications. (blazor to apis) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about this counter more, and I think we should keep it.
I'll make these changes and then merge this PR soon. If I don't hear feedback, I'll assume people are okay with this. It's not an end to discussion; I don't want to hold up metrics progress towards done. |
||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.