Skip to content

Commit 5a0c097

Browse files
authored
Added some kestrel event counters (#21649)
* Added some kestrel event counters - Connection queue length - This is the amount of connections accepted and queued in the thread pool. - Connection count - The number of connections - Total connections - The total number of connections ever connected. - Connection Rate - Connections per second * Added TLS counters - Current TLS handshakes - Total TLS handshakes - Failed TLS handshakes - TLS handshake per second * Added HTTP/2 queue length counter * Improve the event information - Add TLS version to handshake events - Add HTTP version to request queue events - Renamed HTTP/2 request queue length to http request queue Contributes to #4769
1 parent dfb126d commit 5a0c097

13 files changed

+310
-21
lines changed

src/Servers/Kestrel/Core/src/Internal/ConnectionDispatcher.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ async Task AcceptConnectionsAsync()
6161
_transportConnectionManager.AddConnection(id, kestrelConnection);
6262

6363
Log.ConnectionAccepted(connection.ConnectionId);
64+
KestrelEventSource.Log.ConnectionQueuedStart(connection);
6465

6566
ThreadPool.UnsafeQueueUserWorkItem(kestrelConnection, preferLocal: false);
6667
}

src/Servers/Kestrel/Core/src/Internal/Http/Http1Connection.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ public Http1Connection(HttpConnectionContext context)
7676

7777
protected override void OnRequestProcessingEnded()
7878
{
79+
if (IsUpgraded)
80+
{
81+
KestrelEventSource.Log.RequestUpgradedStop(this);
82+
83+
ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne();
84+
}
85+
7986
TimeoutControl.StartDrainTimeout(MinResponseDataRate, ServerOptions.Limits.MaxResponseBufferSize);
8087

8188
// Prevent RequestAborted from firing. Free up unneeded feature references.

src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.FeatureCollection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ async Task<Stream> IHttpUpgradeFeature.UpgradeAsync()
293293

294294
IsUpgraded = true;
295295

296+
KestrelEventSource.Log.RequestUpgradedStart(this);
297+
296298
ConnectionFeatures.Get<IDecrementConcurrentConnectionCountFeature>()?.ReleaseConnection();
297299

298300
StatusCode = StatusCodes.Status101SwitchingProtocols;

src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public string TraceIdentifier
136136
public int LocalPort { get; set; }
137137
public string Scheme { get; set; }
138138
public HttpMethod Method { get; set; }
139+
public string MethodText => ((IHttpRequestFeature)this).Method;
139140
public string PathBase { get; set; }
140141

141142
public string Path { get; set; }

src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ private void StartStream()
10021002
throw;
10031003
}
10041004

1005+
KestrelEventSource.Log.RequestQueuedStart(_currentHeadersStream, AspNetCore.Http.HttpProtocol.Http2);
10051006
// Must not allow app code to block the connection handling loop.
10061007
ThreadPool.UnsafeQueueUserWorkItem(_currentHeadersStream, preferLocal: false);
10071008
}

src/Servers/Kestrel/Core/src/Internal/Http2/Http2StreamOfT.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using Microsoft.AspNetCore.Hosting.Server;
66
using Microsoft.AspNetCore.Hosting.Server.Abstractions;
7+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
78

89
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
910
{
@@ -19,6 +20,7 @@ public Http2Stream(IHttpApplication<TContext> application, Http2StreamContext co
1920

2021
public override void Execute()
2122
{
23+
KestrelEventSource.Log.RequestQueuedStop(this, AspNetCore.Http.HttpProtocol.Http2);
2224
// REVIEW: Should we store this in a field for easy debugging?
2325
_ = ProcessRequestsAsync(_application);
2426
}

src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ internal async Task InnerProcessRequestsAsync<TContext>(IHttpApplication<TContex
243243
{
244244
_streams[streamId] = http3Stream;
245245
}
246+
KestrelEventSource.Log.RequestQueuedStart(stream, AspNetCore.Http.HttpProtocol.Http3);
246247
ThreadPool.UnsafeQueueUserWorkItem(stream, preferLocal: false);
247248
}
248249
}

src/Servers/Kestrel/Core/src/Internal/Http3/Http3StreamOfT.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.AspNetCore.Hosting.Server;
55
using Microsoft.AspNetCore.Hosting.Server.Abstractions;
6+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
67

78
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3
89
{
@@ -17,6 +18,8 @@ public Http3Stream(IHttpApplication<TContext> application, Http3Connection conne
1718

1819
public override void Execute()
1920
{
21+
KestrelEventSource.Log.RequestQueuedStop(this, AspNetCore.Http.HttpProtocol.Http3);
22+
2023
if (_requestHeaderParsingState == Http3Stream.RequestHeaderParsingState.Ready)
2124
{
2225
_ = ProcessRequestAsync(_application);

src/Servers/Kestrel/Core/src/Internal/HttpConnection.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,6 @@ public async Task ProcessRequestsAsync<TContext>(IHttpApplication<TContext> http
107107
{
108108
Log.LogCritical(0, ex, $"Unexpected exception in {nameof(HttpConnection)}.{nameof(ProcessRequestsAsync)}.");
109109
}
110-
finally
111-
{
112-
if (_http1Connection?.IsUpgraded == true)
113-
{
114-
_context.ServiceContext.ConnectionManager.UpgradedConnectionCount.ReleaseOne();
115-
}
116-
}
117110
}
118111

119112
// For testing only

src/Servers/Kestrel/Core/src/Internal/Infrastructure/KestrelConnectionOfT.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ internal async Task ExecuteAsync()
4040

4141
try
4242
{
43+
KestrelEventSource.Log.ConnectionQueuedStop(connectionContext);
44+
4345
Logger.ConnectionStart(connectionContext.ConnectionId);
4446
KestrelEventSource.Log.ConnectionStart(connectionContext);
4547

0 commit comments

Comments
 (0)