Skip to content

Commit f67beca

Browse files
[release/9.0] Readd DiagnosticSource to KestrelServerImpl (#60202)
* Readd DiagnosticSource to KestrelServerImpl * null --------- Co-authored-by: Brennan <[email protected]>
1 parent 8b2b207 commit f67beca

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ public KestrelServerImpl(
3939
IEnumerable<IMultiplexedConnectionListenerFactory> multiplexedFactories,
4040
IHttpsConfigurationService httpsConfigurationService,
4141
ILoggerFactory loggerFactory,
42+
DiagnosticSource? diagnosticSource,
4243
KestrelMetrics metrics)
43-
: this(transportFactories, multiplexedFactories, httpsConfigurationService, CreateServiceContext(options, loggerFactory, diagnosticSource: null, metrics))
44+
: this(transportFactories, multiplexedFactories, httpsConfigurationService, CreateServiceContext(options, loggerFactory, diagnosticSource, metrics))
4445
{
4546
}
4647

@@ -111,7 +112,8 @@ private static ServiceContext CreateServiceContext(IOptions<KestrelServerOptions
111112

112113
public KestrelServerOptions Options => ServiceContext.ServerOptions;
113114

114-
private ServiceContext ServiceContext { get; }
115+
// Internal for testing
116+
internal ServiceContext ServiceContext { get; }
115117

116118
private KestrelTrace Trace => ServiceContext.Log;
117119

src/Servers/Kestrel/Core/src/KestrelServer.cs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public KestrelServer(IOptions<KestrelServerOptions> options, IConnectionListener
3636
Array.Empty<IMultiplexedConnectionListenerFactory>(),
3737
new SimpleHttpsConfigurationService(),
3838
loggerFactory,
39+
diagnosticSource: null,
3940
new KestrelMetrics(new DummyMeterFactory()));
4041
}
4142

src/Servers/Kestrel/Core/test/KestrelServerTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ private static KestrelServerImpl CreateKestrelServer(
309309
multiplexedFactories,
310310
httpsConfigurationService,
311311
loggerFactory ?? new LoggerFactory(new[] { new KestrelTestLoggerProvider() }),
312+
diagnosticSource: null,
312313
metrics ?? new KestrelMetrics(new TestMeterFactory()));
313314
}
314315

src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections;
5+
using System.IO.Pipelines;
56
using Microsoft.AspNetCore.Connections;
67
using Microsoft.AspNetCore.Hosting;
78
using Microsoft.AspNetCore.Hosting.Server;
89
using Microsoft.AspNetCore.Server.Kestrel.Core;
10+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
911
using Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Internal;
1012
using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets;
1113
using Microsoft.Extensions.DependencyInjection;
@@ -107,6 +109,11 @@ public void ServerIsKestrelServerImpl()
107109
.UseKestrel()
108110
.Configure(app => { });
109111

110-
Assert.IsType<KestrelServerImpl>(hostBuilder.Build().Services.GetService<IServer>());
112+
var server = Assert.IsType<KestrelServerImpl>(hostBuilder.Build().Services.GetService<IServer>());
113+
114+
Assert.NotNull(server.ServiceContext.DiagnosticSource);
115+
Assert.IsType<KestrelMetrics>(server.ServiceContext.Metrics);
116+
Assert.Equal(PipeScheduler.ThreadPool, server.ServiceContext.Scheduler);
117+
Assert.Equal(TimeProvider.System, server.ServiceContext.TimeProvider);
111118
}
112119
}

0 commit comments

Comments
 (0)