@@ -206,7 +206,7 @@ class TJsonNodes : public TViewerPipeClient {
206
206
bool HasDisks = false ;
207
207
bool GotDatabaseFromDatabaseBoardInfo = false ;
208
208
bool GotDatabaseFromResourceBoardInfo = false ;
209
- int UptimeSeconds = 0 ;
209
+ std::optional< int > UptimeSeconds = 0 ;
210
210
ui32 Connections = 0 ;
211
211
ui64 SendThroughput = 0 ;
212
212
ui64 ReceiveThroughput = 0 ;
@@ -460,11 +460,19 @@ class TJsonNodes : public TViewerPipeClient {
460
460
return TInstant::MilliSeconds (SystemState.GetDisconnectTime ());
461
461
}
462
462
463
- int GetUptimeSeconds (TInstant now) const {
463
+ std::optional< int > GetUptimeSeconds (TInstant now) const {
464
464
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
+ }
466
470
} 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
+ }
468
476
}
469
477
}
470
478
@@ -538,39 +546,42 @@ class TJsonNodes : public TViewerPipeClient {
538
546
}
539
547
540
548
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 ) {
558
566
return " down <10m" ;
559
567
}
560
- if (UptimeSeconds > -60 * 60 ) {
568
+ if (* UptimeSeconds > -60 * 60 ) {
561
569
return " down <1h" ;
562
570
}
563
- if (UptimeSeconds > -60 * 60 * 24 ) {
571
+ if (* UptimeSeconds > -60 * 60 * 24 ) {
564
572
return " down <24h" ;
565
573
}
566
- if (UptimeSeconds > -60 * 60 * 24 * 7 ) {
574
+ if (* UptimeSeconds > -60 * 60 * 24 * 7 ) {
567
575
return " down 24h+" ;
568
576
}
569
577
return " down 1 week+" ;
570
- } else {
571
- return " disconnected" ;
572
578
}
573
579
}
580
+ if (Disconnected) {
581
+ return " disconnected" ;
582
+ } else {
583
+ return " unknown" ;
584
+ }
574
585
}
575
586
576
587
TString GetVersionForGroup () const {
@@ -682,7 +693,7 @@ class TJsonNodes : public TViewerPipeClient {
682
693
case ENodeFields::Missing:
683
694
return MissingDisks;
684
695
case ENodeFields::Uptime:
685
- return UptimeSeconds;
696
+ return UptimeSeconds. value_or ( 0 ) ;
686
697
case ENodeFields::SystemState:
687
698
return static_cast <int >(GetOverall ());
688
699
case ENodeFields::ConnectStatus:
@@ -937,6 +948,9 @@ class TJsonNodes : public TViewerPipeClient {
937
948
FilterGroup = params.Get (" filter_group" );
938
949
FilterGroupBy = ParseENodeFields (params.Get (" filter_group_by" ));
939
950
FieldsRequired.set (+FilterGroupBy);
951
+ if (FilterGroupBy == ENodeFields::Uptime) {
952
+ FieldsRequired.set (+ENodeFields::DisconnectTime);
953
+ }
940
954
}
941
955
942
956
OffloadMerge = FromStringWithDefault<bool >(params.Get (" offload_merge" ), OffloadMerge);
@@ -1034,6 +1048,9 @@ class TJsonNodes : public TViewerPipeClient {
1034
1048
NeedGroup = true ;
1035
1049
GroupBy = ParseENodeFields (group);
1036
1050
FieldsRequired.set (+GroupBy);
1051
+ if (GroupBy == ENodeFields::Uptime) {
1052
+ FieldsRequired.set (+ENodeFields::DisconnectTime);
1053
+ }
1037
1054
NeedSort = false ;
1038
1055
NeedLimit = false ;
1039
1056
}
@@ -1094,7 +1111,7 @@ class TJsonNodes : public TViewerPipeClient {
1094
1111
TIntrusivePtr<TDomainsInfo> domains = AppData ()->DomainsInfo ;
1095
1112
auto * domain = domains->GetDomain ();
1096
1113
DomainPath = " /" + domain->Name ;
1097
- if (ProblemNodesOnly || GroupBy == ENodeFields::Uptime ) {
1114
+ if (ProblemNodesOnly || FieldsRequired. test (+ENodeFields::Uptime) || FieldsRequired. test (+ ENodeFields::DisconnectTime) ) {
1098
1115
FieldsRequired.set (+ENodeFields::SystemState);
1099
1116
TTabletId rootHiveId = domains->GetHive ();
1100
1117
HivesToAsk.push_back (rootHiveId);
@@ -1294,7 +1311,7 @@ class TJsonNodes : public TViewerPipeClient {
1294
1311
if (UptimeSeconds > 0 && FieldsAvailable.test (+ENodeFields::SystemState)) {
1295
1312
TNodeView nodeView;
1296
1313
for (TNode* node : NodeView) {
1297
- if (node->UptimeSeconds < UptimeSeconds) {
1314
+ if (node->UptimeSeconds . value_or ( 0 ) < UptimeSeconds) {
1298
1315
nodeView.push_back (node);
1299
1316
}
1300
1317
}
@@ -1446,7 +1463,7 @@ class TJsonNodes : public TViewerPipeClient {
1446
1463
NeedSort = false ;
1447
1464
break ;
1448
1465
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);
1450
1467
NeedSort = false ;
1451
1468
break ;
1452
1469
case ENodeFields::Memory:
@@ -3126,7 +3143,7 @@ class TJsonNodes : public TViewerPipeClient {
3126
3143
jsonNode.SetDatabase (node->Database );
3127
3144
}
3128
3145
if (node->UptimeSeconds ) {
3129
- jsonNode.SetUptimeSeconds (node->UptimeSeconds );
3146
+ jsonNode.SetUptimeSeconds (*( node->UptimeSeconds ) );
3130
3147
}
3131
3148
if (node->Disconnected ) {
3132
3149
jsonNode.SetDisconnected (node->Disconnected );
0 commit comments