Skip to content
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

Adjust System.Net.Http metrics #89809

Merged
merged 10 commits into from
Aug 3, 2023

Conversation

antonfirsov
Copy link
Member

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.

@ghost
Copy link

ghost commented Aug 1, 2023

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

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.

Author: antonfirsov
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

@antonfirsov antonfirsov requested review from noahfalk and a team August 1, 2023 20:30
@antonfirsov antonfirsov added this to the 8.0.0 milestone 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 =>
Copy link
Member Author

@antonfirsov antonfirsov Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes #89451 by making the test deterministic.

@azure-pipelines

This comment was marked as resolved.

@azure-pipelines

This comment was marked as resolved.

@azure-pipelines

This comment was marked as resolved.

@antonfirsov
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@antonfirsov
Copy link
Member Author

/azp run runtime

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@antonfirsov
Copy link
Member Author

All CI failures are unrelated.

@antonfirsov antonfirsov merged commit 82934fd into dotnet:main Aug 3, 2023
151 of 172 checks passed
_ => $"HTTP/{httpVersion.Major}.{httpVersion.Minor}"
(1, 0) => "1.0",
(1, 1) => "1.1",
(2, 0) => "2.0",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @JamesNK uses "2" and "3" for HTTP/2 and HTTP/3 for asp.net core and kestrel, which, I believe, matches their RFCs (HTTP/2, HTTP/3).

can we still unify?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I will open a follow-up PR.

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #90020 PTAL.

_currentRequests = meter.CreateUpDownCounter<long>(
"http-client-current-requests",
_activeRequests = meter.CreateUpDownCounter<long>(
"http.client.active_requests",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit should be "{request}"

@ghost ghost locked as resolved and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants