From f2114fe32332c890c94317fafff4ebb90a629529 Mon Sep 17 00:00:00 2001 From: Saluki Date: Tue, 14 Jun 2022 01:31:02 +0200 Subject: [PATCH] First attempt for incident details --- src/cli/incident.rs | 16 +++++++++++++--- src/relay/instance.rs | 13 +++++++++++-- src/server/storage.rs | 24 ++++++++++++++++++------ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/cli/incident.rs b/src/cli/incident.rs index 3688a1d..14af4ac 100644 --- a/src/cli/incident.rs +++ b/src/cli/incident.rs @@ -13,6 +13,7 @@ pub async fn list_incidents(base_url: &str, token: &str) -> Result<(), Error> { let mut timestamp_length = 15; let mut message_length = 15; + let mut error_length = 15; for incident in incidents.iter() { if incident.timestamp.len() > timestamp_length { @@ -22,14 +23,23 @@ pub async fn list_incidents(base_url: &str, token: &str) -> Result<(), Error> { if incident.message.len() > message_length { message_length = incident.message.len(); } + + if let Some(error_message) = incident.error_message.as_ref() { + if error_message.len() > error_length { + error_length = error_message.len(); + } + } } println!(); - println!("| ID | {: , + pub error_detail: Option } pub async fn launch(base_url: String, token: String, region_name: String) -> Result<(), Error> { @@ -52,6 +54,9 @@ pub async fn launch(base_url: String, token: String, region_name: String) -> Res for group in ®ion_config.groups { let mut is_group_working = true; + let mut error_message = None; + let mut error_detail = None; + for test in &group.tests { let test_result = execute_test(test).await; @@ -66,13 +71,17 @@ pub async fn launch(base_url: String, token: String, region_name: String) -> Res Err(err) => { eprintln!("{}", err); is_group_working = false; + error_message = Some(err.message); + error_detail = err.details; } } } group_results.push(GroupResult { name: group.name.clone(), - working: is_group_working + working: is_group_working, + error_message, + error_detail }); } diff --git a/src/server/storage.rs b/src/server/storage.rs index 8b34851..be2cf1f 100644 --- a/src/server/storage.rs +++ b/src/server/storage.rs @@ -44,7 +44,9 @@ pub struct GroupStatus { pub struct IncidentRecord { pub id: u32, pub message: String, - pub timestamp: DateTime + pub timestamp: DateTime, + pub error_message: Option, + pub error_details: Option } pub struct MemoryStorage { @@ -80,7 +82,9 @@ pub struct GroupSummaryItem { pub struct IncidentItem { pub id: u32, pub message: String, - pub timestamp: String + pub timestamp: String, + pub error_message: Option, + pub error_details: Option } impl MemoryStorage { @@ -136,7 +140,9 @@ impl MemoryStorage { incidents.push(IncidentItem { id: incident.id, message: incident.message.clone(), - timestamp: incident.timestamp.to_rfc3339() + timestamp: incident.timestamp.to_rfc3339(), + error_message: incident.error_message.clone(), + error_details: incident.error_details.clone() }) } @@ -150,7 +156,9 @@ impl MemoryStorage { .map(|result| IncidentItem { id: result.id, message: result.message.clone(), - timestamp: result.timestamp.to_rfc3339() + timestamp: result.timestamp.to_rfc3339(), + error_message: result.error_message.clone(), + error_details: result.error_details.clone() }) } @@ -235,7 +243,9 @@ impl MemoryStorage { self.incidents.push(IncidentRecord { id: self.last_incident_id, message: format!("Region {} is DOWN", region), - timestamp: Utc::now() + timestamp: Utc::now(), + error_message: Some("Incident triggered at the region level".to_string()), + error_details: None }); self.last_incident_id += 1; @@ -281,7 +291,9 @@ impl MemoryStorage { self.incidents.push(IncidentRecord { id: self.last_incident_id, message: format!("Group {}.{} is DOWN", region, group), - timestamp: Utc::now() + timestamp: Utc::now(), + error_message: Some("Incident triggered at the group level".to_string()), + error_details: None }); self.last_incident_id += 1;