Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ protected void MarkConnectionAsEstablished(Activity? connectionSetupActivity, IP
protocol,
_pool.IsSecure ? "https" : "http",
_pool.TelemetryServerAddress,
_pool.OriginAuthority.Port,
remoteEndPoint?.Address?.ToString());
_pool.OriginAuthority.Port);

_connectionMetrics.ConnectionEstablished();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ internal sealed class ConnectionMetrics
private readonly object _schemeTag;
private readonly object _hostTag;
private readonly object _portTag;
private readonly object? _peerAddressTag;
private bool _currentlyIdle;

public ConnectionMetrics(SocketsHttpHandlerMetrics metrics, string protocolVersion, string scheme, string host, int port, string? peerAddress)
public ConnectionMetrics(SocketsHttpHandlerMetrics metrics, string protocolVersion, string scheme, string host, int port)
{
_metrics = metrics;
_openConnectionsEnabled = _metrics.OpenConnections.Enabled;
_protocolVersionTag = protocolVersion;
_schemeTag = scheme;
_hostTag = host;
_portTag = DiagnosticsHelper.GetBoxedInt32(port);
_peerAddressTag = peerAddress;
}

// TagList is a huge struct, so we avoid storing it in a field to reduce the amount we allocate on the heap.
Expand All @@ -38,11 +36,6 @@ private TagList GetTags()
tags.Add("server.address", _hostTag);
tags.Add("server.port", _portTag);

if (_peerAddressTag is not null)
{
tags.Add("network.peer.address", _peerAddressTag);
}

return tags;
}

Expand Down
27 changes: 5 additions & 22 deletions src/libraries/System.Net.Http/tests/FunctionalTests/MetricsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,6 @@ protected HttpMetricsTestBase(ITestOutputHelper output) : base(output)
}


private static void VerifyPeerAddress(KeyValuePair<string, object?>[] tags, IPAddress[] validPeerAddresses = null)
{
string ipString = (string)tags.Single(t => t.Key == "network.peer.address").Value;
validPeerAddresses ??= [IPAddress.Loopback.MapToIPv6(), IPAddress.Loopback, IPAddress.IPv6Loopback];
IPAddress ip = IPAddress.Parse(ipString);
Assert.Contains(ip, validPeerAddresses);
}


protected static void VerifyRequestDuration(Measurement<double> measurement,
Uri uri,
Version? protocolVersion = null,
Expand Down Expand Up @@ -127,29 +118,23 @@ protected static void VerifyActiveRequests(string instrumentName, long measureme
Assert.Equal(method, tags.Single(t => t.Key == "http.request.method").Value);
}

protected static void VerifyOpenConnections(string actualName, object measurement, KeyValuePair<string, object?>[] tags, long expectedValue, Uri uri, Version? protocolVersion, string state, IPAddress[] validPeerAddresses = null)
protected static void VerifyOpenConnections(string actualName, object measurement, KeyValuePair<string, object?>[] tags, long expectedValue, Uri uri, Version? protocolVersion, string state)
{
Assert.Equal(InstrumentNames.OpenConnections, actualName);
Assert.Equal(expectedValue, Assert.IsType<long>(measurement));
VerifySchemeHostPortTags(tags, uri);
VerifyTag(tags, "network.protocol.version", GetVersionString(protocolVersion));
VerifyTag(tags, "http.connection.state", state);
VerifyPeerAddress(tags, validPeerAddresses);
}
Comment thread
ManickaP marked this conversation as resolved.
Comment thread
ManickaP marked this conversation as resolved.

protected static void VerifyConnectionDuration(string instrumentName, object measurement, KeyValuePair<string, object?>[] tags, Uri uri, Version? protocolVersion, IPAddress[] validPeerAddresses = null)
protected static void VerifyConnectionDuration(string instrumentName, object measurement, KeyValuePair<string, object?>[] tags, Uri uri, Version? protocolVersion)
{
Assert.Equal(InstrumentNames.ConnectionDuration, instrumentName);
double value = Assert.IsType<double>(measurement);

// This flakes for remote requests on CI.
if (validPeerAddresses is null)
{
Assert.InRange(value, double.Epsilon, 60);
}
Assert.InRange(value, double.Epsilon, 60);
VerifySchemeHostPortTags(tags, uri);
VerifyTag(tags, "network.protocol.version", GetVersionString(protocolVersion));
Comment thread
ManickaP marked this conversation as resolved.
VerifyPeerAddress(tags, validPeerAddresses);
}
Comment thread
ManickaP marked this conversation as resolved.

protected static void VerifyTimeInQueue(string instrumentName, object measurement, KeyValuePair<string, object?>[] tags, Uri uri, Version? protocolVersion, string method = "GET")
Expand Down Expand Up @@ -384,8 +369,6 @@ public async Task ExternalServer_DurationMetrics_Recorded()
Uri uri = UseVersion == HttpVersion.Version11
? Test.Common.Configuration.Http.RemoteHttp11Server.EchoUri
: Test.Common.Configuration.Http.RemoteHttp2Server.EchoUri;
IPAddress[] addresses = await Dns.GetHostAddressesAsync(uri.Host);
addresses = addresses.Union(addresses.Select(a => a.MapToIPv6())).ToArray();

using (HttpMessageInvoker client = CreateHttpMessageInvoker())
{
Expand All @@ -398,9 +381,9 @@ public async Task ExternalServer_DurationMetrics_Recorded()

VerifyRequestDuration(Assert.Single(requestDurationRecorder.GetMeasurements()), uri, UseVersion, 200, "GET");
Measurement<double> cd = Assert.Single(connectionDurationRecorder.GetMeasurements());
VerifyConnectionDuration(InstrumentNames.ConnectionDuration, cd.Value, cd.Tags.ToArray(), uri, UseVersion, addresses);
VerifyConnectionDuration(InstrumentNames.ConnectionDuration, cd.Value, cd.Tags.ToArray(), uri, UseVersion);
Measurement<long> oc = openConnectionsRecorder.GetMeasurements().First();
VerifyOpenConnections(InstrumentNames.OpenConnections, oc.Value, oc.Tags.ToArray(), 1, uri, UseVersion, "idle", addresses);
VerifyOpenConnections(InstrumentNames.OpenConnections, oc.Value, oc.Tags.ToArray(), 1, uri, UseVersion, "idle");
Comment thread
ManickaP marked this conversation as resolved.
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
Expand Down
Loading