@@ -45,8 +45,6 @@ use crate::storage::ObjectStorageError;
4545use crate :: sync:: alert_runtime;
4646use crate :: utils:: user_auth_for_query;
4747
48- use self :: target:: Target ;
49-
5048// these types describe the scheduled task for an alert
5149pub type ScheduledTaskHandlers = ( JoinHandle < ( ) > , Receiver < ( ) > , Sender < ( ) > ) ;
5250
@@ -519,10 +517,10 @@ pub struct AlertRequest {
519517
520518impl AlertRequest {
521519 pub async fn into ( self ) -> Result < AlertConfig , AlertError > {
522- let mut targets = Vec :: new ( ) ;
523- for id in self . targets {
524- targets. push ( TARGETS . get_target_by_id ( id) . await ?) ;
525- }
520+ // let mut targets = Vec::new();
521+ // for id in self.targets {
522+ // targets.push(TARGETS.get_target_by_id(id).await?);
523+ // }
526524 let config = AlertConfig {
527525 version : AlertVerison :: from ( CURRENT_ALERTS_VERSION ) ,
528526 id : Ulid :: new ( ) ,
@@ -532,7 +530,7 @@ impl AlertRequest {
532530 alert_type : self . alert_type ,
533531 aggregates : self . aggregates ,
534532 eval_config : self . eval_config ,
535- targets,
533+ targets : self . targets ,
536534 state : AlertState :: default ( ) ,
537535 } ;
538536 Ok ( config)
@@ -551,25 +549,24 @@ pub struct AlertConfig {
551549 pub alert_type : AlertType ,
552550 pub aggregates : Aggregates ,
553551 pub eval_config : EvalConfig ,
554- pub targets : Vec < Target > ,
552+ pub targets : Vec < Ulid > ,
555553 // for new alerts, state should be resolved
556554 #[ serde( default ) ]
557555 pub state : AlertState ,
558556}
559557
560558impl AlertConfig {
561559 pub async fn modify ( & mut self , alert : AlertRequest ) -> Result < ( ) , AlertError > {
562- let mut targets = Vec :: new ( ) ;
563- for id in alert. targets {
564- targets. push ( TARGETS . get_target_by_id ( id) . await ?) ;
565- }
566-
560+ // let mut targets = Vec::new();
561+ // for id in alert.targets {
562+ // targets.push(id);
563+ // }
567564 self . title = alert. title ;
568565 self . stream = alert. stream ;
569566 self . alert_type = alert. alert_type ;
570567 self . aggregates = alert. aggregates ;
571568 self . eval_config = alert. eval_config ;
572- self . targets = targets;
569+ self . targets = alert . targets ;
573570 self . state = AlertState :: default ( ) ;
574571 Ok ( ( ) )
575572 }
@@ -593,7 +590,8 @@ impl AlertConfig {
593590 } ;
594591
595592 // validate that target repeat notifs !> eval_frequency
596- for target in & self . targets {
593+ for target_id in & self . targets {
594+ let target = TARGETS . get_target_by_id ( target_id) . await ?;
597595 match & target. timeout . times {
598596 target:: Retry :: Infinite => { }
599597 target:: Retry :: Finite ( repeat) => {
@@ -779,7 +777,8 @@ impl AlertConfig {
779777 pub async fn trigger_notifications ( & self , message : String ) -> Result < ( ) , AlertError > {
780778 let mut context = self . get_context ( ) ;
781779 context. message = message;
782- for target in & self . targets {
780+ for target_id in & self . targets {
781+ let target = TARGETS . get_target_by_id ( target_id) . await ?;
783782 trace ! ( "Target (trigger_notifications)-\n {target:?}" ) ;
784783 target. call ( context. clone ( ) ) ;
785784 }
0 commit comments