From 8d24e7e557cc247503a6ef139536617efdcb9867 Mon Sep 17 00:00:00 2001 From: KirillKurdyukov Date: Mon, 16 Dec 2024 17:06:21 +0300 Subject: [PATCH 1/7] dev: update log level on AttachStream --- src/Ydb.Sdk/src/Services/Query/SessionPool.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs index 51897f7d..7c6bdb3c 100644 --- a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs @@ -74,27 +74,31 @@ protected override async Task CreateSession() // ReSharper disable once InvertIf if (!session.IsActive) { - Logger.LogWarning("Session[{SessionId}] is deactivated", session.SessionId); + Logger.LogWarning("Session[{SessionId}] is deactivated. Reason: {Status}", + session.SessionId, sessionStateStatus); return; } } + Logger.LogDebug("Session[{SessionId}]: Attached stream is closed", session.SessionId); + // attach stream is closed } - catch (Driver.TransportException) + catch (Driver.TransportException e) { + Logger.LogWarning(e, "Session[{SessionId}] is deactivated by transport error", session.SessionId); } } - catch (Exception e) + catch (Driver.TransportException e) { + Logger.LogError(e, "Transport error on attach session"); + completeTask.SetException(e); } finally { session.IsActive = false; - - Logger.LogTrace("Session[{SessionId}]: Attached stream is closed", session.SessionId); } }); From ebe746224cd3fdb1aa198747a67cf3cd3a2c626b Mon Sep 17 00:00:00 2001 From: KirillKurdyukov Date: Mon, 16 Dec 2024 17:07:11 +0300 Subject: [PATCH 2/7] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 713a7bb6..22583b15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +- Update log level on AttachStream + ## v0.9.0 - Writer client for YDB topics - Fix: delete default timeout grpc.deadline From 6f1044bc87839758e2a444d8a125f6a2a32a41bd Mon Sep 17 00:00:00 2001 From: KirillKurdyukov Date: Mon, 16 Dec 2024 17:24:28 +0300 Subject: [PATCH 3/7] delete LogError on Exception because throw out --- src/Ydb.Sdk/src/Services/Query/SessionPool.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs index 7c6bdb3c..a16fc449 100644 --- a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs @@ -92,8 +92,6 @@ protected override async Task CreateSession() } catch (Driver.TransportException e) { - Logger.LogError(e, "Transport error on attach session"); - completeTask.SetException(e); } finally From adc92a71fb0b007c8d139f82ef6ee818783af796 Mon Sep 17 00:00:00 2001 From: KirillKurdyukov Date: Mon, 16 Dec 2024 17:39:38 +0300 Subject: [PATCH 4/7] SLO make Debug log level --- slo/src/Internal/SloContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slo/src/Internal/SloContext.cs b/slo/src/Internal/SloContext.cs index b3554b14..dfb69b5c 100644 --- a/slo/src/Internal/SloContext.cs +++ b/slo/src/Internal/SloContext.cs @@ -11,7 +11,7 @@ public abstract class SloContext where T : IDisposable { // ReSharper disable once StaticMemberInGenericType protected static readonly ILoggerFactory Factory = - LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information)); + LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Debug)); protected static readonly ILogger Logger = Factory.CreateLogger>(); From e89ba33ebb876df1916f4b40fee607c9e475502d Mon Sep 17 00:00:00 2001 From: KirillKurdyukov Date: Mon, 16 Dec 2024 17:58:22 +0300 Subject: [PATCH 5/7] revert slo log level --- slo/src/Internal/SloContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slo/src/Internal/SloContext.cs b/slo/src/Internal/SloContext.cs index dfb69b5c..b3554b14 100644 --- a/slo/src/Internal/SloContext.cs +++ b/slo/src/Internal/SloContext.cs @@ -11,7 +11,7 @@ public abstract class SloContext where T : IDisposable { // ReSharper disable once StaticMemberInGenericType protected static readonly ILoggerFactory Factory = - LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Debug)); + LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information)); protected static readonly ILogger Logger = Factory.CreateLogger>(); From 00a4a34b101ed345ef78050d7350539a8d3e41cb Mon Sep 17 00:00:00 2001 From: KirillKurdyukov Date: Tue, 17 Dec 2024 10:17:30 +0300 Subject: [PATCH 6/7] update log levels --- src/Ydb.Sdk/src/Pool/SessionPool.cs | 16 ++++++++++++--- src/Ydb.Sdk/src/Services/Query/SessionPool.cs | 20 ++++++++++--------- src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs | 4 +++- src/Ydb.Sdk/tests/Utils.cs | 2 +- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/Ydb.Sdk/src/Pool/SessionPool.cs b/src/Ydb.Sdk/src/Pool/SessionPool.cs index c46d8dc4..271d99b3 100644 --- a/src/Ydb.Sdk/src/Pool/SessionPool.cs +++ b/src/Ydb.Sdk/src/Pool/SessionPool.cs @@ -208,6 +208,7 @@ private async ValueTask TryDriverDispose(int expectedCurrentCount) public abstract class SessionBase where T : SessionBase { private readonly SessionPool _sessionPool; + private readonly ILogger _logger; public string SessionId { get; } @@ -215,18 +216,27 @@ public abstract class SessionBase where T : SessionBase internal volatile bool IsActive = true; - internal SessionBase(SessionPool sessionPool, string sessionId, long nodeId) + internal SessionBase(SessionPool sessionPool, string sessionId, long nodeId, ILogger logger) { _sessionPool = sessionPool; SessionId = sessionId; NodeId = nodeId; + _logger = logger; } internal void OnStatus(Status status) { - if (status.StatusCode is StatusCode.BadSession or StatusCode.SessionBusy or StatusCode.InternalError - or StatusCode.ClientTransportTimeout or StatusCode.Unavailable or StatusCode.ClientTransportUnavailable) + // ReSharper disable once InvertIf + if (status.StatusCode is + StatusCode.BadSession or + StatusCode.SessionBusy or + StatusCode.InternalError or + StatusCode.ClientTransportTimeout or + StatusCode.Unavailable or + StatusCode.ClientTransportUnavailable) { + _logger.LogWarning("Session[{SessionId}] is deactivated. Reason: {Status}", SessionId, status); + IsActive = false; } } diff --git a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs index a16fc449..777b5721 100644 --- a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs @@ -22,12 +22,14 @@ internal sealed class SessionPool : SessionPool, IAsyncDisposable private readonly Driver _driver; private readonly bool _disposingDriver; + private readonly ILogger _loggerSession; internal SessionPool(Driver driver, int? maxSessionPool = null, bool disposingDriver = false) : base(driver.LoggerFactory.CreateLogger(), maxSessionPool) { _driver = driver; _disposingDriver = disposingDriver; + _loggerSession = driver.LoggerFactory.CreateLogger(); } protected override async Task CreateSession() @@ -35,13 +37,11 @@ protected override async Task CreateSession() var response = await _driver.UnaryCall(QueryService.CreateSessionMethod, CreateSessionRequest, CreateSessionSettings); - var status = Status.FromProto(response.Status, response.Issues); - - status.EnsureSuccess(); + Status.FromProto(response.Status, response.Issues).EnsureSuccess(); TaskCompletionSource completeTask = new(); - var session = new Session(_driver, this, response.SessionId, response.NodeId); + var session = new Session(_driver, this, response.SessionId, response.NodeId, _loggerSession); _ = Task.Run(async () => { @@ -74,9 +74,6 @@ protected override async Task CreateSession() // ReSharper disable once InvertIf if (!session.IsActive) { - Logger.LogWarning("Session[{SessionId}] is deactivated. Reason: {Status}", - session.SessionId, sessionStateStatus); - return; } } @@ -136,8 +133,13 @@ internal class Session : SessionBase { private readonly Driver _driver; - internal Session(Driver driver, SessionPool sessionPool, string sessionId, long nodeId) - : base(sessionPool, sessionId, nodeId) + internal Session( + Driver driver, + SessionPool sessionPool, + string sessionId, + long nodeId, + ILogger logger + ) : base(sessionPool, sessionId, nodeId, logger) { _driver = driver; } diff --git a/src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs b/src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs index 165ec050..7dfcb1d2 100644 --- a/src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs +++ b/src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs @@ -1,4 +1,5 @@ using Google.Protobuf.Collections; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Xunit; using Ydb.Issue; @@ -106,7 +107,8 @@ protected override Task DeleteSession(TestSession session) public class TestSession : SessionBase { - internal TestSession(SessionPool sessionPool) : base(sessionPool, "0", 0) + internal TestSession(SessionPool sessionPool) + : base(sessionPool, "0", 0, Utils.GetLoggerFactory().CreateLogger()) { } } diff --git a/src/Ydb.Sdk/tests/Utils.cs b/src/Ydb.Sdk/tests/Utils.cs index 825cad9c..4da30819 100644 --- a/src/Ydb.Sdk/tests/Utils.cs +++ b/src/Ydb.Sdk/tests/Utils.cs @@ -47,7 +47,7 @@ public static async Task ExecuteSchemeQuery( internal static ILoggerFactory GetLoggerFactory() { return new ServiceCollection() - .AddLogging(configure => configure.AddConsole().SetMinimumLevel(LogLevel.Debug)) + .AddLogging(configure => configure.AddConsole().SetMinimumLevel(LogLevel.Information)) .BuildServiceProvider() .GetService() ?? NullLoggerFactory.Instance; } From 37d3c25cce2fc96c5c40c08f794b9ba0a5aa7dbc Mon Sep 17 00:00:00 2001 From: KirillKurdyukov Date: Tue, 17 Dec 2024 10:36:26 +0300 Subject: [PATCH 7/7] ADO.NET & WriterTopic make Debug in tests --- src/Ydb.Sdk/tests/Utils.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Ydb.Sdk/tests/Utils.cs b/src/Ydb.Sdk/tests/Utils.cs index 4da30819..dd914563 100644 --- a/src/Ydb.Sdk/tests/Utils.cs +++ b/src/Ydb.Sdk/tests/Utils.cs @@ -47,7 +47,13 @@ public static async Task ExecuteSchemeQuery( internal static ILoggerFactory GetLoggerFactory() { return new ServiceCollection() - .AddLogging(configure => configure.AddConsole().SetMinimumLevel(LogLevel.Information)) + .AddLogging(configure => + { + configure.AddConsole().SetMinimumLevel(LogLevel.Information); + configure.AddFilter("Ydb.Sdk.Ado", LogLevel.Debug); + configure.AddFilter("Ydb.Sdk.Services.Query", LogLevel.Debug); + configure.AddFilter("Ydb.Sdk.Services.Topic", LogLevel.Debug); + }) .BuildServiceProvider() .GetService() ?? NullLoggerFactory.Instance; }