Skip to content

Commit 9adb3a0

Browse files
authored
Add epoch version & nodes count sensors in NodeBroker & DynamicNameserver (#20625)
1 parent b9f0d8d commit 9adb3a0

13 files changed

+78
-0
lines changed

ydb/core/mind/dynamic_nameserver.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "dynamic_nameserver_impl.h"
22

33
#include <ydb/core/base/appdata.h>
4+
#include <ydb/core/base/counters.h>
45
#include <ydb/core/base/nameservice.h>
56
#include <ydb/core/mon/mon.h>
67
#include <ydb/library/services/services.pb.h>
@@ -91,6 +92,7 @@ class TActorCacheMiss : public TActor<TActorCacheMiss<TCacheMiss>>, public TCach
9192
ResetInterconnectProxyConfig(NodeId, ctx);
9293
ListNodesCache->Invalidate(); // node was erased
9394
}
95+
Owner->UpdateCounters();
9496
OnError(rec.GetStatus().GetReason(), ctx);
9597
return;
9698
}
@@ -105,6 +107,7 @@ class TActorCacheMiss : public TActor<TActorCacheMiss<TCacheMiss>>, public TCach
105107
ResetInterconnectProxyConfig(NodeId, ctx);
106108
Config->DynamicNodes.emplace(NodeId, node);
107109

110+
Owner->UpdateCounters();
108111
OnSuccess(ctx);
109112
}
110113

@@ -240,6 +243,13 @@ void TDynamicNameserver::Bootstrap(const TActorContext &ctx)
240243
OpenPipe(domain->DomainUid);
241244
}
242245

246+
auto counters = GetServiceCounters(AppData(ctx)->Counters, "utils")->GetSubgroup("component", "nameserver");
247+
ActiveDynamicNodesCounter = counters->GetCounter("ActiveDynamicNodes");
248+
ExpiredDynamicNodesCounter = counters->GetCounter("ExpireDynamicNodes");
249+
StaticNodesCounter = counters->GetCounter("StaticNodes");
250+
EpochVersionCounter = counters->GetCounter("EpochVersion");
251+
UpdateCounters();
252+
243253
Send(MakeBlobStorageNodeWardenID(SelfId().NodeId()), new TEvNodeWardenQueryStorageConfig(true));
244254

245255
Become(&TDynamicNameserver::StateFunc);
@@ -282,6 +292,7 @@ void TDynamicNameserver::ReplaceNameserverSetup(TIntrusivePtr<TTableNameserverSe
282292
for (const auto& subscriber : StaticNodeChangeSubscribers) {
283293
TActivationContext::Send(new IEventHandle(SelfId(), subscriber, new TEvInterconnect::TEvListNodes));
284294
}
295+
UpdateCounters();
285296
}
286297
}
287298

@@ -518,6 +529,8 @@ void TDynamicNameserver::UpdateState(const NKikimrNodeBroker::TNodesInfo &rec,
518529
}
519530
config->Epoch = rec.GetEpoch();
520531
}
532+
533+
UpdateCounters();
521534
}
522535

523536
void TDynamicNameserver::OnPipeDestroyed(ui32 domain, const TActorContext &ctx)
@@ -542,6 +555,18 @@ void TDynamicNameserver::OnPipeDestroyed(ui32 domain, const TActorContext &ctx)
542555
OpenPipe(DynamicConfigs[domain]->NodeBrokerPipe);
543556
}
544557

558+
void TDynamicNameserver::UpdateCounters() {
559+
auto info = AppData()->DomainsInfo;
560+
if (info->Domain) {
561+
const auto &config = DynamicConfigs[info->Domain->DomainUid];
562+
563+
*EpochVersionCounter = config->Epoch.Version;
564+
*ActiveDynamicNodesCounter = config->DynamicNodes.size();
565+
*ExpiredDynamicNodesCounter = config->ExpiredNodes.size();
566+
*StaticNodesCounter = StaticConfig->StaticNodeTable.size();
567+
}
568+
}
569+
545570
void TDynamicNameserver::Handle(TEvInterconnect::TEvResolveNode::TPtr &ev,
546571
const TActorContext &ctx)
547572
{
@@ -805,6 +830,8 @@ void TDynamicNameserver::Handle(TEvNodeBroker::TEvUpdateNodes::TPtr &ev, const T
805830
break;
806831
}
807832
}
833+
834+
UpdateCounters();
808835
}
809836

