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

Processing errors adds duplicate error.type diagnostic tags to kestrel.connection.duration in Microsoft.AspNetCore.Server.Kestrel #57558

Closed
1 task done
nsentinel opened this issue Aug 28, 2024 · 2 comments · Fixed by #57561
Assignees
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Comments

@nsentinel
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In case of processing errors, Microsoft.AspNetCore.Server.Kestrel diagnostic metrics contain duplicates of error.type in the output statistics for kestrel.connection.duration, both when viewed by standard diagnostic tools and when publishing values to Prometheus/OpenTelemetry, which leads to failures due to duplication error.

The issue is similar to the situation in #55159.

Examples of publishing to prometheus:

kestrel_connection_duration_seconds_bucket{otel_scope_name="Microsoft.AspNetCore.Server.Kestrel",error_type="connection_reset",error_type="connection_reset",network_protocol_name="http",network_protocol_version="2",network_transport="tcp",network_type="ipv4",server_address="192.168.1.2",server_port="9559",tls_protocol_version="1.2",le="0.1"} 0 1724805383433

kestrel_connection_duration_seconds_bucket{otel_scope_name="Microsoft.AspNetCore.Server.Kestrel",error_type="keep_alive_timeout",error_type="keep_alive_timeout",network_protocol_name="http",network_protocol_version="2",network_transport="tcp",network_type="ipv4",server_address="192.168.1.2",server_port="9559",tls_protocol_version="1.2",le="0.5"} 0 1724805383433

The application works fine with .NET 8, the issue occurs when migrating to .NET 9 Preview 7

Expected Behavior

The tags on the metrics should not be duplicated

Steps To Reproduce

  1. Run the example application below using dotnet run
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", (HttpContext context, CancellationToken _) => Console.WriteLine(context.Connection.RemoteIpAddress));
app.Run();
  1. Attach using dotnet-counters collect -n DuplicateTagRepro Microsoft.AspNetCore.Server.Kestrel (or any other tooling that allows seeing the Microsoft.AspNetCore.Server.Kestrel metrics.

  2. Simulate errors, e.g., by running the following code 1 or more times, adjusting the connection port to match the running application (see step 1)

using System.Net;
using System.Net.Sockets;

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

socket.Connect(IPAddress.Loopback, 62203);
socket.Send("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"u8);
socket.Close();
  1. Observe that metrics now show Microsoft.AspNetCore.Server.Kestrel,kestrel.connection.duration metrics with duplicated error.type=invalid_request_line tags

E.g. Microsoft.AspNetCore.Server.Kestrel,kestrel.connection.duration (s)[error.type=invalid_request_line;error.type=invalid_request_line;network.protocol.name=http;network.protocol.version=1.1;network.transport=tcp;network.type=ipv4;server.address=127.0.0.1;server.port=62203;Percentile=95],Metric,0.00519561767578125

Exceptions (if any)

No response

.NET Version

9.0.100-preview.7.24407.12

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 28, 2024
@JamesNK JamesNK self-assigned this Aug 28, 2024
@JamesNK
Copy link
Member

JamesNK commented Aug 28, 2024

Thanks for filling the issue. I could reproduce it with your sample and I have a fix here: #57561

@nsentinel
Copy link
Author

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants