Skip to content

Commit 5218bc8

Browse files
add datasets to alerts summary
1 parent fe01d39 commit 5218bc8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/alerts/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,14 @@ impl AlertRequest {
545545
for id in &self.targets {
546546
TARGETS.get_target_by_id(id).await?;
547547
}
548+
let datasets = resolve_stream_names(&self.query)?;
548549
let config = AlertConfig {
549550
version: AlertVerison::from(CURRENT_ALERTS_VERSION),
550551
id: Ulid::new(),
551552
severity: self.severity,
552553
title: self.title,
553554
query: self.query,
555+
datasets,
554556
alert_type: self.alert_type,
555557
threshold_config: self.threshold_config,
556558
eval_config: self.eval_config,
@@ -572,6 +574,7 @@ pub struct AlertConfig {
572574
pub severity: Severity,
573575
pub title: String,
574576
pub query: String,
577+
pub datasets: Vec<String>,
575578
pub alert_type: AlertType,
576579
pub threshold_config: ThresholdConfig,
577580
pub eval_config: EvalConfig,
@@ -593,6 +596,7 @@ impl AlertConfig {
593596
let alert_info = format!("Alert '{}' (ID: {})", basic_fields.title, basic_fields.id);
594597

595598
let query = Self::build_query_from_v1(alert_json, &alert_info).await?;
599+
let datasets = resolve_stream_names(&query)?;
596600
let threshold_config = Self::extract_threshold_config(alert_json, &alert_info)?;
597601
let eval_config = Self::extract_eval_config(alert_json, &alert_info)?;
598602
let targets = Self::extract_targets(alert_json, &alert_info)?;
@@ -605,6 +609,7 @@ impl AlertConfig {
605609
severity: basic_fields.severity,
606610
title: basic_fields.title,
607611
query,
612+
datasets,
608613
alert_type: AlertType::Threshold,
609614
threshold_config,
610615
eval_config,
@@ -1245,6 +1250,16 @@ impl AlertConfig {
12451250
);
12461251
}
12471252

1253+
map.insert(
1254+
"datasets".to_string(),
1255+
serde_json::Value::Array(
1256+
self.datasets
1257+
.iter()
1258+
.map(|dataset| serde_json::Value::String(dataset.clone()))
1259+
.collect(),
1260+
),
1261+
);
1262+
12481263
map
12491264
}
12501265
}

0 commit comments

Comments
 (0)