Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/alerts/alert_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ impl AlertRequest {
notification_config: self.notification_config,
created: Utc::now(),
tags: self.tags,
last_triggered_at: None,
};
Ok(config)
}
Expand All @@ -342,6 +343,7 @@ pub struct AlertConfig {
pub notification_config: NotificationConfig,
pub created: DateTime<Utc>,
pub tags: Option<Vec<String>>,
pub last_triggered_at: Option<DateTime<Utc>>,
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
Expand All @@ -367,6 +369,7 @@ pub struct AlertConfigResponse {
pub notification_config: NotificationConfig,
pub created: DateTime<Utc>,
pub tags: Option<Vec<String>>,
pub last_triggered_at: Option<DateTime<Utc>>,
}

impl AlertConfig {
Expand Down Expand Up @@ -405,6 +408,7 @@ impl AlertConfig {
notification_config: self.notification_config,
created: self.created,
tags: self.tags,
last_triggered_at: self.last_triggered_at,
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/alerts/alert_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct ThresholdAlert {
pub created: DateTime<Utc>,
pub tags: Option<Vec<String>>,
pub datasets: Vec<String>,
pub last_triggered_at: Option<DateTime<Utc>>,
}

#[async_trait]
Expand Down Expand Up @@ -192,6 +193,11 @@ impl AlertTrait for ThresholdAlert {
// update state in memory
self.state = new_state;

// if new state is `Triggered`, change triggered at
if new_state.eq(&AlertState::Triggered) {
self.last_triggered_at = Some(Utc::now());
}

// update on disk
store.put_alert(self.id, &self.to_alert_config()).await?;
// The task should have already been removed from the list of running tasks
Expand Down Expand Up @@ -220,6 +226,11 @@ impl AlertTrait for ThresholdAlert {
// update state in memory
self.state = new_state;

// if new state is `Triggered`, change triggered at
if new_state.eq(&AlertState::Triggered) {
self.last_triggered_at = Some(Utc::now());
}

// update on disk
store.put_alert(self.id, &self.to_alert_config()).await?;

Expand Down Expand Up @@ -367,6 +378,7 @@ impl From<AlertConfig> for ThresholdAlert {
created: value.created,
tags: value.tags,
datasets: value.datasets,
last_triggered_at: value.last_triggered_at,
}
}
}
Expand All @@ -389,6 +401,7 @@ impl From<ThresholdAlert> for AlertConfig {
created: val.created,
tags: val.tags,
datasets: val.datasets,
last_triggered_at: val.last_triggered_at,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/alerts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl AlertConfig {
notification_config: NotificationConfig::default(),
created: Utc::now(),
tags: None,
last_triggered_at: None,
};

// Save the migrated alert back to storage
Expand Down
Loading