77use crate :: Omdb ;
88use crate :: check_allow_destructive:: DestructiveOperationToken ;
99use anyhow:: Context ;
10- use chrono:: TimeDelta ;
1110use chrono:: Utc ;
1211use clap:: Args ;
1312use clap:: Subcommand ;
1413use nexus_lockstep_client:: types:: PendingRecovery ;
1514use nexus_lockstep_client:: types:: QuiesceState ;
1615use nexus_lockstep_client:: types:: QuiesceStatus ;
1716use nexus_lockstep_client:: types:: SagaQuiesceStatus ;
18- use std:: time:: Duration ;
1917
2018#[ derive( Debug , Args ) ]
2119pub struct QuiesceArgs {
@@ -77,7 +75,7 @@ async fn quiesce_show(
7775 println ! (
7876 "quiescing since {} ({} ago)" ,
7977 humantime:: format_rfc3339_millis( time_requested. into( ) ) ,
80- format_time_delta( now - time_requested) ,
78+ omicron_common :: format_time_delta( now - time_requested) ,
8179 ) ;
8280 println ! ( "details: waiting for running sagas to finish" ) ;
8381 }
@@ -89,14 +87,16 @@ async fn quiesce_show(
8987 println ! (
9088 "quiescing since {} ({} ago)" ,
9189 humantime:: format_rfc3339_millis( time_requested. into( ) ) ,
92- format_time_delta( now - time_requested) ,
90+ omicron_common :: format_time_delta( now - time_requested) ,
9391 ) ;
9492 println ! (
9593 "details: waiting for database connections to be released"
9694 ) ;
9795 println ! (
9896 " previously: waiting for sagas took {}" ,
99- format_duration_ms( duration_draining_sagas. into( ) ) ,
97+ omicron_common:: format_duration_ms(
98+ duration_draining_sagas. into( )
99+ ) ,
100100 ) ;
101101 }
102102 QuiesceState :: RecordingQuiesce {
@@ -108,15 +108,17 @@ async fn quiesce_show(
108108 println ! (
109109 "quiescing since {} ({} ago)" ,
110110 humantime:: format_rfc3339_millis( time_requested. into( ) ) ,
111- format_time_delta( now - time_requested) ,
111+ omicron_common :: format_time_delta( now - time_requested) ,
112112 ) ;
113113 println ! (
114114 " waiting for sagas took {}" ,
115- format_duration_ms( duration_draining_sagas. into( ) ) ,
115+ omicron_common:: format_duration_ms(
116+ duration_draining_sagas. into( )
117+ ) ,
116118 ) ;
117119 println ! (
118120 " waiting for db quiesce took {}" ,
119- format_duration_ms( duration_draining_db. into( ) ) ,
121+ omicron_common :: format_duration_ms( duration_draining_db. into( ) ) ,
120122 ) ;
121123 }
122124 QuiesceState :: Quiesced {
@@ -130,23 +132,27 @@ async fn quiesce_show(
130132 println ! (
131133 "quiesced since {} ({} ago)" ,
132134 humantime:: format_rfc3339_millis( time_quiesced. into( ) ) ,
133- format_time_delta( now - time_quiesced) ,
135+ omicron_common :: format_time_delta( now - time_quiesced) ,
134136 ) ;
135137 println ! (
136138 " waiting for sagas took {}" ,
137- format_duration_ms( duration_draining_sagas. into( ) ) ,
139+ omicron_common:: format_duration_ms(
140+ duration_draining_sagas. into( )
141+ ) ,
138142 ) ;
139143 println ! (
140144 " waiting for db quiesce took {}" ,
141- format_duration_ms( duration_draining_db. into( ) ) ,
145+ omicron_common :: format_duration_ms( duration_draining_db. into( ) ) ,
142146 ) ;
143147 println ! (
144148 " recording quiesce took {}" ,
145- format_duration_ms( duration_recording_quiesce. into( ) ) ,
149+ omicron_common:: format_duration_ms(
150+ duration_recording_quiesce. into( )
151+ ) ,
146152 ) ;
147153 println ! (
148154 " total quiesce time: {}" ,
149- format_duration_ms( duration_total. into( ) ) ,
155+ omicron_common :: format_duration_ms( duration_total. into( ) ) ,
150156 ) ;
151157 }
152158 }
@@ -225,7 +231,7 @@ async fn quiesce_show(
225231 " claim {} held since {} ({} ago)" ,
226232 claim. id,
227233 claim. held_since,
228- format_time_delta( Utc :: now( ) - claim. held_since) ,
234+ omicron_common :: format_time_delta( Utc :: now( ) - claim. held_since) ,
229235 ) ;
230236 if args. stacks {
231237 println ! ( " acquired by:" ) ;
@@ -243,18 +249,3 @@ async fn quiesce_start(
243249 client. quiesce_start ( ) . await . context ( "quiescing Nexus" ) ?;
244250 quiesce_show ( client, & QuiesceShowArgs { stacks : false } ) . await
245251}
246-
247- fn format_duration_ms ( duration : Duration ) -> String {
248- // Ignore units smaller than a millisecond.
249- let elapsed = Duration :: from_millis (
250- u64:: try_from ( duration. as_millis ( ) ) . unwrap_or ( u64:: MAX ) ,
251- ) ;
252- humantime:: format_duration ( elapsed) . to_string ( )
253- }
254-
255- fn format_time_delta ( time_delta : TimeDelta ) -> String {
256- match time_delta. to_std ( ) {
257- Ok ( d) => format_duration_ms ( d) ,
258- Err ( _) => String :: from ( "<time delta out of range>" ) ,
259- }
260- }
0 commit comments