810837
void TDynamicNameserver::Handle(TEvNodeBroker::TEvSyncNodesResponse::TPtr &ev, const TActorContext &ctx)

ydb/core/mind/dynamic_nameserver_impl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ class TDynamicNameserver : public TActorBootstrapped<TDynamicNameserver> {
261261
void OnPipeDestroyed(ui32 domain,
262262
const TActorContext &ctx);
263263

264+
void UpdateCounters();
265+
264266
void Handle(TEvInterconnect::TEvResolveNode::TPtr &ev, const TActorContext &ctx);
265267
void Handle(TEvResolveAddress::TPtr &ev, const TActorContext &ctx);
266268
void Handle(TEvInterconnect::TEvListNodes::TPtr &ev, const TActorContext &ctx);
@@ -305,6 +307,11 @@ class TDynamicNameserver : public TActorBootstrapped<TDynamicNameserver> {
305307
bool SyncInProgress = false;
306308
ui64 SyncCookie = 0;
307309
ui64 SeqNo = 0;
310+
311+
::NMonitoring::TDynamicCounters::TCounterPtr StaticNodesCounter;
312+
::NMonitoring::TDynamicCounters::TCounterPtr ActiveDynamicNodesCounter;
313+
::NMonitoring::TDynamicCounters::TCounterPtr ExpiredDynamicNodesCounter;
314+
::NMonitoring::TDynamicCounters::TCounterPtr EpochVersionCounter;
308315
};
309316

310317
} // NNodeBroker

ydb/core/mind/dynamic_nameserver_mon.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ TString ToString(TInstant t)
2121
return t.FormatLocalTime("%d %b %Y %H:%M:%S %Z");
2222
}
2323

24+
TString ToString(EProtocolState s)
25+
{
26+
switch (s) {
27+
case EProtocolState::Connecting:
28+
return "Connecting";
29+
case EProtocolState::UseEpochProtocol:
30+
return "EpochProtocol";
31+
case EProtocolState::UseDeltaProtocol:
32+
return "DeltaProtocol";
33+
}
34+
return "Unknown";
35+
}
36+
2437
void OutputStaticContent(IOutputStream &str)
2538
{
2639
str << R"__(
@@ -194,6 +207,10 @@ void TDynamicNameserver::Handle(NMon::TEvHttpInfo::TPtr &ev, const TActorContext
194207
<< " <td class='right-align'>Max dynamic node ID:</td>" << Endl
195208
<< " <td>" << config->MaxDynamicNodeId << "</td>" << Endl
196209
<< " </tr>" << Endl
210+
<< " <tr>" << Endl
211+
<< " <td class='right-align'>Protocol state:</td>" << Endl
212+
<< " <td>" << ToString(ProtocolState) << "</td>" << Endl
213+
<< " </tr>" << Endl
197214
<< " </tbody>" << Endl
198215
<< "</table></div>" << Endl;
199216

ydb/core/mind/node_broker.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,13 @@ bool TNodeBroker::HasOutdatedSubscription(TActorId subscriber, ui64 newSeqNo) co
786786
return false;
787787
}
788788

789+
void TNodeBroker::UpdateCommittedStateCounters() {
790+
TabletCounters->Simple()[COUNTER_ACTIVE_NODES].Set(Committed.Nodes.size());
791+
TabletCounters->Simple()[COUNTER_EXPIRED_NODES].Set(Committed.ExpiredNodes.size());
792+
TabletCounters->Simple()[COUNTER_REMOVED_NODES].Set(Committed.RemovedNodes.size());
793+
TabletCounters->Simple()[COUNTER_EPOCH_VERSION].Set(Committed.Epoch.Version);
794+
}
795+
789796
void TNodeBroker::TState::LoadConfigFromProto(const NKikimrNodeBroker::TConfig &config)
790797
{
791798
Config = config;

ydb/core/mind/node_broker__extend_lease.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class TNodeBroker::TTxExtendLease : public TTransactionBase<TNodeBroker> {
9090
Self->AddNodeToUpdateNodesLog(node);
9191
Self->ScheduleProcessSubscribersQueue(ctx);
9292
}
93+
94+
Self->UpdateCommittedStateCounters();
9395
}
9496

9597
private:

ydb/core/mind/node_broker__graceful_shutdown.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class TNodeBroker::TTxGracefulShutdown : public TTransactionBase<TNodeBroker> {
5252
Self->Committed.ReleaseSlotIndex(Self->Committed.Nodes.at(Event->Get()->Record.GetNodeId()));
5353
}
5454
ctx.Send(Event->Sender, Response.Release());
55+
56+
Self->UpdateCommittedStateCounters();
5557
}
5658

