Skip to content

Commit 3515936

Browse files
committed
correct uptime group-by in viewer/nodes (#15258)
1 parent 8674834 commit 3515936

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

ydb/core/tablet/node_whiteboard.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,9 @@ class TNodeWhiteboardService : public TActorBootstrapped<TNodeWhiteboardService>
721721
auto& endpoint = *SystemStateInfo.AddEndpoints();
722722
endpoint.SetName(ev->Get()->Name);
723723
endpoint.SetAddress(ev->Get()->Address);
724+
std::sort(SystemStateInfo.MutableEndpoints()->begin(), SystemStateInfo.MutableEndpoints()->end(), [](const auto& a, const auto& b) {
725+
return a.GetName() < b.GetName();
726+
});
724727
SystemStateInfo.SetChangeTime(ctx.Now().MilliSeconds());
725728
}
726729

ydb/core/viewer/viewer_nodes.h

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class TJsonNodes : public TViewerPipeClient {
206206
bool HasDisks = false;
207207
bool GotDatabaseFromDatabaseBoardInfo = false;
208208
bool GotDatabaseFromResourceBoardInfo = false;
209-
int UptimeSeconds = 0;
209+
std::optional<int> UptimeSeconds = 0;
210210
ui32 Connections = 0;
211211
ui64 SendThroughput = 0;
212212
ui64 ReceiveThroughput = 0;
@@ -460,11 +460,19 @@ class TJsonNodes : public TViewerPipeClient {
460460
return TInstant::MilliSeconds(SystemState.GetDisconnectTime());
461461
}
462462

463-
int GetUptimeSeconds(TInstant now) const {
463+
std::optional<int> GetUptimeSeconds(TInstant now) const {
464464
if (Disconnected) {
465-
return static_cast<int>(GetDisconnectTime().Seconds()) - static_cast<int>(now.Seconds()); // negative for disconnected nodes
465+
if (SystemState.HasDisconnectTime()) {
466+
return static_cast<int>(GetDisconnectTime().Seconds()) - static_cast<int>(now.Seconds()); // negative for disconnected nodes
467+
} else {
468+
return std::nullopt;
469+
}
466470
} else {
467-
return static_cast<int>(now.Seconds()) - static_cast<int>(GetStartTime().Seconds());
471+
if (SystemState.HasStartTime()) {
472+
return static_cast<int>(now.Seconds()) - static_cast<int>(GetStartTime().Seconds());
473+
} else {
474+
return std::nullopt;
475+
}
468476
}
469477
}
470478

@@ -538,39 +546,42 @@ class TJsonNodes : public TViewerPipeClient {
538546
}
539547

540548
TString GetUptimeForGroup() const {
541-
if (!Disconnected && UptimeSeconds >= 0) {
542-
if (UptimeSeconds < 60 * 10) {
543-
return "up <10m";
544-
}
545-
if (UptimeSeconds < 60 * 60) {
546-
return "up <1h";
547-
}
548-
if (UptimeSeconds < 60 * 60 * 24) {
549-
return "up <24h";
550-
}
551-
if (UptimeSeconds < 60 * 60 * 24 * 7) {
552-
return "up 24h+";
553-
}
554-
return "up 1 week+";
555-
} else {
556-
if (SystemState.HasDisconnectTime()) {
557-
if (UptimeSeconds > -60 * 10) {
549+
if (UptimeSeconds) {
550+
if (*UptimeSeconds >= 0) {
551+
if (*UptimeSeconds < 60 * 10) {
552+
return "up <10m";
553+
}
554+
if (*UptimeSeconds < 60 * 60) {
555+
return "up <1h";
556+
}
557+
if (*UptimeSeconds < 60 * 60 * 24) {
558+
return "up <24h";
559+
}
560+
if (*UptimeSeconds < 60 * 60 * 24 * 7) {
561+
return "up 24h+";
562+
}
563+
return "up 1 week+";
564+
} else {
565+
if (*UptimeSeconds > -60 * 10) {
558566
return "down <10m";
559567
}
560-
if (UptimeSeconds > -60 * 60) {
568+
if (*UptimeSeconds > -60 * 60) {
561569
return "down <1h";
562570
}
563-
if (UptimeSeconds > -60 * 60 * 24) {
571+
if (*UptimeSeconds > -60 * 60 * 24) {
564572
return "down <24h";
565573
}
566-
if (UptimeSeconds > -60 * 60 * 24 * 7) {
574+
if (*UptimeSeconds > -60 * 60 * 24 * 7) {
567575
return "down 24h+";
568576
}
569577
return "down 1 week+";
570-
} else {
571-
return "disconnected";
572578
}
573579
}
580+
if (Disconnected) {
581+
return "disconnected";
582+
} else {
583+
return "unknown";
584+
}
574585
}
575586

576587
TString GetVersionForGroup() const {
@@ -682,7 +693,7 @@ class TJsonNodes : public TViewerPipeClient {
682693
case ENodeFields::Missing:
683694
return MissingDisks;
684695
case ENodeFields::Uptime:
685-
return UptimeSeconds;
696+
return UptimeSeconds.value_or(0);
686697
case ENodeFields::SystemState:
687698
return static_cast<int>(GetOverall());
688699
case ENodeFields::ConnectStatus:
@@ -937,6 +948,9 @@ class TJsonNodes : public TViewerPipeClient {
937948
FilterGroup = params.Get("filter_group");
938949
FilterGroupBy = ParseENodeFields(params.Get("filter_group_by"));
939950
FieldsRequired.set(+FilterGroupBy);
951+
if (FilterGroupBy == ENodeFields::Uptime) {
952+
FieldsRequired.set(+ENodeFields::DisconnectTime);
953+
}
940954
}
941955

942956
OffloadMerge = FromStringWithDefault<bool>(params.Get("offload_merge"), OffloadMerge);
@@ -1034,6 +1048,9 @@ class TJsonNodes : public TViewerPipeClient {
10341048
NeedGroup = true;
10351049
GroupBy = ParseENodeFields(group);
10361050
FieldsRequired.set(+GroupBy);
1051+
if (GroupBy == ENodeFields::Uptime) {
1052+
FieldsRequired.set(+ENodeFields::DisconnectTime);
1053+
}
10371054
NeedSort = false;
10381055
NeedLimit = false;
10391056
}
@@ -1094,7 +1111,7 @@ class TJsonNodes : public TViewerPipeClient {
10941111
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
10951112
auto* domain = domains->GetDomain();
10961113
DomainPath = "/" + domain->Name;
1097-
if (ProblemNodesOnly || GroupBy == ENodeFields::Uptime) {
1114+
if (ProblemNodesOnly || FieldsRequired.test(+ENodeFields::Uptime) || FieldsRequired.test(+ENodeFields::DisconnectTime)) {
10981115
FieldsRequired.set(+ENodeFields::SystemState);
10991116
TTabletId rootHiveId = domains->GetHive();
11001117
HivesToAsk.push_back(rootHiveId);
@@ -1294,7 +1311,7 @@ class TJsonNodes : public TViewerPipeClient {
12941311
if (UptimeSeconds > 0 && FieldsAvailable.test(+ENodeFields::SystemState)) {
12951312
TNodeView nodeView;
12961313
for (TNode* node : NodeView) {
1297-
if (node->UptimeSeconds < UptimeSeconds) {
1314+
if (node->UptimeSeconds.value_or(0) < UptimeSeconds) {
12981315
nodeView.push_back(node);
12991316
}
13001317
}
@@ -1446,7 +1463,7 @@ class TJsonNodes : public TViewerPipeClient {
14461463
NeedSort = false;
14471464
break;
14481465
case ENodeFields::Uptime:
1449-
SortCollection(NodeView, [](const TNode* node) { return node->UptimeSeconds; }, ReverseSort);
1466+
SortCollection(NodeView, [](const TNode* node) { return node->UptimeSeconds.value_or(0); }, ReverseSort);
14501467
NeedSort = false;
14511468
break;
14521469
case ENodeFields::Memory:
@@ -3126,7 +3143,7 @@ class TJsonNodes : public TViewerPipeClient {
31263143
jsonNode.SetDatabase(node->Database);
31273144
}
31283145
if (node->UptimeSeconds) {
3129-
jsonNode.SetUptimeSeconds(node->UptimeSeconds);
3146+
jsonNode.SetUptimeSeconds(*(node->UptimeSeconds));
31303147
}
31313148
if (node->Disconnected) {
31323149
jsonNode.SetDisconnected(node->Disconnected);

0 commit comments

Comments
 (0)