diff --git a/slo/src/AdoNet/SloContext.cs b/slo/src/AdoNet/SloContext.cs index 0e9f5407..5ead9eec 100644 --- a/slo/src/AdoNet/SloContext.cs +++ b/slo/src/AdoNet/SloContext.cs @@ -1,4 +1,5 @@ using Internal; +using Microsoft.Extensions.Logging; using Polly; using Prometheus; using Ydb.Sdk; @@ -15,6 +16,7 @@ public class SloContext : SloContext { var errorsGauge = (Gauge)context["errorsGauge"]; + Logger.LogWarning(e, "Failed read / write operation"); errorsGauge?.WithLabels(((YdbException)e).Code.StatusName(), "retried").Inc(); }); diff --git a/slo/src/Internal/SloContext.cs b/slo/src/Internal/SloContext.cs index 18bc66e0..f7407eff 100644 --- a/slo/src/Internal/SloContext.cs +++ b/slo/src/Internal/SloContext.cs @@ -9,16 +9,13 @@ namespace Internal; public abstract class SloContext where T : IDisposable { - protected readonly ILoggerFactory Factory; - private readonly ILogger _logger; + // ReSharper disable once StaticMemberInGenericType + protected static readonly ILoggerFactory Factory = + LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information)); - private volatile int _maxId; + protected static readonly ILogger Logger = Factory.CreateLogger>(); - protected SloContext() - { - Factory = LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information)); - _logger = Factory.CreateLogger>(); - } + private volatile int _maxId; protected abstract string Job { get; } @@ -29,7 +26,7 @@ public async Task Create(CreateConfig config) using var client = await CreateClient(config); for (var attempt = 0; attempt < maxCreateAttempts; attempt++) { - _logger.LogInformation("Creating table {TableName}..", config.TableName); + Logger.LogInformation("Creating table {TableName}..", config.TableName); try { var createTableSql = $""" @@ -49,17 +46,17 @@ PRIMARY KEY (hash, id) AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = {config.MaxPartitionsCount} ); """; - _logger.LogInformation("YQL script: {sql}", createTableSql); + Logger.LogInformation("YQL script: {sql}", createTableSql); await Create(client, createTableSql, config.WriteTimeout); - _logger.LogInformation("Created table {TableName}", config.TableName); + Logger.LogInformation("Created table {TableName}", config.TableName); break; } catch (Exception e) { - _logger.LogError(e, "Fail created table"); + Logger.LogError(e, "Fail created table"); if (attempt == maxCreateAttempts - 1) { @@ -82,11 +79,11 @@ PRIMARY KEY (hash, id) } catch (Exception e) { - _logger.LogError(e, "Init failed when all tasks, continue.."); + Logger.LogError(e, "Init failed when all tasks, continue.."); } finally { - _logger.LogInformation("Created task is finished"); + Logger.LogInformation("Created task is finished"); } } @@ -103,7 +100,7 @@ public async Task Run(RunConfig runConfig) new Dictionary(), runConfig.ReadTimeout); _maxId = (int)maxId!; - _logger.LogInformation("Init row count: {MaxId}", _maxId); + Logger.LogInformation("Init row count: {MaxId}", _maxId); var writeLimiter = new FixedWindowRateLimiter(new FixedWindowRateLimiterOptions { @@ -120,7 +117,7 @@ public async Task Run(RunConfig runConfig) var writeTask = ShootingTask(writeLimiter, "write", Upsert); var readTask = ShootingTask(readLimiter, "read", Select); - _logger.LogInformation("Started write / read shooting.."); + Logger.LogInformation("Started write / read shooting.."); try { @@ -128,13 +125,13 @@ public async Task Run(RunConfig runConfig) } catch (Exception e) { - _logger.LogInformation(e, "Cancel shooting"); + Logger.LogInformation(e, "Cancel shooting"); } await prometheus.StopAsync(); await MetricReset(promPgwEndpoint); - _logger.LogInformation("Run task is finished"); + Logger.LogInformation("Run task is finished"); return; Task ShootingTask(RateLimiter rateLimitPolicy, string jobName, @@ -203,7 +200,7 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string jobName, // ReSharper disable once MethodSupportsCancellation await Task.Delay(TimeSpan.FromSeconds(runConfig.ShutdownTime)); - _logger.LogInformation("{ShootingName} shooting is stopped", jobName); + Logger.LogInformation("{ShootingName} shooting is stopped", jobName); }); } } @@ -254,7 +251,7 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string jobName, """, new Dictionary { - { "$id", YdbValue.MakeUint64((ulong)Random.Shared.Next(_maxId)) } + { "$id", YdbValue.MakeInt32(Random.Shared.Next(_maxId)) } }, config.ReadTimeout, errorsGauge); return (attempts, code); diff --git a/slo/src/TableService/SloContext.cs b/slo/src/TableService/SloContext.cs index 96e556ba..d426ace7 100644 --- a/slo/src/TableService/SloContext.cs +++ b/slo/src/TableService/SloContext.cs @@ -1,4 +1,5 @@ using Internal; +using Microsoft.Extensions.Logging; using Prometheus; using Ydb.Sdk; using Ydb.Sdk.Services.Table; @@ -38,6 +39,7 @@ protected override async Task Create(TableClient client, string createTableSql, return response; } + errorsGauge?.WithLabels(response.Status.StatusCode.ToString(), "retried").Inc(); return response; @@ -64,6 +66,8 @@ protected override async Task Create(TableClient client, string createTableSql, return response; } + Logger.LogWarning("{}", response.Status.ToString()); + errorsGauge?.WithLabels(response.Status.StatusCode.StatusName(), "retried").Inc(); return response;