Adjust System.Net.Http metrics#89809
Merged
antonfirsov merged 10 commits intodotnet:mainfrom Aug 3, 2023
Merged
Conversation
|
Tagging subscribers to this area: @dotnet/ncl Issue DetailsAdjust System.Net.Http metrics naming and semantics according to the outcome of the discussion in lmolkova/semantic-conventions#1: Contributes to #89093.
|
antonfirsov
commented
Aug 1, 2023
Comment on lines
+272
to
311
| [ConditionalFact(typeof(SocketsHttpHandler), nameof(SocketsHttpHandler.IsSupported))] | ||
| public async Task ActiveRequests_InstrumentEnabledAfterSending_NotRecorded() | ||
| { | ||
| SemaphoreSlim instrumentEnabledSemaphore = new SemaphoreSlim(0); | ||
| if (UseVersion == HttpVersion.Version30) | ||
| { | ||
| return; // This test depends on ConnectCallback. | ||
| } | ||
|
|
||
| TaskCompletionSource connectionStarted = new TaskCompletionSource(); | ||
|
|
||
| await LoopbackServerFactory.CreateClientAndServerAsync(async uri => | ||
| { | ||
| using HttpMessageInvoker client = CreateHttpMessageInvoker(); | ||
| GetUnderlyingSocketsHttpHandler(Handler).ConnectCallback = async (ctx, cancellationToken) => | ||
| { | ||
| connectionStarted.SetResult(); | ||
| Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true }; | ||
| try | ||
| { | ||
| await socket.ConnectAsync(ctx.DnsEndPoint, cancellationToken); | ||
| return new NetworkStream(socket, ownsSocket: true); | ||
| } | ||
| catch | ||
| { | ||
| socket.Dispose(); | ||
| throw; | ||
| } | ||
| }; | ||
|
|
||
| // Enable recording request-duration to test the path with metrics enabled. | ||
| using InstrumentRecorder<double> unrelatedRecorder = SetupInstrumentRecorder<double>(InstrumentNames.RequestDuration); | ||
|
|
||
| using HttpRequestMessage request = new(HttpMethod.Get, uri) { Version = UseVersion }; | ||
| Task<HttpResponseMessage> clientTask = SendAsync(client, request); | ||
| await Task.Delay(100); | ||
| using InstrumentRecorder<long> recorder = new(Handler.MeterFactory, InstrumentNames.CurrentRequests); | ||
| instrumentEnabledSemaphore.Release(); | ||
|
|
||
| Task<HttpResponseMessage> clientTask = Task.Run(() => SendAsync(client, request)); | ||
| await connectionStarted.Task; | ||
| using InstrumentRecorder<long> recorder = new(Handler.MeterFactory, InstrumentNames.ActiveRequests); | ||
| using HttpResponseMessage response = await clientTask; | ||
|
|
||
| Assert.Empty(recorder.GetMeasurements()); | ||
| }, async server => |
Contributor
Author
There was a problem hiding this comment.
This fixes #89451 by making the test deterministic.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This was referenced Aug 2, 2023
MihaZupan
approved these changes
Aug 2, 2023
src/libraries/System.Net.Http/src/System/Net/Http/Metrics/MetricsHandler.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Metrics/MetricsHandler.cs
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
Contributor
Author
|
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
Author
|
/azp run runtime |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
Author
|
All CI failures are unrelated. |
lmolkova
reviewed
Aug 3, 2023
| _ => $"HTTP/{httpVersion.Major}.{httpVersion.Minor}" | ||
| (1, 0) => "1.0", | ||
| (1, 1) => "1.1", | ||
| (2, 0) => "2.0", |
Contributor
Author
There was a problem hiding this comment.
Yup I will open a follow-up PR.
antonfirsov
added a commit
that referenced
this pull request
Aug 3, 2023
This was
linked to
issues
Aug 4, 2023
noahfalk
reviewed
Aug 4, 2023
Member
noahfalk
left a comment
There was a problem hiding this comment.
Sorry I was delayed with some other work, this looked good but I noticed two instruments are missing their units.
| name: "http-client-current-idle-connections", | ||
| description: "Number of outbound HTTP connections that are currently idle on the client."); | ||
| public readonly UpDownCounter<long> OpenConnections = meter.CreateUpDownCounter<long>( | ||
| name: "http.client.open_connections", |
| _currentRequests = meter.CreateUpDownCounter<long>( | ||
| "http-client-current-requests", | ||
| _activeRequests = meter.CreateUpDownCounter<long>( | ||
| "http.client.active_requests", |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Adjust System.Net.Http metrics naming and semantics according to the outcome of the discussion in lmolkova/semantic-conventions#1:
https://github.com/lmolkova/semantic-conventions/blob/dotnet8-metrics/docs/dotnet/dotnet-http-metrics.md
Contributes to #89093.
Fixes #89451.