Skip to content

Commit

Permalink
First attempt for incident details
Browse files Browse the repository at this point in the history
  • Loading branch information
Saluki committed Jun 13, 2022
1 parent 06a5b3e commit f2114fe
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
16 changes: 13 additions & 3 deletions src/cli/incident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 | {: <h_max$} | {: <v_max$} |", "Timestamp", "Message", h_max=timestamp_length, v_max=message_length);
println!("|------|-{:-<h_max$}-|-{:-<v_max$}-|", "", "", h_max=timestamp_length, v_max=message_length);
println!("| ID | {: <h_max$} | {: <v_max$} | {: <e_max$} |", "Timestamp", "Message", "Details", h_max=timestamp_length, v_max=message_length, e_max=error_length);
println!("|------|-{:-<h_max$}-|-{:-<v_max$}-|-{:-<e_max$}-|", "", "", "", h_max=timestamp_length, v_max=message_length, e_max=error_length);

for incident in incidents.iter() {
println!("| {: <4} | {: <h_max$} | {: <v_max$} |", incident.id, incident.timestamp, incident.message, h_max=timestamp_length, v_max=message_length);

let empty_message = "no_message".to_string();
let error_message = incident.error_message.as_ref().unwrap_or(&empty_message);
println!("| {: <4} | {: <h_max$} | {: <v_max$} | {: <e_max$} |", incident.id, incident.timestamp, incident.message, error_message, h_max=timestamp_length, v_max=message_length, e_max=error_length);
}
println!();

Expand Down
13 changes: 11 additions & 2 deletions src/relay/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::common::error::Error;
#[derive(Deserialize,Serialize)]
pub struct GroupResult {
pub name: String,
pub working: bool
pub working: bool,
pub error_message: Option<String>,
pub error_detail: Option<String>
}

pub async fn launch(base_url: String, token: String, region_name: String) -> Result<(), Error> {
Expand Down Expand Up @@ -52,6 +54,9 @@ pub async fn launch(base_url: String, token: String, region_name: String) -> Res
for group in &region_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;
Expand All @@ -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
});
}

Expand Down
24 changes: 18 additions & 6 deletions src/server/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pub struct GroupStatus {
pub struct IncidentRecord {
pub id: u32,
pub message: String,
pub timestamp: DateTime<Utc>
pub timestamp: DateTime<Utc>,
pub error_message: Option<String>,
pub error_details: Option<String>
}

pub struct MemoryStorage {
Expand Down Expand Up @@ -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<String>,
pub error_details: Option<String>
}

impl MemoryStorage {
Expand Down Expand Up @@ -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()
})
}

Expand All @@ -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()
})
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit f2114fe

Please sign in to comment.