@@ -96,6 +96,31 @@ impl<'check> Outage<'check> {
96
96
}
97
97
}
98
98
99
+ pub fn short_report ( & self ) -> Result < String , std:: fmt:: Error > {
100
+ let mut buf: String = String :: new ( ) ;
101
+ if self . end . is_some ( ) {
102
+ write ! (
103
+ & mut buf,
104
+ "From {}" ,
105
+ fmt_timestamp( self . start. timestamp_parsed( ) ) ,
106
+ ) ?;
107
+ write ! (
108
+ & mut buf,
109
+ " To {}" ,
110
+ fmt_timestamp( self . end. unwrap( ) . timestamp_parsed( ) ) ,
111
+ ) ?;
112
+ } else {
113
+ write ! (
114
+ & mut buf,
115
+ "From {}" ,
116
+ fmt_timestamp( self . start. timestamp_parsed( ) ) ,
117
+ ) ?;
118
+ write ! ( & mut buf, " To {}" , "(None)" ) ?;
119
+ }
120
+ write ! ( & mut buf, ", Total {}" , self . len( ) ) ?;
121
+ Ok ( buf)
122
+ }
123
+
99
124
/// Returns the length of this [`Outage`].
100
125
pub fn len ( & self ) -> usize {
101
126
self . all . len ( )
@@ -243,14 +268,42 @@ fn key_value_write(
243
268
/// Groups consecutive failed checks by check type and creates
244
269
/// Outage records for reporting.
245
270
fn outages ( store : & Store , f : & mut String ) -> Result < ( ) , AnalysisError > {
246
- let all_checks: Vec < & Check > = store. checks ( ) . iter ( ) . collect ( ) ;
247
- let fails_exist = !all_checks. iter ( ) . all ( |c| c. is_success ( ) ) ;
248
- if !fails_exist || all_checks. is_empty ( ) {
271
+ let all: Vec < & Check > = store. checks ( ) . iter ( ) . collect ( ) ;
272
+ let fails_exist = !all. iter ( ) . all ( |c| c. is_success ( ) ) ;
273
+ if !fails_exist || all. is_empty ( ) {
274
+ writeln ! ( f, "None\n " ) ?;
275
+ return Ok ( ( ) ) ;
276
+ }
277
+
278
+ let fail_groups = fail_groups ( & all) ;
279
+ for ( outage_idx, group) in fail_groups. into_iter ( ) . rev ( ) . enumerate ( ) {
280
+ if group. is_empty ( ) {
281
+ error ! ( "empty outage group" ) ;
282
+ continue ;
283
+ }
284
+ let outage = Outage :: new ( group. first ( ) . unwrap ( ) , group. last ( ) . copied ( ) , & group) ;
285
+ writeln ! ( f, "{outage_idx}:\t {}" , & outage. short_report( ) ?) ?;
286
+ if outage_idx > 10 {
287
+ writeln ! ( f, "showing only the 10 latest outages" ) ?;
288
+ break ;
289
+ }
290
+ }
291
+ writeln ! ( f) ?;
292
+ Ok ( ( ) )
293
+ }
294
+
295
+ /// Analyzes and formats outage information from the store.
296
+ ///
297
+ /// Groups consecutive failed checks by check type and creates
298
+ /// Outage records for reporting. This is the more detailed version of [outages]
299
+ pub fn outages_detailed ( all : & [ & Check ] , f : & mut String ) -> Result < ( ) , AnalysisError > {
300
+ let fails_exist = !all. iter ( ) . all ( |c| c. is_success ( ) ) ;
301
+ if !fails_exist || all. is_empty ( ) {
249
302
writeln ! ( f, "None\n " ) ?;
250
303
return Ok ( ( ) ) ;
251
304
}
252
305
253
- let fail_groups = fail_groups ( & all_checks ) ;
306
+ let fail_groups = fail_groups ( all ) ;
254
307
for ( outage_idx, group) in fail_groups. into_iter ( ) . enumerate ( ) {
255
308
if group. is_empty ( ) {
256
309
error ! ( "empty outage group" ) ;
0 commit comments