diff --git a/signal-gateway-bin/src/admin_http/mod.rs b/signal-gateway-bin/src/admin_http/mod.rs index da49d0f..9264d76 100644 --- a/signal-gateway-bin/src/admin_http/mod.rs +++ b/signal-gateway-bin/src/admin_http/mod.rs @@ -15,10 +15,10 @@ use std::time::Duration; #[conf(serde)] pub struct AdminHttpConfig { /// URL to POST admin commands to - #[conf(long, env)] + #[conf(long, env = "ADMIN_HTTP_URL")] pub url: String, /// Timeout for the HTTP request - #[conf(long, env, default_value = "5s", value_parser = conf_extra::parse_duration)] + #[conf(long, env = "ADMIN_HTTP_TIMEOUT", default_value = "5s", value_parser = conf_extra::parse_duration)] pub timeout: Duration, } diff --git a/signal-gateway/src/gateway/mod.rs b/signal-gateway/src/gateway/mod.rs index c529d6a..9107aa0 100644 --- a/signal-gateway/src/gateway/mod.rs +++ b/signal-gateway/src/gateway/mod.rs @@ -680,7 +680,7 @@ impl Gateway { if let Some(prometheus) = self.prometheus.as_ref() { prometheus.purge_old_plots(); for alert in alert_msg.alerts.iter() { - match prometheus.create_alert_plot(alert).await { + match prometheus.create_alert_plot(alert, false).await { Ok(path) => { attachment_paths.push(path); } diff --git a/signal-gateway/src/prometheus/mod.rs b/signal-gateway/src/prometheus/mod.rs index c7e3de2..89e2a0f 100644 --- a/signal-gateway/src/prometheus/mod.rs +++ b/signal-gateway/src/prometheus/mod.rs @@ -108,8 +108,15 @@ impl Prometheus { self.config.plot.purge_old_plots(); } - /// Create a new plot corresponding to a given alert. Returns a pathbuf if it is present - pub async fn create_alert_plot(&self, alert: &Alert) -> Result { + /// Create a new plot corresponding to a given alert. Returns a pathbuf if it is present. + /// + /// If `add_label_selector` is true, appends alert labels as a label selector to the query. + /// This only works for simple metric queries, not for function calls like `rate(...)`. + pub async fn create_alert_plot( + &self, + alert: &Alert, + add_label_selector: bool, + ) -> Result { use chrono::{TimeDelta, Utc}; let expr = alert.parse_expr_from_generator_url()?; @@ -118,12 +125,16 @@ impl Prometheus { // We look for comparison operators and extract the threshold let (base_query, threshold) = parse_alert_expr(&expr)?; - // Build label selector from alert labels (excluding job/instance) - let label_selector = build_label_selector(&alert.labels, &[]); - let query = if label_selector.is_empty() { - base_query.to_owned() + // Optionally add label selector from alert labels + let query = if add_label_selector { + let label_selector = build_label_selector(&alert.labels, &[]); + if label_selector.is_empty() { + base_query + } else { + format!("{base_query}{{{label_selector}}}") + } } else { - format!("{base_query}{{{label_selector}}}") + base_query }; let now = Utc::now();