@@ -343,24 +343,39 @@ fn group_by_time<'check>(checks: &[&'check Check]) -> HashMap<i64, CheckGroup<'c
343
343
344
344
fn fail_groups < ' check > ( checks : & [ & ' check Check ] ) -> Vec < CheckGroup < ' check > > {
345
345
let by_time = group_by_time ( checks) ;
346
- let mut groups: HashSet < CheckGroup > = HashSet :: new ( ) ;
347
- let mut group;
348
- for key in by_time. keys ( ) {
349
- group = Vec :: new ( ) ;
346
+ let mut groups = Vec :: new ( ) ;
347
+ let mut processed_times = HashSet :: new ( ) ;
348
+ let window = DEFAULT_PERIOD * OUTAGE_TIME_SPAN ;
350
349
351
- for in_range_time in
352
- key - ( DEFAULT_PERIOD * OUTAGE_TIME_SPAN ) ..key + ( DEFAULT_PERIOD * OUTAGE_TIME_SPAN )
353
- {
354
- if let Some ( a) = by_time. get ( & in_range_time) . cloned ( ) {
355
- group. extend ( a) ;
350
+ for & time in by_time. keys ( ) {
351
+ // Skip if we've already processed this time as part of another group
352
+ if processed_times. contains ( & time) {
353
+ continue ;
354
+ }
355
+
356
+ let mut current_group = Vec :: new ( ) ;
357
+
358
+ // Find all checks within the time window
359
+ let window_start = time. saturating_sub ( window) ;
360
+ let window_end = time. saturating_add ( window) ;
361
+
362
+ // Mark all times in this window as processed
363
+ for t in by_time. keys ( ) {
364
+ if * t >= window_start && * t <= window_end && processed_times. insert ( * t) {
365
+ // Only process if not already processed
366
+ if let Some ( checks) = by_time. get ( t) {
367
+ current_group. extend ( checks. iter ( ) . cloned ( ) ) ;
368
+ }
356
369
}
357
370
}
358
371
359
- group. sort ( ) ;
360
- groups. insert ( group) ;
372
+ if !current_group. is_empty ( ) {
373
+ current_group. sort ( ) ;
374
+ groups. push ( current_group) ;
375
+ }
361
376
}
362
377
363
- groups. into_iter ( ) . collect ( )
378
+ groups
364
379
}
365
380
366
381
/// Analyze metrics for a specific check type.
0 commit comments