diff --git a/slo/src/AdoNet/SloTableContext.cs b/slo/src/AdoNet/SloTableContext.cs index de0c572f..0ab51f68 100644 --- a/slo/src/AdoNet/SloTableContext.cs +++ b/slo/src/AdoNet/SloTableContext.cs @@ -2,7 +2,6 @@ using Internal; using Microsoft.Extensions.Logging; using Polly; -using Prometheus; using Ydb.Sdk; using Ydb.Sdk.Ado; @@ -12,13 +11,7 @@ public class SloTableContext : SloTableContext { private readonly AsyncPolicy _policy = Policy.Handle(exception => exception.IsTransient) .WaitAndRetryAsync(10, attempt => TimeSpan.FromMilliseconds(attempt * 10), - (e, _, _, context) => - { - var errorsTotal = (Counter)context["errorsTotal"]; - - Logger.LogWarning(e, "Failed read / write operation"); - errorsTotal?.WithLabels(((YdbException)e).Code.StatusName(), "retried").Inc(); - }); + (e, _, _, _) => { Logger.LogWarning(e, "Failed read / write operation"); }); protected override string Job => "AdoNet"; @@ -33,7 +26,7 @@ protected override async Task Create(YdbDataSource client, int operationTimeout) { CommandText = $""" CREATE TABLE `{SloTable.Name}` ( - Guid UUID, + Guid Uuid, Id Int32, PayloadStr Text, PayloadDouble Double, @@ -49,16 +42,9 @@ PRIMARY KEY (Guid, Id) protected override async Task<(int, StatusCode)> Save( YdbDataSource client, SloTable sloTable, - int writeTimeout, - Counter? errorsTotal = null + int writeTimeout ) { - var context = new Context(); - if (errorsTotal != null) - { - context["errorsTotal"] = errorsTotal; - } - var policyResult = await _policy.ExecuteAndCaptureAsync(async _ => { await using var ydbConnection = await client.OpenConnectionAsync(); @@ -66,7 +52,7 @@ PRIMARY KEY (Guid, Id) var ydbCommand = new YdbCommand(ydbConnection) { CommandText = $""" - INSERT INTO `{SloTable.Name}` (Guid, Id, PayloadStr, PayloadDouble, PayloadTimestamp) + UPSERT INTO `{SloTable.Name}` (Guid, Id, PayloadStr, PayloadDouble, PayloadTimestamp) VALUES (@Guid, @Id, @PayloadStr, @PayloadDouble, @PayloadTimestamp) """, CommandTimeout = writeTimeout, @@ -106,7 +92,7 @@ PRIMARY KEY (Guid, Id) }; await ydbCommand.ExecuteNonQueryAsync(); - }, context); + }, new Context()); return (policyResult.Context.TryGetValue("RetryCount", out var countAttempts) ? (int)countAttempts : 1, @@ -116,16 +102,9 @@ PRIMARY KEY (Guid, Id) protected override async Task<(int, StatusCode, object?)> Select( YdbDataSource client, (Guid Guid, int Id) select, - int readTimeout, - Counter? errorsTotal = null + int readTimeout ) { - var context = new Context(); - if (errorsTotal != null) - { - context["errorsTotal"] = errorsTotal; - } - var attempts = 0; var policyResult = await _policy.ExecuteAndCaptureAsync(async _ => { @@ -147,7 +126,7 @@ PRIMARY KEY (Guid, Id) }; return await ydbCommand.ExecuteScalarAsync(); - }, context); + }, new Context()); return (attempts, ((YdbException)policyResult.FinalException)?.Code ?? StatusCode.Success, policyResult.Result); } diff --git a/slo/src/EF/SloTableContext.cs b/slo/src/EF/SloTableContext.cs index 40a3fdef..ad4d265c 100644 --- a/slo/src/EF/SloTableContext.cs +++ b/slo/src/EF/SloTableContext.cs @@ -2,7 +2,6 @@ using Internal; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Prometheus; using Ydb.Sdk; namespace EF; @@ -27,8 +26,8 @@ int operationTimeout protected override async Task<(int, StatusCode)> Save( PooledDbContextFactory client, SloTable sloTable, - int writeTimeout, - Counter? errorsTotal = null) + int writeTimeout + ) { await using var dbContext = await client.CreateDbContextAsync(); dbContext.SloEntities.Add(sloTable); @@ -40,8 +39,7 @@ int operationTimeout protected override async Task<(int, StatusCode, object?)> Select( PooledDbContextFactory client, (Guid Guid, int Id) select, - int readTimeout, - Counter? errorsTotal = null + int readTimeout ) { await using var dbContext = await client.CreateDbContextAsync(); diff --git a/slo/src/Internal/SloTableContext.cs b/slo/src/Internal/SloTableContext.cs index 08bf5273..a9d05187 100644 --- a/slo/src/Internal/SloTableContext.cs +++ b/slo/src/Internal/SloTableContext.cs @@ -132,7 +132,7 @@ public async Task Run(RunConfig runConfig) return; Task ShootingTask(RateLimiter rateLimitPolicy, string operationType, - Func> action) + Func> action) { var metricFactory = Metrics.WithLabels(new Dictionary { @@ -219,7 +219,7 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string operationType, { pendingOperations.Inc(); var sw = Stopwatch.StartNew(); - var (attempts, statusCode) = await action(client, runConfig, errorsTotal); + var (attempts, statusCode) = await action(client, runConfig); sw.Stop(); retryAttempts.Set(attempts); @@ -251,15 +251,13 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string operationType, } // return attempt count & StatusCode operation - protected abstract Task<(int, StatusCode)> Save(T client, SloTable sloTable, int writeTimeout, - Counter? errorsTotal = null); + protected abstract Task<(int, StatusCode)> Save(T client, SloTable sloTable, int writeTimeout); - protected abstract Task<(int, StatusCode, object?)> Select(T client, (Guid Guid, int Id) select, int readTimeout, - Counter? errorsTotal = null); + protected abstract Task<(int, StatusCode, object?)> Select(T client, (Guid Guid, int Id) select, int readTimeout); protected abstract Task SelectCount(T client); - private Task<(int, StatusCode)> Save(T client, Config config, Counter? errorsTotal = null) + private Task<(int, StatusCode)> Save(T client, Config config) { const int minSizeStr = 20; const int maxSizeStr = 40; @@ -276,14 +274,14 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string operationType, PayloadTimestamp = DateTime.Now }; - return Save(client, sloTable, config.WriteTimeout, errorsTotal); + return Save(client, sloTable, config.WriteTimeout); } - private async Task<(int, StatusCode)> Select(T client, RunConfig config, Counter? errorsTotal = null) + private async Task<(int, StatusCode)> Select(T client, RunConfig config) { var id = Random.Shared.Next(_maxId); var (attempts, code, _) = - await Select(client, new ValueTuple(GuidFromInt(id), id), config.ReadTimeout, errorsTotal); + await Select(client, new ValueTuple(GuidFromInt(id), id), config.ReadTimeout); return (attempts, code); }