sui_aws_orchestrator/
logs.rsuse std::cmp::max;
use crate::display;
#[derive(Default)]
pub struct LogsAnalyzer {
pub node_errors: usize,
pub node_panic: bool,
pub client_errors: usize,
pub client_panic: bool,
}
impl LogsAnalyzer {
pub fn set_node_errors(&mut self, log: &str) {
self.node_errors = log.matches(" ERROR").count();
self.node_panic = log.contains("panic");
}
pub fn set_client_errors(&mut self, log: &str) {
self.client_errors = max(self.client_errors, log.matches(" ERROR").count());
self.client_panic = log.contains("panic");
}
pub fn aggregate(counters: Vec<Self>) -> Self {
let mut highest = Self::default();
for counter in counters {
if counter.node_panic || counter.client_panic {
return counter;
} else if counter.client_errors > highest.client_errors
|| counter.node_errors > highest.node_errors
{
highest = counter;
}
}
highest
}
pub fn print_summary(&self) {
if self.node_panic {
display::error("Node(s) panicked!");
} else if self.client_panic {
display::error("Client(s) panicked!");
} else if self.node_errors != 0 || self.client_errors != 0 {
display::newline();
display::warn(format!(
"Logs contain errors (node: {}, client: {})",
self.node_errors, self.client_errors
));
}
}
}