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)]
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,
}
+1 -1
View File
@@ -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);
}
+18 -7
View File
@@ -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<PathBuf, BoxError> {
/// 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<PathBuf, BoxError> {
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();