@@ -26,6 +26,7 @@ use nexus_sled_agent_shared::inventory::{
26
26
use omicron_uuid_kinds:: {
27
27
DatasetUuid , OmicronZoneUuid , PhysicalDiskUuid , ZpoolUuid ,
28
28
} ;
29
+ use std:: collections:: HashMap ;
29
30
use strum:: IntoEnumIterator ;
30
31
use tabled:: Tabled ;
31
32
use tufaceous_artifact:: ArtifactHash ;
@@ -42,6 +43,7 @@ pub struct CollectionDisplay<'a> {
42
43
include_sleds : bool ,
43
44
include_orphaned_datasets : bool ,
44
45
include_clickhouse_keeper_membership : bool ,
46
+ include_cockroach_status : bool ,
45
47
long_string_formatter : LongStringFormatter ,
46
48
}
47
49
@@ -54,6 +56,7 @@ impl<'a> CollectionDisplay<'a> {
54
56
include_sleds : true ,
55
57
include_orphaned_datasets : true ,
56
58
include_clickhouse_keeper_membership : true ,
59
+ include_cockroach_status : true ,
57
60
long_string_formatter : LongStringFormatter :: new ( ) ,
58
61
}
59
62
}
@@ -94,6 +97,15 @@ impl<'a> CollectionDisplay<'a> {
94
97
self
95
98
}
96
99
100
+ /// Control display of Cockroach cluster information (defaults to true).
101
+ pub fn include_cockroach_status (
102
+ & mut self ,
103
+ include_cockroach_status : bool ,
104
+ ) -> & mut Self {
105
+ self . include_cockroach_status = include_cockroach_status;
106
+ self
107
+ }
108
+
97
109
/// Show long strings (defaults to false).
98
110
pub fn show_long_strings ( & mut self , show_long_strings : bool ) -> & mut Self {
99
111
self . long_string_formatter . show_long_strings = show_long_strings;
@@ -111,6 +123,7 @@ impl<'a> CollectionDisplay<'a> {
111
123
. include_clickhouse_keeper_membership (
112
124
filter. include_keeper_membership ( ) ,
113
125
)
126
+ . include_cockroach_status ( filter. include_cockroach_status ( ) )
114
127
}
115
128
}
116
129
@@ -134,6 +147,9 @@ impl fmt::Display for CollectionDisplay<'_> {
134
147
if self . include_clickhouse_keeper_membership {
135
148
display_keeper_membership ( & self . collection , f) ?;
136
149
}
150
+ if self . include_cockroach_status {
151
+ display_cockroach_status ( & self . collection , f) ?;
152
+ }
137
153
138
154
if nerrors > 0 {
139
155
writeln ! (
@@ -199,6 +215,14 @@ impl CollectionDisplayCliFilter {
199
215
Self :: OrphanedDatasets => false ,
200
216
}
201
217
}
218
+
219
+ fn include_cockroach_status ( & self ) -> bool {
220
+ match self {
221
+ Self :: All => true ,
222
+ Self :: Sp { .. } => false ,
223
+ Self :: OrphanedDatasets => false ,
224
+ }
225
+ }
202
226
}
203
227
204
228
/// Which SPs within a collection to display.
@@ -1002,6 +1026,56 @@ fn display_keeper_membership(
1002
1026
Ok ( ( ) )
1003
1027
}
1004
1028
1029
+ fn display_cockroach_status (
1030
+ collection : & Collection ,
1031
+ f : & mut dyn fmt:: Write ,
1032
+ ) -> fmt:: Result {
1033
+ writeln ! ( f, "\n COCKROACH STATUS" ) ?;
1034
+
1035
+ // Under normal conditions, cockroach nodes will report the same data. For
1036
+ // brevity, we will map "status" -> "nodes reporting that status", to avoid
1037
+ // emitting the same information repeatedly for each node.
1038
+ let mut status_to_node = HashMap :: new ( ) ;
1039
+
1040
+ for ( node, status) in & collection. cockroach_status {
1041
+ status_to_node
1042
+ . entry ( status)
1043
+ . and_modify ( |nodes : & mut Vec < _ > | nodes. push ( node) )
1044
+ . or_insert ( vec ! [ node] ) ;
1045
+ }
1046
+
1047
+ for ( status, nodes) in & status_to_node {
1048
+ writeln ! (
1049
+ f,
1050
+ "\n status from nodes: {}" ,
1051
+ nodes. iter( ) . map( |n| n. to_string( ) ) . join( ", " )
1052
+ ) ?;
1053
+
1054
+ writeln ! (
1055
+ f,
1056
+ " \n ranges underreplicated: {}" ,
1057
+ status
1058
+ . ranges_underreplicated
1059
+ . map( |r| r. to_string( ) )
1060
+ . unwrap_or_else( || "-" . to_string( ) )
1061
+ ) ?;
1062
+ writeln ! (
1063
+ f,
1064
+ " \n live nodes: {}" ,
1065
+ status
1066
+ . liveness_live_nodes
1067
+ . map( |r| r. to_string( ) )
1068
+ . unwrap_or_else( || "-" . to_string( ) )
1069
+ ) ?;
1070
+ }
1071
+ if status_to_node. is_empty ( ) {
1072
+ writeln ! ( f, " no cockroach status retrieved" ) ?;
1073
+ }
1074
+ writeln ! ( f, "" ) ?;
1075
+
1076
+ Ok ( ( ) )
1077
+ }
1078
+
1005
1079
#[ derive( Debug ) ]
1006
1080
struct LongStringFormatter {
1007
1081
show_long_strings : bool ,
0 commit comments