From 824d1f22ab8c123fb1bcc7dfea98f5007e5ef2ea Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 26 Mar 2026 02:00:17 -0400 Subject: [PATCH] add hostnames to pages (#1237) --- crates/lib/pager/src/client/pager_builder.rs | 10 +++++++++- crates/lib/pager/src/client/pager_client.rs | 18 ++++++++++++++++-- crates/service/web/storyteller_web/src/main.rs | 2 +- .../storyteller_web/src/startup/build_pager.rs | 15 +++++++-------- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/crates/lib/pager/src/client/pager_builder.rs b/crates/lib/pager/src/client/pager_builder.rs index 1c1ce04cc0..d08f09016b 100644 --- a/crates/lib/pager/src/client/pager_builder.rs +++ b/crates/lib/pager/src/client/pager_builder.rs @@ -13,6 +13,7 @@ pub struct PagerBuilder { client_config: Option, application_name: Option, environment: Option, + hostname: Option, queue_capacity: Option, } @@ -22,6 +23,7 @@ impl PagerBuilder { client_config: None, application_name: None, environment: None, + hostname: None, queue_capacity: None, } } @@ -38,6 +40,12 @@ impl PagerBuilder { self } + /// Set the hostname of the machine sending alerts. + pub fn hostname(mut self, hostname: String) -> Self { + self.hostname = Some(hostname); + self + } + /// Configure the Rootly backend. Returns a sub-builder for Rootly-specific options. pub fn rootly(self, api_key: RootlyApiKey) -> RootlyConfigBuilder { RootlyConfigBuilder { @@ -105,7 +113,7 @@ impl PagerBuilder { } }; - PagerClient::new(client_config, self.application_name.clone(), self.environment.clone()) + PagerClient::new(client_config, self.application_name.clone(), self.environment.clone(), self.hostname.clone()) } } diff --git a/crates/lib/pager/src/client/pager_client.rs b/crates/lib/pager/src/client/pager_client.rs index f2dd0e0271..74aee2be06 100644 --- a/crates/lib/pager/src/client/pager_client.rs +++ b/crates/lib/pager/src/client/pager_client.rs @@ -20,6 +20,9 @@ pub struct PagerClient { /// Environment label (e.g. "production", "staging"). Inserted as a label on alerts. pub environment: Option, + + /// Hostname of the machine sending alerts. Inserted as a label on alerts. + pub hostname: Option, } /// Configuration for the pager client backend. @@ -58,8 +61,9 @@ impl PagerClient { client_config: PagerClientConfig, application_name: Option, environment: Option, + hostname: Option, ) -> Self { - Self { client_config, application_name, environment } + Self { client_config, application_name, environment, hostname } } pub fn is_noop(&self) -> bool { @@ -104,13 +108,23 @@ impl PagerClient { labels.push(("environment".to_string(), env.clone())); } + if let Some(h) = &self.hostname { + labels.push(("hostname".to_string(), h.clone())); + } + let labels = if labels.is_empty() { None } else { Some(labels) }; + // Enrich the description with hostname if both are present. + let description = match (¬ification.description, &self.hostname) { + (Some(desc), Some(h)) => Some(format!("{}\n\nHostname: {}", desc, h)), + (desc, _) => desc.clone(), + }; + let result = create_alert(CreateAlertArgs { api_key: api_key.clone(), source, summary: notification.summary.clone(), - description: notification.description.clone(), + description, status: Some("triggered".to_string()), service_ids: None, group_ids: None, diff --git a/crates/service/web/storyteller_web/src/main.rs b/crates/service/web/storyteller_web/src/main.rs index 6851cb9803..e07d9c45b9 100644 --- a/crates/service/web/storyteller_web/src/main.rs +++ b/crates/service/web/storyteller_web/src/main.rs @@ -339,7 +339,7 @@ async fn main() -> AnyhowResult<()> { ServerEnvironment::Development => server_environment::ServerEnvironment::Development, }; - let (pager, pager_worker, paging_flags) = build_pager(server_environment_typed); + let (pager, pager_worker, paging_flags) = build_pager(server_environment_typed, &server_hostname); info!("Spawning pager worker thread."); diff --git a/crates/service/web/storyteller_web/src/startup/build_pager.rs b/crates/service/web/storyteller_web/src/startup/build_pager.rs index 47e423f17b..c2b19c509b 100644 --- a/crates/service/web/storyteller_web/src/startup/build_pager.rs +++ b/crates/service/web/storyteller_web/src/startup/build_pager.rs @@ -8,6 +8,7 @@ use crate::state::flags::paging_flags::PagingFlags; pub fn build_pager( server_environment: server_environment::ServerEnvironment, + hostname: &str, ) -> (Pager, PagerWorker, PagingFlags) { let paging_flags = PagingFlags::from_env(); @@ -19,22 +20,20 @@ pub fn build_pager( "development" }; + let builder = PagerBuilder::new() + .application_name("storyteller-web".to_string()) + .environment(environment.to_string()) + .hostname(hostname.to_string()); + // If paging is globally disabled, use a NoOp pager regardless of API key. if !paging_flags.is_paging_enabled { warn!("ENABLE_PAGING is false. Pager will be NoOp."); - let (pager, worker) = PagerBuilder::new() - .application_name("storyteller-web".to_string()) - .environment(environment.to_string()) - .build_with_worker(); + let (pager, worker) = builder.build_with_worker(); return (pager, worker, paging_flags); } let maybe_api_key = easyenv::get_env_string_optional("ROOTLY_API_KEY"); - let builder = PagerBuilder::new() - .application_name("storyteller-web".to_string()) - .environment(environment.to_string()); - let (pager, worker) = match maybe_api_key { Some(api_key) => { info!("Rootly API key found. Configuring pager with Rootly backend.");