Skip to content

Commit bf4d098

Browse files
committed
[C++ SDK] Supported metric loading to OTLP in SLO workload
1 parent 37977bb commit bf4d098

File tree

16 files changed

+386
-770
lines changed

16 files changed

+386
-770
lines changed

contrib/libs/opentelemetry-cpp/api/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ NO_COMPILER_WARNINGS()
1919
NO_UTIL()
2020

2121
CFLAGS(
22-
-DOPENTELEMETRY_ABI_VERSION_NO=1
22+
GLOBAL -DOPENTELEMETRY_ABI_VERSION_NO=2
2323
GLOBAL -DOPENTELEMETRY_STL_VERSION=2023
2424
)
2525

contrib/libs/opentelemetry-cpp/ya.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ NO_COMPILER_WARNINGS()
3333
NO_UTIL()
3434

3535
CFLAGS(
36-
-DOPENTELEMETRY_ABI_VERSION_NO=1
36+
GLOBAL -DOPENTELEMETRY_ABI_VERSION_NO=2
3737
GLOBAL -DOPENTELEMETRY_STL_VERSION=2023
3838
)
3939

ydb/public/sdk/cpp/tests/slo_workloads/key_value/generate.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace NYdb::NTable;
88

99

1010
TGenerateInitialContentJob::TGenerateInitialContentJob(const TCreateOptions& createOpts, std::uint32_t maxId)
11-
: TThreadJob(createOpts.CommonOptions)
11+
: TThreadJob(createOpts.CommonOptions, "generate")
1212
, Executor(createOpts.CommonOptions, Stats, TExecutor::ModeBlocking)
1313
, PackGenerator(
1414
createOpts.CommonOptions
@@ -81,5 +81,4 @@ UPSERT INTO `%s` SELECT * FROM AS_TABLE($items);
8181
void TGenerateInitialContentJob::OnFinish() {
8282
Executor.Finish();
8383
Executor.Wait();
84-
Stats.Flush();
8584
}

ydb/public/sdk/cpp/tests/slo_workloads/key_value/key_value.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class TReadJob : public TThreadJob {
4848
private:
4949
std::unique_ptr<TExecutor> Executor;
5050
std::uint32_t ObjectIdRange;
51-
bool SaveResult;
5251
};
5352

5453
int CreateTable(TDatabaseOptions& dbOptions);

ydb/public/sdk/cpp/tests/slo_workloads/key_value/run.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using namespace NYdb;
77
using namespace NYdb::NTable;
88

99
TWriteJob::TWriteJob(const TCommonOptions& opts, std::uint32_t maxId)
10-
: TThreadJob(opts)
10+
: TThreadJob(opts, "write")
1111
, Executor(opts, Stats, TExecutor::ModeNonBlocking)
1212
, Generator(opts, maxId)
1313
{}
@@ -77,15 +77,13 @@ UPSERT INTO `%s` SELECT * FROM AS_TABLE($items);
7777
void TWriteJob::OnFinish() {
7878
Executor.Finish();
7979
Executor.Wait();
80-
Stats.Flush();
8180
}
8281

8382
// Implementation of TReadJob
8483
TReadJob::TReadJob(const TCommonOptions& opts, std::uint32_t maxId)
85-
: TThreadJob(opts)
86-
, Executor(opts.RetryMode ? new TExecutorWithRetry(opts, Stats) : new TExecutor(opts, Stats))
84+
: TThreadJob(opts, "read")
85+
, Executor(std::make_unique<TExecutor>(opts, Stats))
8786
, ObjectIdRange(static_cast<std::uint32_t>(maxId * 1.25)) // 20% of requests with no result
88-
, SaveResult(opts.SaveResult)
8987
{}
9088

9189
void TReadJob::ShowProgress(TStringBuilder& report) {
@@ -154,8 +152,4 @@ void TReadJob::OnFinish() {
154152
if (infly) {
155153
Cerr << "Warning: thread A finished while having " << infly << " infly requests." << Endl;
156154
}
157-
Stats.Flush();
158-
if (SaveResult) {
159-
Stats.SaveResult();
160-
}
161155
}

ydb/public/sdk/cpp/tests/slo_workloads/utils/executor.cpp

Lines changed: 9 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,17 @@ bool TExecutor::Execute(const NYdb::NTable::TTableClient::TOperationFunc& func)
274274
}
275275
}
276276

277-
TStatUnit stat = Stats.CreateStatUnit();
277+
auto stat = Stats.StartRequest();
278+
279+
auto future = InsistentClient.ExecuteWithRetry([func, stat](NYdb::NTable::TSession session) {
280+
auto result = func(session);
281+
return result;
282+
});
278283

