-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[HTTP] High cardinality metrics to observable #131275
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
Open
ManickaP
wants to merge
10
commits into
dotnet:main
Choose a base branch
from
ManickaP:http-metrics-observable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5d44a87
Move to observable counterpart for high cardinality counters
ManickaP eea896c
Fixed ActiveRequests_Success_Recorded test
ManickaP 0c6d611
Fixed ActiveRequests_Redirect_RecordedForEachHttpSpan test
ManickaP 7b3a27d
Fixed AllSocketsHttpHandlerCounters_Success_Recorded test
ManickaP 5624f75
Fixed ExternalServer_DurationMetrics_Recorded test
ManickaP 877451e
Fix missing peerAddress in hash code, removed unused namespace.
ManickaP 69f4502
Feedback
ManickaP 46ae121
Copilot feedback numero 146
ManickaP ab871f7
Fix H/3 connection counter
ManickaP 0869694
Potential fix for pull request finding
ManickaP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,11 @@ internal sealed class ConnectionMetrics | |
| { | ||
| private readonly SocketsHttpHandlerMetrics _metrics; | ||
| private readonly bool _openConnectionsEnabled; | ||
| private readonly object _protocolVersionTag; | ||
| private readonly object _schemeTag; | ||
| private readonly object _hostTag; | ||
| private readonly object _portTag; | ||
| private readonly object? _peerAddressTag; | ||
| private readonly string _protocolVersionTag; | ||
| private readonly string _schemeTag; | ||
| private readonly string _hostTag; | ||
| private readonly int _portTag; | ||
| private readonly string? _peerAddressTag; | ||
| private bool _currentlyIdle; | ||
|
|
||
| public ConnectionMetrics(SocketsHttpHandlerMetrics metrics, string protocolVersion, string scheme, string host, int port, string? peerAddress) | ||
|
|
@@ -24,7 +24,7 @@ public ConnectionMetrics(SocketsHttpHandlerMetrics metrics, string protocolVersi | |
| _protocolVersionTag = protocolVersion; | ||
| _schemeTag = scheme; | ||
| _hostTag = host; | ||
| _portTag = DiagnosticsHelper.GetBoxedInt32(port); | ||
| _portTag = port; | ||
| _peerAddressTag = peerAddress; | ||
| } | ||
|
|
||
|
|
@@ -36,7 +36,7 @@ private TagList GetTags() | |
| tags.Add("network.protocol.version", _protocolVersionTag); | ||
| tags.Add("url.scheme", _schemeTag); | ||
| tags.Add("server.address", _hostTag); | ||
| tags.Add("server.port", _portTag); | ||
| tags.Add("server.port", DiagnosticsHelper.GetBoxedInt32(_portTag)); | ||
|
Member
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. is this called often? If so, than reusing a boxed int might save some allocations. but feel free to ignore this.
Member
Author
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. It is reusing the boxed int. |
||
|
|
||
| if (_peerAddressTag is not null) | ||
| { | ||
|
|
@@ -46,45 +46,47 @@ private TagList GetTags() | |
| return tags; | ||
| } | ||
|
|
||
| private static KeyValuePair<string, object?> GetStateTag(bool idle) => new KeyValuePair<string, object?>("http.connection.state", idle ? "idle" : "active"); | ||
| private OpenConnectionsTagKey CreateTagKey(bool idle) => | ||
| new OpenConnectionsTagKey(_protocolVersionTag, _schemeTag, _hostTag, _portTag, idle, _peerAddressTag); | ||
|
|
||
| public void ConnectionEstablished() | ||
| { | ||
| if (_openConnectionsEnabled) | ||
| { | ||
| _currentlyIdle = true; | ||
| TagList tags = GetTags(); | ||
| tags.Add(GetStateTag(idle: true)); | ||
| _metrics.OpenConnections.Add(1, tags); | ||
| lock (this) | ||
| { | ||
| _currentlyIdle = true; | ||
| _metrics.OpenConnectionsTracker.Increment(CreateTagKey(idle: true)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void ConnectionClosed(long durationMs) | ||
| { | ||
| TagList tags = GetTags(); | ||
|
|
||
| if (_metrics.ConnectionDuration.Enabled) | ||
| { | ||
| _metrics.ConnectionDuration.Record(durationMs / 1000d, tags); | ||
| _metrics.ConnectionDuration.Record(durationMs / 1000d, GetTags()); | ||
| } | ||
|
|
||
| if (_openConnectionsEnabled) | ||
| { | ||
| tags.Add(GetStateTag(idle: _currentlyIdle)); | ||
| _metrics.OpenConnections.Add(-1, tags); | ||
| lock (this) | ||
| { | ||
| _metrics.OpenConnectionsTracker.Decrement(CreateTagKey(idle: _currentlyIdle)); | ||
| } | ||
| } | ||
|
ManickaP marked this conversation as resolved.
|
||
| } | ||
|
|
||
| public void IdleStateChanged(bool idle) | ||
| { | ||
| if (_openConnectionsEnabled && _currentlyIdle != idle) | ||
| { | ||
| _currentlyIdle = idle; | ||
| TagList tags = GetTags(); | ||
| tags.Add(GetStateTag(idle: !idle)); | ||
| _metrics.OpenConnections.Add(-1, tags); | ||
| tags[tags.Count - 1] = GetStateTag(idle: idle); | ||
| _metrics.OpenConnections.Add(1, tags); | ||
| lock (this) | ||
| { | ||
| _currentlyIdle = idle; | ||
| _metrics.OpenConnectionsTracker.Decrement(CreateTagKey(idle: !idle)); | ||
| _metrics.OpenConnectionsTracker.Increment(CreateTagKey(idle: idle)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.