Uh oh!
There was an error while loading. Please reload this page.
Adjust System.Net.Http metrics - #89809
Conversation
ghost
commented
Aug 1, 2023
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.
|
| [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 => |
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
This comment was marked as resolved.
antonfirsov
commented
Aug 2, 2023
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
antonfirsov
commented
Aug 3, 2023
/azp run runtime |
|
Azure Pipelines successfully started running 1 pipeline(s). |
antonfirsov
commented
Aug 3, 2023
All CI failures are unrelated. |
| _ => $"HTTP/{httpVersion.Major}.{httpVersion.Minor}" | ||
| (1, 0) => "1.0", | ||
| (1, 1) => "1.1", | ||
| (2, 0) => "2.0", |
There was a problem hiding this comment.
Yup I will open a follow-up PR.
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", |
There was a problem hiding this comment.
The unit should be set to "{connection}"
@lmolkova - confirming that is correct and not just some formatting thing in the spec that wasn't intended to be used literally?
| _currentRequests = meter.CreateUpDownCounter<long>( | ||
| "http-client-current-requests", | ||
| _activeRequests = meter.CreateUpDownCounter<long>( | ||
| "http.client.active_requests", |
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.