279-
auto future = InsistentClient.ExecuteWithRetry(func);
280284
future.Subscribe([this, stat, SemaphoreWrapper](const TAsyncFinalStatus& future) mutable {
281285
Y_ABORT_UNLESS(future.HasValue());
282286
TFinalStatus resultStatus = future.GetValue();
283-
Stats.Report(stat, resultStatus);
287+
Stats.FinishRequest(stat, resultStatus);
284288
if (resultStatus) {
285289
CheckForError(*resultStatus);
286290
}
@@ -351,7 +355,6 @@ bool TExecutor::IsStopped() {
351355
}
352356

353357
void TExecutor::Finish() {
354-
// Stats.UpdateSessionStats(InsistentClient.GetSessionStats());
355358
with_lock(Lock) {
356359
if (!AllJobsLaunched) {
357360
AllJobsLaunched = true;
@@ -361,9 +364,6 @@ void TExecutor::Finish() {
361364
}
362365

363366
void TExecutor::UpdateStats() {
364-
if (Infly > MaxSecInfly) {
365-
MaxSecInfly = Infly;
366-
}
367367
std::uint64_t activeSessions = InsistentClient.GetActiveSessions();
368368
if (activeSessions > MaxSecSessions) {
369369
MaxSecSessions = activeSessions;
@@ -382,10 +382,10 @@ void TExecutor::UpdateStats() {
382382
}
383383

384384
void TExecutor::ReportStats() {
385+
Stats.ReportStats(MaxSecSessions, MaxSecReadPromises, MaxSecExecutorPromises);
385386
TInstant now = TInstant::Now();
386387
if (now.Seconds() > LastReportSec) {
387-
Stats.ReportStats(MaxSecInfly, MaxSecSessions, MaxSecReadPromises, MaxSecExecutorPromises);
388-
MaxSecInfly = 0;
388+
Stats.ReportStats(MaxSecSessions, MaxSecReadPromises, MaxSecExecutorPromises);
389389
MaxSecSessions = 0;
390390
MaxSecReadPromises = 0;
391391
MaxSecExecutorPromises = 0;
@@ -442,93 +442,3 @@ void TExecutor::Report(TStringBuilder& out) const {
442442
}
443443
}
444444
}
445-
446-
447-
TExecutorWithRetry::TExecutorWithRetry(const TCommonOptions& opts, TStat& stats)
448-
: TExecutor(opts, stats)
449-
{}
450-
451-
bool TExecutorWithRetry::Execute(const NYdb::NTable::TTableClient::TOperationFunc& func) {
452-
auto threadFunc = [this, func]() {
453-
if (IsStopped()) {
454-
DecrementWaiting();
455-
return;
456-
}
457-
458-
with_lock(Lock) {
459-
--Waiting;
460-
if (Infly < Opts.MaxInfly) {
461-
++Infly;
462-
if (Infly > MaxInfly) {
463-
MaxInfly = Infly;
464-
}
465-
UpdateStats();
466-
} else {
467-
Stats.ReportMaxInfly();
468-
UpdateStats();
469-
return;
470-
}
471-
}
472-
473-
std::shared_ptr<TRetryContext> context = std::make_shared<TRetryContext>(Stats);
474-
475-
auto executeOperation = [this, func]() {
476-
return InsistentClient.ExecuteWithRetry(func);
477-
};
478-
479-
context->HandleStatusFunc = std::make_unique<std::function<void(const TAsyncFinalStatus& resultFuture)>>(
480-
[this, executeOperation, context](const TAsyncFinalStatus& future) mutable {
481-
Y_ABORT_UNLESS(future.HasValue());
482-
TFinalStatus resultStatus = future.GetValue();
483-
if (resultStatus) {
484-
// Reply received
485-
CheckForError(*resultStatus);
486-
if (resultStatus->IsSuccess()) {
487-
//Ok received
488-
Stats.Report(context->LifeTimeStat, resultStatus->GetStatus());
489-
DecrementInfly();
490-
context->HandleStatusFunc.reset();
491-
return;
492-
}
493-
}
494-
if (IsStopped() || TInstant::Now() - context->LifeTimeStat.Start > GlobalTimeout) {
495-
// Application stopped working or global timeout reached. Ok reply hasn't received yet
496-
Stats.Report(context->LifeTimeStat, TInnerStatus::StatusNotFinished);
497-
DecrementInfly();
498-
context->HandleStatusFunc.reset();
499-
return;
500-
}
501-
Stats.Report(context->PerRequestStat, resultStatus);
502-
context->PerRequestStat = Stats.CreateStatUnit();
503-
// Retrying:
504-
executeOperation().Subscribe(*context->HandleStatusFunc);
505-
});
506-
507-
context->Retries.fetch_add(1);
508-
Y_ABORT_UNLESS(context->Retries.load() < 500, "Too much retries");
509-
510-
executeOperation().Subscribe(*context->HandleStatusFunc);
511-
};
512-
513-
if (IsStopped()) {
514-
return false;
515-
}
516-
517-
bool CanLaunchJob = false;
518-
519-
with_lock(Lock) {
520-
if (!AllJobsLaunched) {
521-
CanLaunchJob = true;
522-
++Waiting;
523-
}
524-
}
525-
526-
if (CanLaunchJob) {
527-
if (!InputQueue->AddFunc(threadFunc)) {
528-
DecrementWaiting();
529-
}
530-
}
531-
++InProgressCount;
532-
InProgressSum += InputQueue->Size();
533-
return true;
534-
}

ydb/public/sdk/cpp/tests/slo_workloads/utils/executor.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "statistics.h"
34
#include "utils.h"
45

56
#include <ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/table/table.h>
@@ -56,7 +57,7 @@ class TInsistentClient {
5657
bool Valid = true;
5758
};
5859

59-
struct TOperationContext : public TThrRefBase {
60+
struct TOperationContext {
6061
bool Finished = false;
6162
TAdaptiveLock Lock;
6263
TCheckedIterator RetryIter;
@@ -131,7 +132,6 @@ class TExecutor {
131132
std::uint32_t Wait(TDuration waitTimeout);
132133
bool IsStopped();
133134
void Finish();
134-
std::uint32_t GetTotal() const;
135135
void Report(TStringBuilder& out) const;
136136

137137
protected:
@@ -167,8 +167,6 @@ class TExecutor {
167167
TInstant Deadline;
168168
// Last second we reported Infly
169169
std::uint64_t LastReportSec = 0;
170-
// Max infly for current second
171-
std::uint64_t MaxSecInfly = 0;
172170
// Max Active sessions for current second
173171
std::uint64_t MaxSecSessions = 0;
174172

@@ -178,21 +176,3 @@ class TExecutor {
178176
std::uint64_t MaxSecReadPromises = 0;
179177
std::uint64_t MaxSecExecutorPromises = 0;
180178
};
181-
182-
class TExecutorWithRetry : public TExecutor {
183-
public:
184-
struct TRetryContext {
185-
TRetryContext(TStat& stat)
186-
: LifeTimeStat(stat.CreateStatUnit())
187-
, PerRequestStat(stat.CreateStatUnit())
188-
{}
189-
190-
TStatUnit LifeTimeStat;
191-
TStatUnit PerRequestStat;
192-
std::unique_ptr<std::function<void(const TAsyncFinalStatus& resultFuture)>> HandleStatusFunc;
193-
std::atomic<std::uint64_t> Retries = 0;
194-
};
195-
196-
TExecutorWithRetry(const TCommonOptions& opts, TStat& stats);
197-
bool Execute(const NYdb::NTable::TTableClient::TOperationFunc& func) override;
198-
};

ydb/public/sdk/cpp/tests/slo_workloads/utils/job.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@
55
const std::string LogFileName = "benchmark.log";
66

77

8-
TThreadJob::TThreadJob(const TCommonOptions& opts)
8+
TThreadJob::TThreadJob(const TCommonOptions& opts, const std::string& operationType)
99
: RpsProvider(opts.Rps)
1010
, Prefix(opts.DatabaseOptions.Prefix)
11-
, Stats(
12-
opts.ReactionTime,
13-
opts.ResultFileName,
14-
!opts.DontPushMetrics,
15-
opts.RetryMode
16-
)
11+
, Stats(opts.DontPushMetrics ? std::nullopt : std::make_optional(opts.MetricsPushUrl), operationType)
1712
, StopOnError(opts.StopOnError)
1813
, MaxDelay(opts.ReactionTime)
19-
, UseFollowers(opts.UseFollowers)
2014
{
2115
}
2216

@@ -28,7 +22,7 @@ void TThreadJob::Start(TInstant deadline) {
2822

2923
void TThreadJob::StartThread() {
3024
auto threadFunc = [this]() {
31-
Stats.Reset();
25+
Stats.Start();
3226
RpsProvider.Reset();
3327
DoJob();
3428
Stats.Finish();

ydb/public/sdk/cpp/tests/slo_workloads/utils/job.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#pragma once
22

3+
#include "statistics.h"
34
#include "utils.h"
45

56
#include <util/string/builder.h>
67
#include <util/thread/pool.h>
78

89
class TThreadJob {
910
public:
10-
TThreadJob(const TCommonOptions& opts);
11+
TThreadJob(const TCommonOptions& opts, const std::string& operationType);
1112
virtual ~TThreadJob() = default;
1213

1314
virtual void Start(TInstant deadline);
@@ -31,10 +32,9 @@ class TThreadJob {
3132
TStat Stats;
3233
bool StopOnError;
3334
TDuration MaxDelay;
34-
bool UseFollowers;
3535
};
3636

37-
class TJobContainer : public TThrRefBase {
37+
class TJobContainer {
3838
public:
3939
void Add(TThreadJob* job);
4040
void Start(TInstant deadline = TInstant());

0 commit comments

Comments
 (0)