From 3a7a0475a1d28e75c7d66ced570f4c51485e7014 Mon Sep 17 00:00:00 2001 From: Brennan Date: Thu, 30 Jan 2025 17:41:06 -0800 Subject: [PATCH 1/2] Readd DiagnosticSource to KestrelServerImpl --- .../Kestrel/Core/src/Internal/KestrelServerImpl.cs | 6 ++++-- src/Servers/Kestrel/Core/src/KestrelServer.cs | 1 + src/Servers/Kestrel/Core/test/KestrelServerTests.cs | 1 + .../Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs | 9 ++++++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs b/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs index b8af73a906dd..e618f74be5a6 100644 --- a/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs +++ b/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs @@ -39,8 +39,9 @@ public KestrelServerImpl( IEnumerable multiplexedFactories, IHttpsConfigurationService httpsConfigurationService, ILoggerFactory loggerFactory, + DiagnosticSource diagnosticSource, KestrelMetrics metrics) - : this(transportFactories, multiplexedFactories, httpsConfigurationService, CreateServiceContext(options, loggerFactory, diagnosticSource: null, metrics)) + : this(transportFactories, multiplexedFactories, httpsConfigurationService, CreateServiceContext(options, loggerFactory, diagnosticSource, metrics)) { } @@ -111,7 +112,8 @@ private static ServiceContext CreateServiceContext(IOptions ServiceContext.ServerOptions; - private ServiceContext ServiceContext { get; } + // Internal for testing + internal ServiceContext ServiceContext { get; } private KestrelTrace Trace => ServiceContext.Log; diff --git a/src/Servers/Kestrel/Core/src/KestrelServer.cs b/src/Servers/Kestrel/Core/src/KestrelServer.cs index 75cec0130767..7f2909c77cf6 100644 --- a/src/Servers/Kestrel/Core/src/KestrelServer.cs +++ b/src/Servers/Kestrel/Core/src/KestrelServer.cs @@ -36,6 +36,7 @@ public KestrelServer(IOptions options, IConnectionListener Array.Empty(), new SimpleHttpsConfigurationService(), loggerFactory, + diagnosticSource: null, new KestrelMetrics(new DummyMeterFactory())); } diff --git a/src/Servers/Kestrel/Core/test/KestrelServerTests.cs b/src/Servers/Kestrel/Core/test/KestrelServerTests.cs index f3f4e3a60afd..6837ae0218de 100644 --- a/src/Servers/Kestrel/Core/test/KestrelServerTests.cs +++ b/src/Servers/Kestrel/Core/test/KestrelServerTests.cs @@ -308,6 +308,7 @@ private static KestrelServerImpl CreateKestrelServer( multiplexedFactories, httpsConfigurationService, loggerFactory ?? new LoggerFactory(new[] { new KestrelTestLoggerProvider() }), + diagnosticSource: null, metrics ?? new KestrelMetrics(new TestMeterFactory())); } diff --git a/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs b/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs index 759d074a6d82..b24da893ab53 100644 --- a/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs +++ b/src/Servers/Kestrel/Kestrel/test/WebHostBuilderKestrelExtensionsTests.cs @@ -2,10 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; +using System.IO.Pipelines; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; using Microsoft.Extensions.DependencyInjection; @@ -107,6 +109,11 @@ public void ServerIsKestrelServerImpl() .UseKestrel() .Configure(app => { }); - Assert.IsType(hostBuilder.Build().Services.GetService()); + var server = Assert.IsType(hostBuilder.Build().Services.GetService()); + + Assert.NotNull(server.ServiceContext.DiagnosticSource); + Assert.IsType(server.ServiceContext.Metrics); + Assert.Equal(PipeScheduler.ThreadPool, server.ServiceContext.Scheduler); + Assert.Equal(TimeProvider.System, server.ServiceContext.TimeProvider); } } From 850c1602302af22623018a7340ced3f1ec6aee55 Mon Sep 17 00:00:00 2001 From: Brennan Date: Thu, 30 Jan 2025 17:54:39 -0800 Subject: [PATCH 2/2] null --- src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs b/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs index e618f74be5a6..5cb38d2832c9 100644 --- a/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs +++ b/src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs @@ -39,7 +39,7 @@ public KestrelServerImpl( IEnumerable multiplexedFactories, IHttpsConfigurationService httpsConfigurationService, ILoggerFactory loggerFactory, - DiagnosticSource diagnosticSource, + DiagnosticSource? diagnosticSource, KestrelMetrics metrics) : this(transportFactories, multiplexedFactories, httpsConfigurationService, CreateServiceContext(options, loggerFactory, diagnosticSource, metrics)) {