Skip to content

[release/8.0] Readd DiagnosticSource to KestrelServerImpl #60203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -308,6 +308,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);
}
}
Loading