5759
private:

ydb/core/mind/node_broker__migrate_state.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class TNodeBroker::TTxMigrateState : public TTransactionBase<TNodeBroker> {
106106
NKikimrNodeBroker::TVersionInfo versionInfo;
107107
versionInfo.SetSupportDeltaProtocol(true);
108108
Self->SignalTabletActive(ctx, versionInfo.SerializeAsString());
109+
110+
Self->UpdateCommittedStateCounters();
109111
} else {
110112
Self->Execute(Self->CreateTxMigrateState(std::move(DbChanges)));
111113
}

ydb/core/mind/node_broker__register_node.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ class TNodeBroker::TTxRegisterNode : public TTransactionBase<TNodeBroker> {
235235
}
236236

237237
Reply(ctx);
238+
239+
Self->UpdateCommittedStateCounters();
238240
}
239241

240242
private:

ydb/core/mind/node_broker__update_config.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class TNodeBroker::TTxUpdateConfig : public TTransactionBase<TNodeBroker> {
9292
"TTxUpdateConfig reply with: " << Response->ToString());
9393
ctx.Send(Response);
9494
}
95+
96+
Self->UpdateCommittedStateCounters();
9597
}
9698

9799
private:

ydb/core/mind/node_broker__update_config_subscription.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class TNodeBroker::TTxUpdateConfigSubscription : public TTransactionBase<TNodeBr
4141
"Using new subscription id=" << SubscriptionId);
4242

4343
Self->Committed.ConfigSubscriptionId = SubscriptionId;
44+
45+
Self->UpdateCommittedStateCounters();
4446
}
4547

4648
private:

ydb/core/mind/node_broker__update_epoch.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class TNodeBroker::TTxUpdateEpoch : public TTransactionBase<TNodeBroker> {
3636
Self->PrepareUpdateNodesLog();
3737
Self->ProcessDelayedListNodesRequests();
3838
Self->ScheduleProcessSubscribersQueue(ctx);
39+
40+
Self->UpdateCommittedStateCounters();
3941
}
4042

4143
private:

ydb/core/mind/node_broker_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ class TNodeBroker : public TActor<TNodeBroker>
305305
void RemoveSubscriber(TActorId subscriber, const TActorContext &ctx);
306306
bool HasOutdatedSubscription(TActorId subscriber, ui64 newSeqNo) const;
307307

308+
void UpdateCommittedStateCounters();
309+
308310
void Handle(TEvConsole::TEvConfigNotificationRequest::TPtr &ev,
309311
const TActorContext &ctx);
310312
void Handle(TEvConsole::TEvReplaceConfigSubscriptionsResponse::TPtr &ev,

ydb/core/protos/counters_node_broker.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ enum ESimpleCounters {
1010
COUNTER_EPOCH_SIZE_BYTES = 0 [(CounterOpts) = {Name: "EpochSizeBytes"}];
1111
COUNTER_EPOCH_DELTAS_SIZE_BYTES = 1 [(CounterOpts) = {Name: "EpochDeltasSizeBytes"}];
1212
COUNTER_UPDATE_NODES_LOG_SIZE_BYTES = 2 [(CounterOpts) = {Name: "UpdateNodesLogSizeBytes"}];
13+
COUNTER_EPOCH_VERSION = 3 [(CounterOpts) = {Name: "EpochVersion"}];
14+
COUNTER_ACTIVE_NODES = 4 [(CounterOpts) = {Name: "ActiveNodes"}];
15+
COUNTER_EXPIRED_NODES = 5 [(CounterOpts) = {Name: "ExpiredNodes"}];
16+
COUNTER_REMOVED_NODES = 6 [(CounterOpts) = {Name: "RemovedNodes"}];
1317
}
1418

1519
enum ECumulativeCounters {

0 commit comments

Comments
 (0)