fixups after deployment

This commit is contained in:
Chris Beck
2025-12-06 21:03:48 -07:00
parent 0cca1f8da3
commit 0bc1329fcf
3 changed files with 21 additions and 10 deletions
+2 -2
View File
@@ -15,10 +15,10 @@ use std::time::Duration;
#[conf(serde)] #[conf(serde)]
pub struct AdminHttpConfig { pub struct AdminHttpConfig {
/// URL to POST admin commands to /// URL to POST admin commands to
#[conf(long, env)] #[conf(long, env = "ADMIN_HTTP_URL")]
pub url: String, pub url: String,
/// Timeout for the HTTP request /// 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, pub timeout: Duration,
} }
+1 -1
View File
@@ -680,7 +680,7 @@ impl Gateway {
if let Some(prometheus) = self.prometheus.as_ref() { if let Some(prometheus) = self.prometheus.as_ref() {
prometheus.purge_old_plots(); prometheus.purge_old_plots();
for alert in alert_msg.alerts.iter() { for alert in alert_msg.alerts.iter() {
match prometheus.create_alert_plot(alert).await { match prometheus.create_alert_plot(alert, false).await {
Ok(path) => { Ok(path) => {
attachment_paths.push(path); attachment_paths.push(path);
} }
+18 -7
View File
@@ -108,8 +108,15 @@ impl Prometheus {
self.config.plot.purge_old_plots(); self.config.plot.purge_old_plots();
} }
/// Create a new plot corresponding to a given alert. Returns a pathbuf if it is present /// 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<PathBuf, BoxError> { ///
/// 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<PathBuf, BoxError> {
use chrono::{TimeDelta, Utc}; use chrono::{TimeDelta, Utc};
let expr = alert.parse_expr_from_generator_url()?; let expr = alert.parse_expr_from_generator_url()?;
@@ -118,12 +125,16 @@ impl Prometheus {
// We look for comparison operators and extract the threshold // We look for comparison operators and extract the threshold
let (base_query, threshold) = parse_alert_expr(&expr)?; let (base_query, threshold) = parse_alert_expr(&expr)?;
// Build label selector from alert labels (excluding job/instance) // Optionally add label selector from alert labels
let label_selector = build_label_selector(&alert.labels, &[]); let query = if add_label_selector {
let query = if label_selector.is_empty() { let label_selector = build_label_selector(&alert.labels, &[]);
base_query.to_owned() if label_selector.is_empty() {
base_query
} else {
format!("{base_query}{{{label_selector}}}")
}
} else { } else {
format!("{base_query}{{{label_selector}}}") base_query
}; };
let now = Utc::now(); let now = Utc::now();