1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using Microsoft . AspNetCore . Connections ;
4
5
using Microsoft . Extensions . Metrics ;
5
6
using System . Diagnostics ;
6
7
using System . Diagnostics . Metrics ;
@@ -24,13 +25,6 @@ internal sealed class KestrelMetrics
24
25
private readonly Histogram < double > _tlsHandshakeDuration ;
25
26
private readonly UpDownCounter < long > _currentTlsHandshakesCounter ;
26
27
27
- public bool CurrentConnectionsCounterEnabled => _currentConnectionsCounter . Enabled ;
28
- public bool ConnectionDurationEnabled => _connectionDuration . Enabled ;
29
- public bool QueuedConnectionsCounterEnabled => _queuedConnectionsCounter . Enabled ;
30
- public bool QueuedRequestsCounterEnabled => _queuedRequestsCounter . Enabled ;
31
- public bool CurrentUpgradedRequestsCounterEnabled => _currentUpgradedRequestsCounter . Enabled ;
32
- public bool CurrentTlsHandshakesCounterEnabled => _currentTlsHandshakesCounter . Enabled ;
33
-
34
28
public KestrelMetrics ( IMeterFactory meterFactory )
35
29
{
36
30
_meter = meterFactory . CreateMeter ( MeterName ) ;
@@ -296,9 +290,15 @@ private static void InitializeConnectionTags(ref TagList tags, in ConnectionMetr
296
290
if ( metricsContext . ConnectionContext . LocalEndPoint is { } localEndpoint )
297
291
{
298
292
// TODO: Improve getting string allocation for endpoint. Currently allocates.
299
- // Possible solution is to cache in the endpoint: https://github.com/dotnet/runtime/issues/84515
300
- // Alternatively, add cache to ConnectionContext.
293
+ // Considering adding a way to cache on ConnectionContext.
301
294
tags . Add ( "endpoint" , localEndpoint . ToString ( ) ) ;
302
295
}
303
296
}
297
+
298
+ public ConnectionMetricsContext CreateContext ( BaseConnectionContext connection )
299
+ {
300
+ return new ConnectionMetricsContext ( connection ,
301
+ _currentConnectionsCounter . Enabled , _connectionDuration . Enabled , _queuedConnectionsCounter . Enabled ,
302
+ _queuedRequestsCounter . Enabled , _currentUpgradedRequestsCounter . Enabled , _currentTlsHandshakesCounter . Enabled ) ;
303
+ }
304
304
}
0 commit comments