Skip to content

Commit f2114fe

Browse files
committed
First attempt for incident details
1 parent 06a5b3e commit f2114fe

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

src/cli/incident.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub async fn list_incidents(base_url: &str, token: &str) -> Result<(), Error> {
1313

1414
let mut timestamp_length = 15;
1515
let mut message_length = 15;
16+
let mut error_length = 15;
1617
for incident in incidents.iter() {
1718

1819
if incident.timestamp.len() > timestamp_length {
@@ -22,14 +23,23 @@ pub async fn list_incidents(base_url: &str, token: &str) -> Result<(), Error> {
2223
if incident.message.len() > message_length {
2324
message_length = incident.message.len();
2425
}
26+
27+
if let Some(error_message) = incident.error_message.as_ref() {
28+
if error_message.len() > error_length {
29+
error_length = error_message.len();
30+
}
31+
}
2532
}
2633

2734
println!();
28-
println!("| ID | {: <h_max$} | {: <v_max$} |", "Timestamp", "Message", h_max=timestamp_length, v_max=message_length);
29-
println!("|------|-{:-<h_max$}-|-{:-<v_max$}-|", "", "", h_max=timestamp_length, v_max=message_length);
35+
println!("| ID | {: <h_max$} | {: <v_max$} | {: <e_max$} |", "Timestamp", "Message", "Details", h_max=timestamp_length, v_max=message_length, e_max=error_length);
36+
println!("|------|-{:-<h_max$}-|-{:-<v_max$}-|-{:-<e_max$}-|", "", "", "", h_max=timestamp_length, v_max=message_length, e_max=error_length);
3037

3138
for incident in incidents.iter() {
32-
println!("| {: <4} | {: <h_max$} | {: <v_max$} |", incident.id, incident.timestamp, incident.message, h_max=timestamp_length, v_max=message_length);
39+
40+
let empty_message = "no_message".to_string();
41+
let error_message = incident.error_message.as_ref().unwrap_or(&empty_message);
42+
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);
3343
}
3444
println!();
3545

src/relay/instance.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use crate::common::error::Error;
1616
#[derive(Deserialize,Serialize)]
1717
pub struct GroupResult {
1818
pub name: String,
19-
pub working: bool
19+
pub working: bool,
20+
pub error_message: Option<String>,
21+
pub error_detail: Option<String>
2022
}
2123

2224
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
5254
for group in &region_config.groups {
5355

5456
let mut is_group_working = true;
57+
let mut error_message = None;
58+
let mut error_detail = None;
59+
5560
for test in &group.tests {
5661

5762
let test_result = execute_test(test).await;
@@ -66,13 +71,17 @@ pub async fn launch(base_url: String, token: String, region_name: String) -> Res
6671
Err(err) => {
6772
eprintln!("{}", err);
6873
is_group_working = false;
74+
error_message = Some(err.message);
75+
error_detail = err.details;
6976
}
7077
}
7178
}
7279

7380
group_results.push(GroupResult {
7481
name: group.name.clone(),
75-
working: is_group_working
82+
working: is_group_working,
83+
error_message,
84+
error_detail
7685
});
7786
}
7887

src/server/storage.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ pub struct GroupStatus {
4444
pub struct IncidentRecord {
4545
pub id: u32,
4646
pub message: String,
47-
pub timestamp: DateTime<Utc>
47+
pub timestamp: DateTime<Utc>,
48+
pub error_message: Option<String>,
49+
pub error_details: Option<String>
4850
}
4951

5052
pub struct MemoryStorage {
@@ -80,7 +82,9 @@ pub struct GroupSummaryItem {
8082
pub struct IncidentItem {
8183
pub id: u32,
8284
pub message: String,
83-
pub timestamp: String
85+
pub timestamp: String,
86+
pub error_message: Option<String>,
87+
pub error_details: Option<String>
8488
}
8589

8690
impl MemoryStorage {
@@ -136,7 +140,9 @@ impl MemoryStorage {
136140
incidents.push(IncidentItem {
137141
id: incident.id,
138142
message: incident.message.clone(),
139-
timestamp: incident.timestamp.to_rfc3339()
143+
timestamp: incident.timestamp.to_rfc3339(),
144+
error_message: incident.error_message.clone(),
145+
error_details: incident.error_details.clone()
140146
})
141147
}
142148

@@ -150,7 +156,9 @@ impl MemoryStorage {
150156
.map(|result| IncidentItem {
151157
id: result.id,
152158
message: result.message.clone(),
153-
timestamp: result.timestamp.to_rfc3339()
159+
timestamp: result.timestamp.to_rfc3339(),
160+
error_message: result.error_message.clone(),
161+
error_details: result.error_details.clone()
154162
})
155163
}
156164

@@ -235,7 +243,9 @@ impl MemoryStorage {
235243
self.incidents.push(IncidentRecord {
236244
id: self.last_incident_id,
237245
message: format!("Region {} is DOWN", region),
238-
timestamp: Utc::now()
246+
timestamp: Utc::now(),
247+
error_message: Some("Incident triggered at the region level".to_string()),
248+
error_details: None
239249
});
240250
self.last_incident_id += 1;
241251

@@ -281,7 +291,9 @@ impl MemoryStorage {
281291
self.incidents.push(IncidentRecord {
282292
id: self.last_incident_id,
283293
message: format!("Group {}.{} is DOWN", region, group),
284-
timestamp: Utc::now()
294+
timestamp: Utc::now(),
295+
error_message: Some("Incident triggered at the group level".to_string()),
296+
error_details: None
285297
});
286298
self.last_incident_id += 1;
287299

0 commit comments

Comments
 (0)