Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
955f83b
[release/9.0-rc1] Update dependencies from dotnet/efcore, dotnet/runt…
dotnet-maestro[bot] Aug 20, 2024
5954d02
[release/9.0-rc1] Update dependencies from dotnet/runtime (#57435)
dotnet-maestro[bot] Aug 21, 2024
7270086
Update dependencies from https://github.com/dotnet/efcore build 20240…
dotnet-maestro[bot] Aug 22, 2024
c75a99c
Update dependencies from https://github.com/dotnet/extensions build 2…
dotnet-maestro[bot] Aug 26, 2024
9f52b5c
[release/9.0] Update dependencies from dotnet/arcade (#57446)
dotnet-maestro[bot] Aug 26, 2024
2b865e3
Quarantine two CircuitTests (#57606)
github-actions[bot] Aug 30, 2024
6b64c4c
Update dependencies from https://github.com/dotnet/runtime build 2024…
dotnet-maestro[bot] Aug 31, 2024
779d2cf
Update dependencies from https://github.com/dotnet/efcore build 20240…
dotnet-maestro[bot] Aug 31, 2024
66b86e5
Update dependencies from https://github.com/dotnet/runtime build 2024…
dotnet-maestro[bot] Sep 1, 2024
74bc395
Update dependencies from https://github.com/dotnet/efcore build 20240…
dotnet-maestro[bot] Sep 1, 2024
280c613
Merge pull request #57632 from dotnet/darc-release/9.0-rc1-c5c3a56e-f…
dkurepa Sep 2, 2024
c88b5f5
Merge branch 'release/9.0' into merge/release/9.0-rc1-to-release/9.0
wtgodbe Sep 3, 2024
36cdc65
Merge pull request #57659 from dotnet/merge/release/9.0-rc1-to-releas…
wtgodbe Sep 3, 2024
e31c6a4
[release/9.0] Fix duplicate error.type on kestrel.connection.duration…
github-actions[bot] Sep 3, 2024
dc3923e
Merge branch 'main' into merge/release/9.0-to-main
wtgodbe Sep 3, 2024
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
Prev Previous commit
Next Next commit
[release/9.0] Fix duplicate error.type on kestrel.connection.duration (
…#57581)

* Fix duplicate error.type on kestrel.connection.duration

* Comment

* Clean up

---------

Co-authored-by: James Newton-King <[email protected]>
  • Loading branch information
github-actions[bot] and JamesNK authored Sep 3, 2024
commit e31c6a473e8847af2387e6873b6dea48a57302be
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ private void ConnectionStopCore(ConnectionMetricsContext metricsContext, Excepti

if (metricsContext.ConnectionDurationEnabled)
{
// Add custom tags for duration.
if (customTags != null)
{
for (var i = 0; i < customTags.Count; i++)
{
tags.Add(customTags[i]);
}
}

// Check if there is an end reason on the context. For example, the connection could have been aborted by shutdown.
if (metricsContext.ConnectionEndReason is { } reason && TryGetErrorType(reason, out var errorValue))
{
Expand All @@ -130,15 +139,6 @@ private void ConnectionStopCore(ConnectionMetricsContext metricsContext, Excepti
tags.TryAddTag(ErrorTypeAttributeName, exception.GetType().FullName);
}

// Add custom tags for duration.
if (customTags != null)
{
for (var i = 0; i < customTags.Count; i++)
{
tags.Add(customTags[i]);
}
}

var duration = Stopwatch.GetElapsedTime(startTimestamp, currentTimestamp);
_connectionDuration.Record(duration.TotalSeconds, tags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Security.Authentication;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Internal;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.Metrics;
using Microsoft.Extensions.Diagnostics.Metrics.Testing;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
Expand All @@ -23,6 +23,72 @@ namespace Interop.FunctionalTests.Http2;
[Collection(nameof(NoParallelCollection))]
public class Http2RequestTests : LoggedTest
{
[Fact]
public async Task InvalidHandshake_MetricsHasErrorType()
{
// Arrange
var builder = CreateHostBuilder(
c =>
{
return Task.CompletedTask;
},
protocol: HttpProtocols.Http2,
plaintext: true);

using (var host = builder.Build())
{
var meterFactory = host.Services.GetRequiredService<IMeterFactory>();

// Use MeterListener for this test because we want to check that a single error.type tag is added.
// MetricCollector can't be used for this because it stores tags in a dictionary and overwrites values.
var measurementTcs = new TaskCompletionSource<Measurement<double>>();
var meterListener = new MeterListener();
meterListener.InstrumentPublished = (instrument, meterListener) =>
{
if (instrument.Meter.Scope == meterFactory &&
instrument.Meter.Name == "Microsoft.AspNetCore.Server.Kestrel" &&
instrument.Name == "kestrel.connection.duration")
{
meterListener.EnableMeasurementEvents(instrument);
meterListener.SetMeasurementEventCallback<double>((Instrument instrument, double measurement, ReadOnlySpan<KeyValuePair<string, object>> tags, object state) =>
{
measurementTcs.SetResult(new Measurement<double>(measurement, tags));
});
}
};
meterListener.Start();

await host.StartAsync();
var client = HttpHelpers.CreateClient(maxResponseHeadersLength: 1024);

// Act
using var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
socket.LingerState = new LingerOption(false, 0);

socket.Connect(IPAddress.Loopback, host.GetPort());
socket.Send(new byte[1024 * 16]);

// Wait for measurement to be available.
var measurement = await measurementTcs.Task.DefaultTimeout();

// Assert
Assert.True(measurement.Value > 0);

var tags = measurement.Tags.ToArray();
Assert.Equal("http", (string)tags.Single(t => t.Key == "network.protocol.name").Value);
Assert.Equal("2", (string)tags.Single(t => t.Key == "network.protocol.version").Value);
Assert.Equal("tcp", (string)tags.Single(t => t.Key == "network.transport").Value);
Assert.Equal("ipv4", (string)tags.Single(t => t.Key == "network.type").Value);
Assert.Equal("127.0.0.1", (string)tags.Single(t => t.Key == "server.address").Value);
Assert.Equal(host.GetPort(), (int)tags.Single(t => t.Key == "server.port").Value);
Assert.Equal("invalid_handshake", (string)tags.Single(t => t.Key == "error.type").Value);

socket.Close();

await host.StopAsync();
}
}

[Fact]
public async Task GET_Metrics_HttpProtocolAndTlsSet()
{
Expand Down
Loading