Skip to content

Commit

Permalink
Readd DiagnosticSource to KestrelServerImpl (#60129)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy authored Feb 5, 2025
1 parent 65f485e commit 0ca0136
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Servers/Kestrel/Core/src/Internal/KestrelServerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public KestrelServerImpl(
IEnumerable<IMultiplexedConnectionListenerFactory> 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))
{
}

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

public KestrelServerOptions Options => ServiceContext.ServerOptions;

private ServiceContext ServiceContext { get; }
// Internal for testing
internal ServiceContext ServiceContext { get; }

private KestrelTrace Trace => ServiceContext.Log;

Expand Down
1 change: 1 addition & 0 deletions src/Servers/Kestrel/Core/src/KestrelServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public KestrelServer(IOptions<KestrelServerOptions> options, IConnectionListener
Array.Empty<IMultiplexedConnectionListenerFactory>(),
new SimpleHttpsConfigurationService(),
loggerFactory,
diagnosticSource: null,
new KestrelMetrics(new DummyMeterFactory()));
}

Expand Down
1 change: 1 addition & 0 deletions src/Servers/Kestrel/Core/test/KestrelServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ private static KestrelServerImpl CreateKestrelServer(
multiplexedFactories,
httpsConfigurationService,
loggerFactory ?? new LoggerFactory(new[] { new KestrelTestLoggerProvider() }),
diagnosticSource: null,
metrics ?? new KestrelMetrics(new TestMeterFactory()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,6 +109,11 @@ public void ServerIsKestrelServerImpl()
.UseKestrel()
.Configure(app => { });

Assert.IsType<KestrelServerImpl>(hostBuilder.Build().Services.GetService<IServer>());
var server = Assert.IsType<KestrelServerImpl>(hostBuilder.Build().Services.GetService<IServer>());

Assert.NotNull(server.ServiceContext.DiagnosticSource);
Assert.IsType<KestrelMetrics>(server.ServiceContext.Metrics);
Assert.Equal(PipeScheduler.ThreadPool, server.ServiceContext.Scheduler);
Assert.Equal(TimeProvider.System, server.ServiceContext.TimeProvider);
}
}

0 comments on commit 0ca0136

Please sign in to comment.