Skip to content

Commit 51a217c

Browse files
committed
updated message
1 parent f776318 commit 51a217c

File tree

3 files changed

+20
-39
lines changed

3 files changed

+20
-39
lines changed

src/alerts/alert_traits.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub trait MessageCreation {
4343
forecasted_time: DateTime<Utc>,
4444
forecasted_value: f64,
4545
) -> Result<String, AlertError>;
46+
fn get_message_header(&self) -> Result<String, AlertError>;
4647
}
4748

4849
#[async_trait]

src/alerts/alert_types.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,26 @@ impl AlertTrait for ThresholdAlert {
303303
}
304304

305305
impl MessageCreation for ThresholdAlert {
306+
fn get_message_header(&self) -> Result<String, AlertError> {
307+
Ok(format!(
308+
"Alert Name: {}\nAlert Type: Threshold alert\nSeverity: {}\nTriggered at: {}\nThreshold: {}\nAlert ID: {}\nEvaluation Window: {}\nFrequency: {}\n\nValues crossing the threshold:",
309+
self.title,
310+
self.severity,
311+
Utc::now().to_rfc3339(),
312+
format_args!(
313+
"{} {}",
314+
self.threshold_config.operator, self.threshold_config.value
315+
),
316+
self.id,
317+
self.get_eval_window(),
318+
self.get_eval_frequency()
319+
))
320+
}
306321
fn create_threshold_message(&self, actual_value: f64) -> Result<String, AlertError> {
322+
let header = self.get_message_header()?;
307323
Ok(format!(
308-
"Alert Triggered: {}\n\nThreshold: ({} {})\nCurrent Value: {}\nEvaluation Window: {} | Frequency: {}\n\nQuery:\n{}",
309-
self.get_id(),
310-
self.get_threshold_config().operator,
311-
self.get_threshold_config().value,
324+
"{header}\nValue: {}\n\nQuery:\n{}",
312325
actual_value,
313-
self.get_eval_window(),
314-
self.get_eval_frequency(),
315326
self.get_query()
316327
))
317328
}
@@ -384,14 +395,8 @@ impl From<ThresholdAlert> for AlertConfig {
384395

385396
impl ThresholdAlert {
386397
fn create_group_message(&self, breached_groups: &[GroupResult]) -> Result<String, AlertError> {
387-
let mut message = format!(
388-
"Alert Triggered: {}\n\nThreshold: ({} {})\nEvaluation Window: {} | Frequency: {}\n\n",
389-
self.get_id(),
390-
self.get_threshold_config().operator,
391-
self.get_threshold_config().value,
392-
self.get_eval_window(),
393-
self.get_eval_frequency()
394-
);
398+
let header = self.get_message_header()?;
399+
let mut message = format!("{header}\n");
395400

396401
message.push_str(&format!(
397402
"Alerting Groups ({} total):\n",

src/alerts/mod.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -869,31 +869,6 @@ fn is_likely_aggregate_column(column_name: &str) -> bool {
869869
|| lower_name.contains("max(")
870870
}
871871

872-
/// Alternative approach: Walk the entire plan and collect all expressions
873-
pub fn extract_aggregate_aliases_comprehensive(
874-
plan: &LogicalPlan,
875-
) -> Vec<(String, Option<String>)> {
876-
let mut aliases = Vec::new();
877-
collect_all_expressions(plan, &mut aliases);
878-
aliases.dedup(); // Remove duplicates
879-
aliases
880-
}
881-
882-
fn collect_all_expressions(plan: &LogicalPlan, aliases: &mut Vec<(String, Option<String>)>) {
883-
// Collect expressions from current node
884-
let expressions = plan.expressions();
885-
for expr in expressions {
886-
if let Some((agg_name, alias)) = extract_alias_from_expr(&expr) {
887-
aliases.push((agg_name, alias));
888-
}
889-
}
890-
891-
// Recursively process child plans
892-
for input in plan.inputs() {
893-
collect_all_expressions(input, aliases);
894-
}
895-
}
896-
897872
/// Analyze a logical plan to determine if it represents an aggregate query
898873
///
899874
/// Returns the number of aggregate expressions found in the plan

0 commit comments

Comments
 (0)