Skip to content

Commit c3dbb7f

Browse files
authored
Statistics service metrics (#8322)
1 parent b83f29e commit c3dbb7f

File tree

8 files changed

+60
-2
lines changed

8 files changed

+60
-2
lines changed

ydb/core/protos/counters_statistics_aggregator.proto

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,22 @@ enum ETxTypes {
2525
TXTYPE_ANALYZE_TABLE_DELIVERY_PROBLEM = 15 [(TxTypeOpts) = {Name: "TTxAnalyzeTableDeliveryProblem"}];
2626
TXTYPE_ANALYZE_DEADLINE = 16 [(TxTypeOpts) = {Name: "TTxAnalyzeDeadline"}];
2727
}
28+
29+
enum ESimpleCounters {
30+
COUNTER_FORCE_TRAVERSALS_INFLIGHT_SIZE = 0 [(CounterOpts) = {Name: "ForceTraversalsInflightSize"}];
31+
COUNTER_AGGREGATION_TIME = 1 [(CounterOpts) = {Name: "AggregationTime"}];
32+
COUNTER_FORCE_TRAVERSAL_INFLIGHT_MAX_TIME = 2 [(CounterOpts) = {Name: "ForceTraversalsInflightMaxTime"}];
33+
}
34+
35+
enum ECumulativeCounters {
36+
COUNTER_CUMULATIVE_IGNORE = 0;
37+
}
38+
39+
enum EPercentileCounters {
40+
option (GlobalCounterOpts) = {
41+
Ranges { Value: 0 Name: "0 ms" }
42+
Ranges { Value: 1 Name: "1 ms" }
43+
};
44+
45+
COUNTER_PERCENTILE_IGNORE = 0;
46+
}

ydb/core/statistics/aggregator/aggregator_impl.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <ydb/core/engine/minikql/flat_local_tx_factory.h>
77
#include <ydb/core/protos/feature_flags.pb.h>
8+
#include <ydb/core/protos/counters_statistics_aggregator.pb.h>
9+
#include <ydb/core/tablet/tablet_counters_protobuf.h>
810
#include <ydb/core/tx/datashard/datashard.h>
911
#include <ydb/core/tx/scheme_cache/scheme_cache.h>
1012

@@ -21,6 +23,14 @@ TStatisticsAggregator::TStatisticsAggregator(const NActors::TActorId& tablet, TT
2123

2224
auto seed = std::random_device{}();
2325
RandomGenerator.seed(seed);
26+
27+
TabletCountersPtr.Reset(new TProtobufTabletCounters<
28+
ESimpleCounters_descriptor,
29+
ECumulativeCounters_descriptor,
30+
EPercentileCounters_descriptor,
31+
ETxTypes_descriptor
32+
>());
33+
TabletCounters = TabletCountersPtr.Get();
2434
}
2535

2636
void TStatisticsAggregator::OnDetach(const TActorContext& ctx) {
@@ -34,6 +44,7 @@ void TStatisticsAggregator::OnTabletDead(TEvTablet::TEvTabletDead::TPtr&, const
3444
void TStatisticsAggregator::OnActivateExecutor(const TActorContext& ctx) {
3545
SA_LOG_I("[" << TabletID() << "] OnActivateExecutor");
3646

47+
Executor()->RegisterExternalTabletCounters(TabletCountersPtr);
3748
Execute(CreateTxInitSchema(), ctx);
3849
}
3950

@@ -483,8 +494,15 @@ void TStatisticsAggregator::Handle(TEvPrivate::TEvRequestDistribution::TPtr&) {
483494
}
484495

485496
void TStatisticsAggregator::Handle(TEvStatistics::TEvAggregateKeepAlive::TPtr& ev) {
497+
const auto round = ev->Get()->Record.GetRound();
498+
if (round == GlobalTraversalRound && AggregationRequestBeginTime) {
499+
TInstant now = AppData(TlsActivationContext->AsActorContext())->TimeProvider->Now();
500+
TDuration time = now - AggregationRequestBeginTime;
501+
TabletCounters->Simple()[COUNTER_AGGREGATION_TIME].Set(time.MicroSeconds());
502+
}
503+
486504
auto ack = std::make_unique<TEvStatistics::TEvAggregateKeepAliveAck>();
487-
ack->Record.SetRound(ev->Get()->Record.GetRound());
505+
ack->Record.SetRound(round);
488506
Send(ev->Sender, ack.release());
489507
Schedule(KeepAliveTimeout, new TEvPrivate::TEvAckTimeout(++KeepAliveSeqNo));
490508
}
@@ -779,6 +797,7 @@ void TStatisticsAggregator::DeleteForceTraversalOperation(const TString& operati
779797
}
780798

781799
ForceTraversals.remove_if([operationId](const TForceTraversalOperation& elem) { return elem.OperationId == operationId;});
800+
TabletCounters->Simple()[COUNTER_FORCE_TRAVERSALS_INFLIGHT_SIZE].Set(ForceTraversals.size());
782801
}
783802

784803
TStatisticsAggregator::TForceTraversalTable* TStatisticsAggregator::ForceTraversalTable(const TString& operationId, const TPathId& pathId) {

ydb/core/statistics/aggregator/aggregator_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <ydb/core/cms/console/configs_dispatcher.h>
1515
#include <ydb/core/cms/console/console.h>
1616

17+
#include <ydb/core/tablet/tablet_counters.h>
1718
#include <ydb/core/tablet_flat/tablet_flat_executed.h>
1819
#include <ydb/core/tx/datashard/datashard.h>
1920
#include <ydb/core/tx/scheme_cache/scheme_cache.h>
@@ -228,6 +229,11 @@ class TStatisticsAggregator : public TActor<TStatisticsAggregator>, public NTabl
228229

229230
std::mt19937_64 RandomGenerator;
230231

232+
TTabletCountersBase* TabletCounters;
233+
TAutoPtr<TTabletCountersBase> TabletCountersPtr;
234+
235+
TInstant AggregationRequestBeginTime;
236+
231237
bool EnableStatistics = false;
232238
bool EnableColumnStatistics = false;
233239

ydb/core/statistics/aggregator/tx_aggr_stat_response.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ struct TStatisticsAggregator::TTxAggregateStatisticsResponse : public TTxBase {
2828

2929
++Self->KeepAliveSeqNo; // cancel timeout events
3030

31+
Self->TabletCounters->Simple()[COUNTER_AGGREGATION_TIME].Set(0);
32+
Self->AggregationRequestBeginTime = TInstant::Zero();
33+
3134
NIceDb::TNiceDb db(txc.DB);
3235

3336
for (auto& column : Record.GetColumns()) {
@@ -122,6 +125,7 @@ struct TStatisticsAggregator::TTxAggregateStatisticsResponse : public TTxBase {
122125
case EAction::SendAggregate:
123126
ctx.Send(MakeStatServiceID(Self->SelfId().NodeId()), Request.release());
124127
ctx.Schedule(KeepAliveTimeout, new TEvPrivate::TEvAckTimeout(++Self->KeepAliveSeqNo));
128+
Self->AggregationRequestBeginTime = AppData(ctx)->TimeProvider->Now();
125129
break;
126130

127131
default:

ydb/core/statistics/aggregator/tx_analyze.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct TStatisticsAggregator::TTxAnalyze : public TTxBase {
8282
}
8383

8484
Self->ForceTraversals.emplace_back(operation);
85+
Self->TabletCounters->Simple()[COUNTER_FORCE_TRAVERSALS_INFLIGHT_SIZE].Set(Self->ForceTraversals.size());
8586

8687
db.Table<Schema::ForceTraversalOperations>().Key(operationId).Update(
8788
NIceDb::TUpdate<Schema::ForceTraversalOperations::OperationId>(operationId),

ydb/core/statistics/aggregator/tx_init.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ struct TStatisticsAggregator::TTxInit : public TTxBase {
210210
}
211211
}
212212

213+
Self->TabletCounters->Simple()[COUNTER_FORCE_TRAVERSALS_INFLIGHT_SIZE].Set(Self->ForceTraversals.size());
214+
213215
SA_LOG_D("[" << Self->TabletID() << "] Loaded ForceTraversalOperations: "
214216
<< "table count# " << Self->ForceTraversals.size());
215217
}

ydb/core/statistics/aggregator/tx_response_tablet_distribution.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct TStatisticsAggregator::TTxResponseTabletDistribution : public TTxBase {
101101
case EAction::SendAggregate:
102102
ctx.Send(MakeStatServiceID(Self->SelfId().NodeId()), AggregateStatisticsRequest.release());
103103
ctx.Schedule(KeepAliveTimeout, new TEvPrivate::TEvAckTimeout(++Self->KeepAliveSeqNo));
104+
Self->AggregationRequestBeginTime = AppData(ctx)->TimeProvider->Now();
104105
break;
105106

106107
default:

ydb/core/statistics/aggregator/tx_schedule_traversal.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ struct TStatisticsAggregator::TTxScheduleTrasersal : public TTxBase {
1111

1212
TTxType GetTxType() const override { return TXTYPE_SCHEDULE_TRAVERSAL; }
1313

14-
bool Execute(TTransactionContext& txc, const TActorContext&) override {
14+
bool Execute(TTransactionContext& txc, const TActorContext& ctx) override {
1515

1616
if (!Self->EnableColumnStatistics) {
1717
return true;
1818
}
1919

20+
TDuration time = TDuration ::Zero();
21+
if (!Self->ForceTraversals.empty()) {
22+
time = ctx.Now() - Self->ForceTraversals.front().CreatedAt;
23+
}
24+
Self->TabletCounters->Simple()[COUNTER_FORCE_TRAVERSAL_INFLIGHT_MAX_TIME].Set(time.MicroSeconds());
25+
2026
if (Self->TraversalPathId) {
2127
SA_LOG_T("[" << Self->TabletID() << "] TTxScheduleTrasersal::Execute. Traverse is in progress. PathId " << Self->TraversalPathId);
2228
return true;

0 commit comments

Comments
 (0)