mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
add hostnames to pages (#1237)
This commit is contained in:
1 parent
a3c03e3d99
commit
824d1f22ab
4 files changed
+33
-12
No files matched your search
@@ -13,6 +13,7 @@ pub struct PagerBuilder {
|
||||
client_config: Option<PagerClientConfig>,
|
||||
application_name: Option<String>,
|
||||
environment: Option<String>,
|
||||
hostname: Option<String>,
|
||||
queue_capacity: Option<usize>,
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ pub struct PagerClient {
|
||||
|
||||
/// Environment label (e.g. "production", "staging"). Inserted as a label on alerts.
|
||||
pub environment: Option<String>,
|
||||
|
||||
/// Hostname of the machine sending alerts. Inserted as a label on alerts.
|
||||
pub hostname: Option<String>,
|
||||
}
|
||||
|
||||
/// Configuration for the pager client backend.
|
||||
@@ -58,8 +61,9 @@ impl PagerClient {
|
||||
client_config: PagerClientConfig,
|
||||
application_name: Option<String>,
|
||||
environment: Option<String>,
|
||||
hostname: Option<String>,
|
||||
) -> 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,
|
||||
|
||||
@@ -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.");
|
||||
|
||||
|
||||
@@ -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.");
|
||||
|
||||
Reference in new issue
Block a user