Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
Adjust DNS metrics#89813
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Adjust DNS metrics #89813
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d7b7d0d
adjust DNS metrics
antonfirsov 3f93209
set the unit to seconds
antonfirsov 15b2ed1
Update src/libraries/System.Net.NameResolution/src/System/Net/NameRes…
antonfirsov 0e8ff4b
simplify NameResolutionTelemetry.BeforeResolution
antonfirsov f24f384
Merge branch 'adjust-dns-metrics-01' of https://github.com/antonfirso…
antonfirsov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
22 changes: 11 additions & 11 deletions
22 src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs
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
40 changes: 7 additions & 33 deletions
40 src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionMetrics.cs
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
45 changes: 36 additions & 9 deletions
45 src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs
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 |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Diagnostics.Tracing; | ||
| using System.Net.Sockets; | ||
| using System.Threading; | ||
| namespace System.Net | ||
| @@ -60,38 +62,40 @@ protected override void OnEventCommand(EventCommandEventArgs command) | ||
| [NonEvent] | ||
| public long BeforeResolution(object hostNameOrAddress) | ||
| { | ||
| // System.Diagnostics.Metrics part | ||
| NameResolutionMetrics.BeforeResolution(hostNameOrAddress, out string? host); | ||
| // System.Diagnostics.Tracing part | ||
| if (IsEnabled()) | ||
| { | ||
| Interlocked.Increment(ref _lookupsRequested); | ||
| Interlocked.Increment(ref _currentLookups); | ||
| if (IsEnabled(EventLevel.Informational, EventKeywords.None)) | ||
| { | ||
| host ??= NameResolutionMetrics.GetHostnameFromStateObject(hostNameOrAddress); | ||
| string host = GetHostnameFromStateObject(hostNameOrAddress); | ||
| ResolutionStart(host); | ||
| } | ||
| return Stopwatch.GetTimestamp(); | ||
| } | ||
| return 0; | ||
| return NameResolutionMetrics.IsEnabled() ? Stopwatch.GetTimestamp() : 0; | ||
| } | ||
| [NonEvent] | ||
| public void AfterResolution(long? startingTimestamp, bool successful) | ||
| public void AfterResolution(object hostNameOrAddress, long? startingTimestamp, bool successful) | ||
| { | ||
| Debug.Assert(startingTimestamp.HasValue); | ||
| if (startingTimestamp == 0) | ||
| { | ||
| return; | ||
| } | ||
| TimeSpan duration = Stopwatch.GetElapsedTime(startingTimestamp.Value); | ||
| if (startingTimestamp != 0) | ||
| if (IsEnabled()) | ||
| { | ||
| Interlocked.Decrement(ref _currentLookups); | ||
| _lookupsDuration?.WriteMetric(Stopwatch.GetElapsedTime(startingTimestamp.Value).TotalMilliseconds); | ||
| _lookupsDuration?.WriteMetric(duration.TotalMilliseconds); | ||
antonfirsov marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (IsEnabled(EventLevel.Informational, EventKeywords.None)) | ||
| { | ||
| @@ -103,6 +107,29 @@ public void AfterResolution(long? startingTimestamp, bool successful) | ||
| ResolutionStop(); | ||
| } | ||
| } | ||
| if (NameResolutionMetrics.IsEnabled()) | ||
| { | ||
| NameResolutionMetrics.AfterResolution(duration, GetHostnameFromStateObject(hostNameOrAddress)); | ||
| } | ||
| } | ||
| private static string GetHostnameFromStateObject(object hostNameOrAddress) | ||
| { | ||
| Debug.Assert(hostNameOrAddress is not null); | ||
| string host = hostNameOrAddress switch | ||
| { | ||
| string h => h, | ||
| KeyValuePair<string, AddressFamily> t => t.Key, | ||
| IPAddress a => a.ToString(), | ||
| KeyValuePair<IPAddress, AddressFamily> t => t.Key.ToString(), | ||
| _ => null! | ||
| }; | ||
| Debug.Assert(host is not null, $"Unknown hostNameOrAddress type: {hostNameOrAddress.GetType().Name}"); | ||
| return host; | ||
| } | ||
| } | ||
| } | ||
18 changes: 9 additions & 9 deletions
18 src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs
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
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.