@@ -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 ;
@@ -43,6 +44,7 @@ pub struct CollectionDisplay<'a> {
43
44
include_sleds : bool ,
44
45
include_orphaned_datasets : bool ,
45
46
include_clickhouse_keeper_membership : bool ,
47
+ include_cockroach_status : bool ,
46
48
long_string_formatter : LongStringFormatter ,
47
49
}
48
50
@@ -55,6 +57,7 @@ impl<'a> CollectionDisplay<'a> {
55
57
include_sleds : true ,
56
58
include_orphaned_datasets : true ,
57
59
include_clickhouse_keeper_membership : true ,
60
+ include_cockroach_status : true ,
58
61
long_string_formatter : LongStringFormatter :: new ( ) ,
59
62
}
60
63
}
@@ -95,6 +98,15 @@ impl<'a> CollectionDisplay<'a> {
95
98
self
96
99
}
97
100
101
+ /// Control display of Cockroach cluster information (defaults to true).
102
+ pub fn include_cockroach_status (
103
+ & mut self ,
104
+ include_cockroach_status : bool ,
105
+ ) -> & mut Self {
106
+ self . include_cockroach_status = include_cockroach_status;
107
+ self
108
+ }
109
+
98
110
/// Show long strings (defaults to false).
99
111
pub fn show_long_strings ( & mut self , show_long_strings : bool ) -> & mut Self {
100
112
self . long_string_formatter . show_long_strings = show_long_strings;
@@ -112,6 +124,7 @@ impl<'a> CollectionDisplay<'a> {
112
124
. include_clickhouse_keeper_membership (
113
125
filter. include_keeper_membership ( ) ,
114
126
)
127
+ . include_cockroach_status ( filter. include_cockroach_status ( ) )
115
128
}
116
129
}
117
130
@@ -135,6 +148,9 @@ impl fmt::Display for CollectionDisplay<'_> {
135
148
if self . include_clickhouse_keeper_membership {
136
149
display_keeper_membership ( & self . collection , f) ?;
137
150
}
151
+ if self . include_cockroach_status {
152
+ display_cockroach_status ( & self . collection , f) ?;
153
+ }
138
154
139
155
if nerrors > 0 {
140
156
writeln ! (
@@ -200,6 +216,14 @@ impl CollectionDisplayCliFilter {
200
216
Self :: OrphanedDatasets => false ,
201
217
}
202
218
}
219
+
220
+ fn include_cockroach_status ( & self ) -> bool {
221
+ match self {
222
+ Self :: All => true ,
223
+ Self :: Sp { .. } => false ,
224
+ Self :: OrphanedDatasets => false ,
225
+ }
226
+ }
203
227
}
204
228
205
229
/// Which SPs within a collection to display.
@@ -1024,6 +1048,53 @@ fn display_keeper_membership(
1024
1048
Ok ( ( ) )
1025
1049
}
1026
1050
1051
+ fn display_cockroach_status (
1052
+ collection : & Collection ,
1053
+ f : & mut dyn fmt:: Write ,
1054
+ ) -> fmt:: Result {
1055
+ writeln ! ( f, "\n COCKROACH STATUS" ) ?;
1056
+
1057
+ // Under normal conditions, cockroach nodes will report the same data. For
1058
+ // brevity, we will map "status" -> "nodes reporting that status", to avoid
1059
+ // emitting the same information repeatedly for each node.
1060
+ let mut status_to_node: HashMap < _ , Vec < _ > > = HashMap :: new ( ) ;
1061
+
1062
+ for ( node, status) in & collection. cockroach_status {
1063
+ status_to_node. entry ( status) . or_default ( ) . push ( node) ;
1064
+ }
1065
+
1066
+ for ( status, nodes) in & status_to_node {
1067
+ writeln ! (
1068
+ f,
1069
+ "\n status from nodes: {}" ,
1070
+ nodes. iter( ) . map( |n| n. to_string( ) ) . join( ", " )
1071
+ ) ?;
1072
+
1073
+ writeln ! (
1074
+ f,
1075
+ "\n ranges underreplicated: {}" ,
1076
+ status
1077
+ . ranges_underreplicated
1078
+ . map( |r| r. to_string( ) )
1079
+ . unwrap_or_else( || "<cOULD NOT BE PARSED>" . to_string( ) )
1080
+ ) ?;
1081
+ writeln ! (
1082
+ f,
1083
+ "\n live nodes: {}" ,
1084
+ status
1085
+ . liveness_live_nodes
1086
+ . map( |r| r. to_string( ) )
1087
+ . unwrap_or_else( || "<COULD NOT BE PARSED>" . to_string( ) )
1088
+ ) ?;
1089
+ }
1090
+ if status_to_node. is_empty ( ) {
1091
+ writeln ! ( f, " no cockroach status retrieved" ) ?;
1092
+ }
1093
+ writeln ! ( f) ?;
1094
+
1095
+ Ok ( ( ) )
1096
+ }
1097
+
1027
1098
#[ derive( Debug ) ]
1028
1099
struct LongStringFormatter {
1029
1100
show_long_strings : bool ,
0 commit comments