Skip to content

Commit

Permalink
chore: log error for detail (GreptimeTeam#4011)
Browse files Browse the repository at this point in the history
* chore: log error for detail

* chore: by cr
  • Loading branch information
fengjiachun authored May 22, 2024
1 parent 090b59e commit 418090b
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub trait App: Send {

if self.wait_signal() {
if let Err(e) = tokio::signal::ctrl_c().await {
error!("Failed to listen for ctrl-c signal: {}", e);
error!(e; "Failed to listen for ctrl-c signal");
// It's unusual to fail to listen for ctrl-c signal, maybe there's something unexpected in
// the underlying system. So we stop the app instead of running nonetheless to let people
// investigate the issue.
Expand Down
17 changes: 7 additions & 10 deletions src/datanode/src/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,10 @@ impl HeartbeatTask {
let mut last_received_lease = Instant::now();

let _handle = common_runtime::spawn_bg(async move {
while let Some(res) = match rx.message().await {
Ok(m) => m,
Err(e) => {
error!(e; "Error while reading heartbeat response");
None
}
} {
while let Some(res) = rx.message().await.unwrap_or_else(|e| {
error!(e; "Error while reading heartbeat response");
None
}) {
if let Some(msg) = res.mailbox_message.as_ref() {
info!("Received mailbox message: {msg:?}, meta_client id: {client_id:?}");
}
Expand Down Expand Up @@ -238,7 +235,7 @@ impl HeartbeatTask {
Some(req)
}
Err(e) => {
error!(e;"Failed to encode mailbox messages!");
error!(e; "Failed to encode mailbox messages!");
None
}
}
Expand Down Expand Up @@ -276,7 +273,7 @@ impl HeartbeatTask {
if let Some(req) = req {
debug!("Sending heartbeat request: {:?}", req);
if let Err(e) = tx.send(req).await {
error!("Failed to send heartbeat to metasrv, error: {:?}", e);
error!(e; "Failed to send heartbeat to metasrv");
match Self::create_streams(
&meta_client,
running.clone(),
Expand All @@ -301,7 +298,7 @@ impl HeartbeatTask {
Instant::now()
+ Duration::from_secs(META_KEEP_ALIVE_INTERVAL_SECS),
);
error!(e;"Failed to reconnect to metasrv!");
error!(e; "Failed to reconnect to metasrv!");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl HeartbeatTask {
Some(req)
}
Err(e) => {
error!(e;"Failed to encode mailbox messages!");
error!(e; "Failed to encode mailbox messages");
None
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/meta-srv/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl KvBackend for MetaPeerClient {
Ok(res) => return Ok(res),
Err(e) => {
if need_retry(&e) {
warn!("Encountered an error that need to retry, err: {:?}", e);
warn!(e; "Encountered an error that need to retry");
tokio::time::sleep(Duration::from_millis(retry_interval_ms)).await;
} else {
return Err(e);
Expand Down Expand Up @@ -138,7 +138,7 @@ impl KvBackend for MetaPeerClient {
Ok(res) => return Ok(res),
Err(e) => {
if need_retry(&e) {
warn!("Encountered an error that need to retry, err: {:?}", e);
warn!(e; "Encountered an error that need to retry");
tokio::time::sleep(Duration::from_millis(retry_interval_ms)).await;
} else {
return Err(e);
Expand Down
2 changes: 1 addition & 1 deletion src/meta-srv/src/election/etcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl Election for EtcdElection {
.leader_watcher
.send(LeaderChangeMessage::Elected(Arc::new(leader.clone())))
{
error!("Failed to send leader change message, error: {e}");
error!(e; "Failed to send leader change message");
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/meta-srv/src/handler/collect_stats_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl HeartbeatHandler for CollectStatsHandler {
let _ = acc.stat.insert(stat);
}
Err(err) => {
warn!("Incomplete heartbeat data: {:?}, err: {:?}", req, err);
warn!(err; "Incomplete heartbeat data: {:?}", req);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/meta-srv/src/handler/failure_handler/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ impl FailureDetectRunner {

pub(crate) async fn send_heartbeat(&self, heartbeat: DatanodeHeartbeat) {
if let Err(e) = self.heartbeat_tx.send(heartbeat).await {
error!("FailureDetectRunner is stop receiving heartbeats: {}", e)
error!(e; "FailureDetectRunner is stop receiving heartbeats")
}
}

pub(crate) async fn send_control(&self, control: FailureDetectControl) {
if let Err(e) = self.control_tx.send(control).await {
error!("FailureDetectRunner is stop receiving controls: {}", e)
error!(e; "FailureDetectRunner is stop receiving controls")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/meta-srv/src/handler/keep_lease_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl HeartbeatHandler for KeepLeaseHandler {
let res = ctx.in_memory.put(put_req).await;

if let Err(err) = res {
warn!("Failed to update lease KV, peer: {peer:?}, {err}");
warn!(err; "Failed to update lease KV, peer: {peer:?}");
}

Ok(HandleControl::Continue)
Expand Down
6 changes: 3 additions & 3 deletions src/meta-srv/src/metasrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl MetaStateHandler {
if let Some(sub_manager) = self.subscribe_manager.clone() {
info!("Leader changed, un_subscribe all");
if let Err(e) = sub_manager.unsubscribe_all() {
error!("Failed to un_subscribe all, error: {}", e);
error!(e; "Failed to un_subscribe all");
}
}
}
Expand Down Expand Up @@ -405,7 +405,7 @@ impl Metasrv {
while started.load(Ordering::Relaxed) {
let res = election.register_candidate(&node_info).await;
if let Err(e) = res {
warn!("Metasrv register candidate error: {}", e);
warn!(e; "Metasrv register candidate error");
}
}
});
Expand All @@ -419,7 +419,7 @@ impl Metasrv {
while started.load(Ordering::Relaxed) {
let res = election.campaign().await;
if let Err(e) = res {
warn!("Metasrv election error: {}", e);
warn!(e; "Metasrv election error");
}
info!("Metasrv re-initiate election");
}
Expand Down
6 changes: 3 additions & 3 deletions src/mito2/src/region/opener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ impl RegionOpener {
);
}
Err(e) => {
warn!(
"Failed to open region {} before creating it, region_dir: {}, err: {}",
self.region_id, self.region_dir, e
warn!(e;
"Failed to open region {} before creating it, region_dir: {}",
self.region_id, self.region_dir
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/script/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<E: ErrorExt + Send + Sync + 'static> ScriptsTable<E> {
}
Err(err) => {
warn!(
r#"Failed to compile script "{}"" in `scripts` table: {}"#,
r#"Failed to compile script "{}"" in `scripts` table: {:?}"#,
name, err
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/servers/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ impl IntoResponse for Error {
if self.status_code().should_log_error() {
error!(self; "Failed to handle HTTP request: ");
} else {
debug!("Failed to handle HTTP request: {self}");
debug!("Failed to handle HTTP request: {self:?}");
}

HttpStatusCode::INTERNAL_SERVER_ERROR
Expand Down
6 changes: 3 additions & 3 deletions src/servers/src/grpc/flight/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ impl FlightRecordBatchStream {
) {
let schema = recordbatches.schema();
if let Err(e) = tx.send(Ok(FlightMessage::Schema(schema))).await {
warn!("stop sending Flight data, err: {e}");
warn!(e; "stop sending Flight data");
return;
}

while let Some(batch_or_err) = recordbatches.next().in_current_span().await {
match batch_or_err {
Ok(recordbatch) => {
if let Err(e) = tx.send(Ok(FlightMessage::Recordbatch(recordbatch))).await {
warn!("stop sending Flight data, err: {e}");
warn!(e; "stop sending Flight data");
return;
}
}
Err(e) => {
let e = Err(e).context(error::CollectRecordbatchSnafu);
if let Err(e) = tx.send(e.map_err(|x| x.into())).await {
warn!("stop sending Flight data, err: {e}");
warn!(e; "stop sending Flight data");
}
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/servers/src/http/authorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub async fn inner_auth<B>(
let (username, password) = match extract_username_and_password(&req) {
Ok((username, password)) => (username, password),
Err(e) => {
warn!("extract username and password failed: {}", e);
warn!(e; "extract username and password failed");
crate::metrics::METRIC_AUTH_FAILURE
.with_label_values(&[e.status_code().as_ref()])
.inc();
Expand All @@ -108,7 +108,7 @@ pub async fn inner_auth<B>(
Ok(req)
}
Err(e) => {
warn!("authenticate failed: {}", e);
warn!(e; "authenticate failed");
crate::metrics::METRIC_AUTH_FAILURE
.with_label_values(&[e.status_code().as_ref()])
.inc();
Expand Down
2 changes: 1 addition & 1 deletion src/servers/src/mysql/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<W: AsyncWrite + Send + Sync + Unpin> AsyncMysqlShim<W> for MysqlInstanceShi
METRIC_AUTH_FAILURE
.with_label_values(&[e.status_code().as_ref()])
.inc();
warn!("Failed to auth, err: {:?}", e);
warn!(e; "Failed to auth");
return false;
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/servers/src/mysql/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ impl MysqlServer {

async move {
match tcp_stream {
Err(error) => warn!("Broken pipe: {}", error), // IoError doesn't impl ErrorExt.
Err(e) => warn!(e; "Broken pipe"), // IoError doesn't impl ErrorExt.
Ok(io_stream) => {
if let Err(e) = io_stream.set_nodelay(true) {
warn!(e; "Failed to set TCP nodelay");
}
if let Err(error) =
Self::handle(io_stream, io_runtime, spawn_ref, spawn_config).await
{
warn!("Unexpected error when handling TcpStream {}", error);
warn!(error; "Unexpected error when handling TcpStream");
};
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/servers/src/postgres/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl PostgresServer {
Some(addr)
}
Err(e) => {
warn!("Failed to get PostgreSQL client addr, err: {}", e);
warn!(e; "Failed to get PostgreSQL client addr");
None
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/servers/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl AcceptTask {
if let Err(error) = join_handle.await {
// Couldn't use `error!(e; xxx)` because JoinError doesn't implement ErrorExt.
error!(
"Unexpected error during shutdown {} server, error: {}",
"Unexpected error during shutdown {} server, error: {:?}",
name, error
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/table/src/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ impl Predicate {
}
}
Err(e) => {
warn!("Failed to prune row groups, error: {:?}", e);
warn!(e; "Failed to prune row groups");
}
},
Err(e) => {
error!("Failed to create predicate for expr, error: {:?}", e);
error!(e; "Failed to create predicate for expr");
}
}
}
Expand Down

0 comments on commit 418090b

Please sign in to comment.