Skip to content

Commit a326320

Browse files
dev: delete unused errorsTotal (#433)
* dev: downgrade ydb-node version * 9eab163aa60ea7dd9ba8fa5c31dace5da5e7637a * debug ydb-node version * bb7e4aad3eab6d7519c0dc0714394b448c2c83ff * debug * fixes * fix errorsTotal * delete unused errorsTotal
1 parent bd87cf2 commit a326320

File tree

3 files changed

+18
-43
lines changed

3 files changed

+18
-43
lines changed

slo/src/AdoNet/SloTableContext.cs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Internal;
33
using Microsoft.Extensions.Logging;
44
using Polly;
5-
using Prometheus;
65
using Ydb.Sdk;
76
using Ydb.Sdk.Ado;
87

@@ -12,13 +11,7 @@ public class SloTableContext : SloTableContext<YdbDataSource>
1211
{
1312
private readonly AsyncPolicy _policy = Policy.Handle<YdbException>(exception => exception.IsTransient)
1413
.WaitAndRetryAsync(10, attempt => TimeSpan.FromMilliseconds(attempt * 10),
15-
(e, _, _, context) =>
16-
{
17-
var errorsTotal = (Counter)context["errorsTotal"];
18-
19-
Logger.LogWarning(e, "Failed read / write operation");
20-
errorsTotal?.WithLabels(((YdbException)e).Code.StatusName(), "retried").Inc();
21-
});
14+
(e, _, _, _) => { Logger.LogWarning(e, "Failed read / write operation"); });
2215

2316
protected override string Job => "AdoNet";
2417

@@ -33,7 +26,7 @@ protected override async Task Create(YdbDataSource client, int operationTimeout)
3326
{
3427
CommandText = $"""
3528
CREATE TABLE `{SloTable.Name}` (
36-
Guid UUID,
29+
Guid Uuid,
3730
Id Int32,
3831
PayloadStr Text,
3932
PayloadDouble Double,
@@ -49,24 +42,17 @@ PRIMARY KEY (Guid, Id)
4942
protected override async Task<(int, StatusCode)> Save(
5043
YdbDataSource client,
5144
SloTable sloTable,
52-
int writeTimeout,
53-
Counter? errorsTotal = null
45+
int writeTimeout
5446
)
5547
{
56-
var context = new Context();
57-
if (errorsTotal != null)
58-
{
59-
context["errorsTotal"] = errorsTotal;
60-
}
61-
6248
var policyResult = await _policy.ExecuteAndCaptureAsync(async _ =>
6349
{
6450
await using var ydbConnection = await client.OpenConnectionAsync();
6551

6652
var ydbCommand = new YdbCommand(ydbConnection)
6753
{
6854
CommandText = $"""
69-
INSERT INTO `{SloTable.Name}` (Guid, Id, PayloadStr, PayloadDouble, PayloadTimestamp)
55+
UPSERT INTO `{SloTable.Name}` (Guid, Id, PayloadStr, PayloadDouble, PayloadTimestamp)
7056
VALUES (@Guid, @Id, @PayloadStr, @PayloadDouble, @PayloadTimestamp)
7157
""",
7258
CommandTimeout = writeTimeout,
@@ -106,7 +92,7 @@ PRIMARY KEY (Guid, Id)
10692
};
10793

10894
await ydbCommand.ExecuteNonQueryAsync();
109-
}, context);
95+
}, new Context());
11096

11197

11298
return (policyResult.Context.TryGetValue("RetryCount", out var countAttempts) ? (int)countAttempts : 1,
@@ -116,16 +102,9 @@ PRIMARY KEY (Guid, Id)
116102
protected override async Task<(int, StatusCode, object?)> Select(
117103
YdbDataSource client,
118104
(Guid Guid, int Id) select,
119-
int readTimeout,
120-
Counter? errorsTotal = null
105+
int readTimeout
121106
)
122107
{
123-
var context = new Context();
124-
if (errorsTotal != null)
125-
{
126-
context["errorsTotal"] = errorsTotal;
127-
}
128-
129108
var attempts = 0;
130109
var policyResult = await _policy.ExecuteAndCaptureAsync(async _ =>
131110
{
@@ -147,7 +126,7 @@ PRIMARY KEY (Guid, Id)
147126
};
148127

149128
return await ydbCommand.ExecuteScalarAsync();
150-
}, context);
129+
}, new Context());
151130

152131
return (attempts, ((YdbException)policyResult.FinalException)?.Code ?? StatusCode.Success, policyResult.Result);
153132
}

slo/src/EF/SloTableContext.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Internal;
33
using Microsoft.EntityFrameworkCore;
44
using Microsoft.EntityFrameworkCore.Infrastructure;
5-
using Prometheus;
65
using Ydb.Sdk;
76

87
namespace EF;
@@ -27,8 +26,8 @@ int operationTimeout
2726
protected override async Task<(int, StatusCode)> Save(
2827
PooledDbContextFactory<TableDbContext> client,
2928
SloTable sloTable,
30-
int writeTimeout,
31-
Counter? errorsTotal = null)
29+
int writeTimeout
30+
)
3231
{
3332
await using var dbContext = await client.CreateDbContextAsync();
3433
dbContext.SloEntities.Add(sloTable);
@@ -40,8 +39,7 @@ int operationTimeout
4039
protected override async Task<(int, StatusCode, object?)> Select(
4140
PooledDbContextFactory<TableDbContext> client,
4241
(Guid Guid, int Id) select,
43-
int readTimeout,
44-
Counter? errorsTotal = null
42+
int readTimeout
4543
)
4644
{
4745
await using var dbContext = await client.CreateDbContextAsync();

slo/src/Internal/SloTableContext.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public async Task Run(RunConfig runConfig)
132132
return;
133133

134134
Task ShootingTask(RateLimiter rateLimitPolicy, string operationType,
135-
Func<T, RunConfig, Counter?, Task<(int, StatusCode)>> action)
135+
Func<T, RunConfig, Task<(int, StatusCode)>> action)
136136
{
137137
var metricFactory = Metrics.WithLabels(new Dictionary<string, string>
138138
{
@@ -219,7 +219,7 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string operationType,
219219
{
220220
pendingOperations.Inc();
221221
var sw = Stopwatch.StartNew();
222-
var (attempts, statusCode) = await action(client, runConfig, errorsTotal);
222+
var (attempts, statusCode) = await action(client, runConfig);
223223
sw.Stop();
224224

225225
retryAttempts.Set(attempts);
@@ -251,15 +251,13 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string operationType,
251251
}
252252

253253
// return attempt count & StatusCode operation
254-
protected abstract Task<(int, StatusCode)> Save(T client, SloTable sloTable, int writeTimeout,
255-
Counter? errorsTotal = null);
254+
protected abstract Task<(int, StatusCode)> Save(T client, SloTable sloTable, int writeTimeout);
256255

257-
protected abstract Task<(int, StatusCode, object?)> Select(T client, (Guid Guid, int Id) select, int readTimeout,
258-
Counter? errorsTotal = null);
256+
protected abstract Task<(int, StatusCode, object?)> Select(T client, (Guid Guid, int Id) select, int readTimeout);
259257

260258
protected abstract Task<int> SelectCount(T client);
261259

262-
private Task<(int, StatusCode)> Save(T client, Config config, Counter? errorsTotal = null)
260+
private Task<(int, StatusCode)> Save(T client, Config config)
263261
{
264262
const int minSizeStr = 20;
265263
const int maxSizeStr = 40;
@@ -276,14 +274,14 @@ Task ShootingTask(RateLimiter rateLimitPolicy, string operationType,
276274
PayloadTimestamp = DateTime.Now
277275
};
278276

279-
return Save(client, sloTable, config.WriteTimeout, errorsTotal);
277+
return Save(client, sloTable, config.WriteTimeout);
280278
}
281279

282-
private async Task<(int, StatusCode)> Select(T client, RunConfig config, Counter? errorsTotal = null)
280+
private async Task<(int, StatusCode)> Select(T client, RunConfig config)
283281
{
284282
var id = Random.Shared.Next(_maxId);
285283
var (attempts, code, _) =
286-
await Select(client, new ValueTuple<Guid, int>(GuidFromInt(id), id), config.ReadTimeout, errorsTotal);
284+
await Select(client, new ValueTuple<Guid, int>(GuidFromInt(id), id), config.ReadTimeout);
287285

288286
return (attempts, code);
289287
}

0 commit comments

Comments
 (0)