Skip to content

Remove trace interfaces from Kestrel transports #37243

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 3 commits into from
Oct 6, 2021
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
29 changes: 0 additions & 29 deletions src/Servers/Kestrel/Transport.Libuv/src/Internal/ILibuvTrace.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal partial class LibuvConnection : TransportConnection
private bool _connectionClosed;

public LibuvConnection(UvStreamHandle socket,
ILibuvTrace log,
ILogger log,
LibuvThread thread,
IPEndPoint remoteEndPoint,
IPEndPoint localEndPoint,
Expand Down Expand Up @@ -72,7 +72,7 @@ public LibuvConnection(UvStreamHandle socket,
public PipeReader Output => Application.Input;

public LibuvOutputConsumer OutputConsumer { get; set; }
private ILibuvTrace Log { get; }
private ILogger Log { get; }
private LibuvThread Thread { get; }
public override MemoryPool<byte> MemoryPool => Thread.MemoryPool;

Expand Down Expand Up @@ -114,7 +114,7 @@ private async Task StartCore()
else
{
// This is unexpected.
Log.ConnectionError(ConnectionId, ex);
LibuvTrace.ConnectionError(Log, ConnectionId, ex);

inputError = ex;
outputError = ex;
Expand All @@ -133,7 +133,7 @@ private async Task StartCore()
Input.CancelPendingFlush();

// Send a FIN
Log.ConnectionWriteFin(ConnectionId, inputError.Message);
LibuvTrace.ConnectionWriteFin(Log, ConnectionId, inputError.Message);

// We're done with the socket now
_socket.Dispose();
Expand Down Expand Up @@ -204,7 +204,7 @@ private void OnRead(UvStreamHandle handle, int status)
}
else if (status > 0)
{
Log.ConnectionRead(ConnectionId, status);
LibuvTrace.ConnectionRead(Log, ConnectionId, status);

Input.Advance(status);
var flushTask = Input.FlushAsync();
Expand All @@ -225,7 +225,7 @@ private void OnRead(UvStreamHandle handle, int status)

if (status == LibuvConstants.EOF)
{
Log.ConnectionReadFin(ConnectionId);
LibuvTrace.ConnectionReadFin(Log, ConnectionId);
}
else
{
Expand Down Expand Up @@ -262,15 +262,15 @@ private void FireConnectionClosed()

private async Task ApplyBackpressureAsync(ValueTask<FlushResult> flushTask)
{
Log.ConnectionPause(ConnectionId);
LibuvTrace.ConnectionPause(Log, ConnectionId);
_socket.ReadStop();

var result = await flushTask;

// If the reader isn't complete or cancelled then resume reading
if (!result.IsCompleted && !result.IsCanceled)
{
Log.ConnectionResume(ConnectionId);
LibuvTrace.ConnectionResume(Log, ConnectionId);
StartReading();
}
}
Expand Down Expand Up @@ -299,13 +299,13 @@ private Exception LogAndWrapReadError(UvException uvError)
else if (LibuvConstants.IsConnectionReset(uvError.StatusCode))
{
// Log connection resets at a lower (Debug) level.
Log.ConnectionReset(ConnectionId);
LibuvTrace.ConnectionReset(Log, ConnectionId);
return new ConnectionResetException(uvError.Message, uvError);
}
else
{
// This is unexpected.
Log.ConnectionError(ConnectionId, uvError);
LibuvTrace.ConnectionError(Log, ConnectionId, uvError);
return new IOException(uvError.Message, uvError);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public LibuvConnectionListener(LibuvFunctions uv, LibuvTransportContext context,
public List<LibuvThread> Threads { get; } = new List<LibuvThread>();

public IHostApplicationLifetime AppLifetime => TransportContext.AppLifetime;
public ILibuvTrace Log => TransportContext.Log;
public ILogger Log => TransportContext.Log;

#pragma warning disable CS0618
public LibuvTransportOptions TransportOptions => TransportContext.Options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,42 @@

namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
{
internal partial class LibuvTrace : ILibuvTrace
internal static partial class LibuvTrace
{
private readonly ILogger _logger;

public LibuvTrace(ILogger logger)
{
_logger = logger;
}

public void ConnectionRead(string connectionId, int count)
public static void ConnectionRead(ILogger logger, string connectionId, int count)
{
// Don't log for now since this could be *too* verbose.
// Reserved: Event ID 3
}

[LoggerMessage(6, LogLevel.Debug, @"Connection id ""{ConnectionId}"" received FIN.", EventName = nameof(ConnectionReadFin))]
public partial void ConnectionReadFin(string connectionId);
public static partial void ConnectionReadFin(ILogger logger, string connectionId);

[LoggerMessage(7, LogLevel.Debug, @"Connection id ""{ConnectionId}"" sending FIN because: ""{Reason}""", EventName = nameof(ConnectionWriteFin))]
public partial void ConnectionWriteFin(string connectionId, string reason);
public static partial void ConnectionWriteFin(ILogger logger, string connectionId, string reason);

public void ConnectionWrite(string connectionId, int count)
public static void ConnectionWrite(ILogger logger, string connectionId, int count)
{
// Don't log for now since this could be *too* verbose.
// Reserved: Event ID 11
}

public void ConnectionWriteCallback(string connectionId, int status)
public static void ConnectionWriteCallback(ILogger logger, string connectionId, int status)
{
// Don't log for now since this could be *too* verbose.
// Reserved: Event ID 12
}

[LoggerMessage(14, LogLevel.Debug, @"Connection id ""{ConnectionId}"" communication error.", EventName = nameof(ConnectionError))]
public partial void ConnectionError(string connectionId, Exception ex);
public static partial void ConnectionError(ILogger logger, string connectionId, Exception ex);

[LoggerMessage(19, LogLevel.Debug, @"Connection id ""{ConnectionId}"" reset.", EventName = nameof(ConnectionReset))]
public partial void ConnectionReset(string connectionId);
public static partial void ConnectionReset(ILogger logger, string connectionId);

[LoggerMessage(4, LogLevel.Debug, @"Connection id ""{ConnectionId}"" paused.", EventName = nameof(ConnectionPause))]
public partial void ConnectionPause(string connectionId);
public static partial void ConnectionPause(ILogger logger, string connectionId);

[LoggerMessage(5, LogLevel.Debug, @"Connection id ""{ConnectionId}"" resumed.", EventName = nameof(ConnectionResume))]
public partial void ConnectionResume(string connectionId);

public IDisposable BeginScope<TState>(TState state) => _logger.BeginScope(state);

public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
=> _logger.Log(logLevel, eventId, state, exception, formatter);
public static partial void ConnectionResume(ILogger logger, string connectionId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO.Pipelines;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
{
Expand All @@ -13,15 +14,15 @@ internal class LibuvOutputConsumer
private readonly LibuvThread _thread;
private readonly UvStreamHandle _socket;
private readonly string _connectionId;
private readonly ILibuvTrace _log;
private readonly ILogger _log;
private readonly PipeReader _pipe;

public LibuvOutputConsumer(
PipeReader pipe,
LibuvThread thread,
UvStreamHandle socket,
string connectionId,
ILibuvTrace log)
ILogger log)
{
_pipe = pipe;
_thread = thread;
Expand Down Expand Up @@ -97,7 +98,7 @@ private void LogWriteInfo(int status, Exception error)
{
if (error == null)
{
_log.ConnectionWriteCallback(_connectionId, status);
LibuvTrace.ConnectionWriteCallback(_log, _connectionId, status);
}
else
{
Expand All @@ -108,11 +109,11 @@ private void LogWriteInfo(int status, Exception error)
}
else if (LibuvConstants.IsConnectionReset(status))
{
_log.ConnectionReset(_connectionId);
LibuvTrace.ConnectionReset(_log, _connectionId);
}
else
{
_log.ConnectionError(_connectionId, error);
LibuvTrace.ConnectionError(_log, _connectionId, error);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ internal class LibuvThread : PipeScheduler
private bool _stopImmediate;
private bool _initCompleted;
private Exception _closeError;
private readonly ILibuvTrace _log;
private readonly ILogger _log;

public LibuvThread(LibuvFunctions libuv, LibuvTransportContext libuvTransportContext, int maxLoops = 8)
: this(libuv, libuvTransportContext.AppLifetime, libuvTransportContext.Options.MemoryPoolFactory(), libuvTransportContext.Log, maxLoops)
{
}

public LibuvThread(LibuvFunctions libuv, IHostApplicationLifetime appLifetime, MemoryPool<byte> pool, ILibuvTrace log, int maxLoops = 8)
public LibuvThread(LibuvFunctions libuv, IHostApplicationLifetime appLifetime, MemoryPool<byte> pool, ILogger log, int maxLoops = 8)
{
_libuv = libuv;
_appLifetime = appLifetime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
{
Expand All @@ -13,6 +14,6 @@ internal class LibuvTransportContext

public IHostApplicationLifetime AppLifetime { get; set; }

public ILibuvTrace Log { get; set; }
public ILogger Log { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public LibuvTransportFactory(
}

var logger = loggerFactory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv");
var trace = new LibuvTrace(logger);

#pragma warning disable CS0618
var threadCount = options.Value.ThreadCount;
Expand All @@ -52,19 +51,19 @@ public LibuvTransportFactory(

if (!LibuvConstants.ECONNRESET.HasValue)
{
trace.LogWarning("Unable to determine ECONNRESET value on this platform.");
logger.LogWarning("Unable to determine ECONNRESET value on this platform.");
}

if (!LibuvConstants.EADDRINUSE.HasValue)
{
trace.LogWarning("Unable to determine EADDRINUSE value on this platform.");
logger.LogWarning("Unable to determine EADDRINUSE value on this platform.");
}

_baseTransportContext = new LibuvTransportContext
{
Options = options.Value,
AppLifetime = applicationLifetime,
Log = trace,
Log = logger,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Listener(LibuvTransportContext transportContext) : base(transportContext)

protected UvStreamHandle ListenSocket { get; private set; }

public ILibuvTrace Log => TransportContext.Log;
public ILogger Log => TransportContext.Log;

public Task StartAsync(
EndPoint endPoint,
Expand Down Expand Up @@ -184,7 +184,7 @@ private void OnConnection(UvStreamHandle listenSocket, int status)
}
catch (UvException ex) when (LibuvConstants.IsConnectionReset(ex.StatusCode))
{
Log.ConnectionReset("(null)");
LibuvTrace.ConnectionReset(Log, "(null)");
acceptSocket?.Dispose();
}
catch (UvException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected internal void HandleConnection(UvStreamHandle socket)
}
catch (UvException ex) when (LibuvConstants.IsConnectionReset(ex.StatusCode))
{
TransportContext.Log.ConnectionReset("(null)");
LibuvTrace.ConnectionReset(TransportContext.Log, "(null)");
socket.Dispose();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ListenerSecondary(LibuvTransportContext transportContext) : base(transpor

UvPipeHandle DispatchPipe { get; set; }

public ILibuvTrace Log => TransportContext.Log;
public ILogger Log => TransportContext.Log;

public Task StartAsync(
string pipeName,
Expand Down Expand Up @@ -156,7 +156,7 @@ private void ReadStartCallback(UvStreamHandle handle, int status)
}
catch (UvException ex) when (LibuvConstants.IsConnectionReset(ex.StatusCode))
{
Log.ConnectionReset("(null)");
LibuvTrace.ConnectionReset(Log, "(null)");
acceptSocket.Dispose();
}
catch (UvException ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Threading;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking
{
Expand All @@ -15,7 +16,7 @@ internal class UvAsyncHandle : UvHandle
private Action _callback;
private Action<Action<IntPtr>, IntPtr> _queueCloseHandle;

public UvAsyncHandle(ILibuvTrace logger) : base(logger)
public UvAsyncHandle(ILogger logger) : base(logger)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class UvConnectRequest : UvRequest
private Action<UvConnectRequest, int, UvException, object> _callback;
private object _state;

public UvConnectRequest(ILibuvTrace logger) : base (logger)
public UvConnectRequest(ILogger logger) : base (logger)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Threading;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal.Networking
{
Expand All @@ -12,7 +13,7 @@ internal abstract class UvHandle : UvMemory
private static readonly LibuvFunctions.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle);
private Action<Action<IntPtr>, IntPtr> _queueCloseHandle;

protected UvHandle(ILibuvTrace logger) : base (logger)
protected UvHandle(ILogger logger) : base (logger)
{
}

Expand Down
Loading