Accurate log messages (#425)

This commit is contained in:
Lev Kokotov
2023-05-05 08:27:19 -07:00
committed by GitHub
parent ba5243b6dd
commit 389993bf3e
2 changed files with 26 additions and 10 deletions

View File

@@ -641,7 +641,10 @@ impl ConnectionPool {
{ {
Ok(conn) => conn, Ok(conn) => conn,
Err(err) => { Err(err) => {
error!("Banning instance {:?}, error: {:?}", address, err); error!(
"Connection checkout error for instance {:?}, error: {:?}",
address, err
);
self.ban(address, BanReason::FailedCheckout, Some(client_stats)); self.ban(address, BanReason::FailedCheckout, Some(client_stats));
address.stats.error(); address.stats.error();
client_stats.idle(); client_stats.idle();
@@ -717,7 +720,7 @@ impl ConnectionPool {
// Health check failed. // Health check failed.
Err(err) => { Err(err) => {
error!( error!(
"Banning instance {:?} because of failed health check, {:?}", "Failed health check on instance {:?}, error: {:?}",
address, err address, err
); );
} }
@@ -726,7 +729,7 @@ impl ConnectionPool {
// Health check timed out. // Health check timed out.
Err(err) => { Err(err) => {
error!( error!(
"Banning instance {:?} because of health check timeout, {:?}", "Health check timeout on instance {:?}, error: {:?}",
address, err address, err
); );
} }
@@ -748,13 +751,16 @@ impl ConnectionPool {
return; return;
} }
error!("Banning instance {:?}, reason: {:?}", address, reason);
let now = chrono::offset::Utc::now().naive_utc(); let now = chrono::offset::Utc::now().naive_utc();
let mut guard = self.banlist.write(); let mut guard = self.banlist.write();
error!("Banning {:?}", address);
if let Some(client_info) = client_info { if let Some(client_info) = client_info {
client_info.ban_error(); client_info.ban_error();
address.stats.error(); address.stats.error();
} }
guard[address.shard].insert(address.clone(), (reason, now)); guard[address.shard].insert(address.clone(), (reason, now));
} }

View File

@@ -705,7 +705,10 @@ impl Server {
Ok(()) Ok(())
} }
Err(err) => { Err(err) => {
error!("Terminating server because of: {:?}", err); error!(
"Terminating server {:?} because of: {:?}",
self.address, err
);
self.bad = true; self.bad = true;
Err(err) Err(err)
} }
@@ -720,7 +723,10 @@ impl Server {
let mut message = match read_message(&mut self.stream).await { let mut message = match read_message(&mut self.stream).await {
Ok(message) => message, Ok(message) => message,
Err(err) => { Err(err) => {
error!("Terminating server because of: {:?}", err); error!(
"Terminating server {:?} because of: {:?}",
self.address, err
);
self.bad = true; self.bad = true;
return Err(err); return Err(err);
} }
@@ -1135,14 +1141,18 @@ impl Drop for Server {
_ => debug!("Dirty shutdown"), _ => debug!("Dirty shutdown"),
}; };
// Should not matter.
self.bad = true;
let now = chrono::offset::Utc::now().naive_utc(); let now = chrono::offset::Utc::now().naive_utc();
let duration = now - self.connected_at; let duration = now - self.connected_at;
let message = if self.bad {
"Server connection terminated"
} else {
"Server connection closed"
};
info!( info!(
"Server connection closed {:?}, session duration: {}", "{} {:?}, session duration: {}",
message,
self.address, self.address,
crate::format_duration(&duration) crate::format_duration(&duration)
); );