Skip to content

Commit 1a4b22a

Browse files
committed
feat(logging): Add logging with node index and node id for requests; log backoffs
Signed-off-by: Joshua Potts <[email protected]>
1 parent e8629db commit 1a4b22a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/execute.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* ‍
1919
*/
2020

21+
use std::any::type_name;
22+
use std::borrow::Cow;
2123
use std::error::Error as StdError;
2224
use std::ops::ControlFlow;
2325
use std::time::{
@@ -267,6 +269,23 @@ where
267269
while let Some(node_index) = random_node_indexes.next().await {
268270
let tmp = execute_single(ctx, executable, node_index, &mut transaction_id).await;
269271

272+
log::log!(
273+
match &tmp {
274+
Ok(ControlFlow::Break(_)) => log::Level::Debug,
275+
Ok(ControlFlow::Continue(_)) => log::Level::Warn,
276+
Err(_) => log::Level::Error,
277+
},
278+
"Execution of {} on node at index {node_index} / node id {} {}",
279+
type_name::<E>(),
280+
ctx.network.channel(node_index).0,
281+
match &tmp {
282+
Ok(ControlFlow::Break(_)) => Cow::Borrowed("succeeded"),
283+
Ok(ControlFlow::Continue(err)) =>
284+
format!("will continue due to {err:?}").into(),
285+
Err(err) => format!("failed due to {err:?}").into(),
286+
},
287+
);
288+
270289
match tmp? {
271290
ControlFlow::Continue(err) => last_error = Some(err),
272291
ControlFlow::Break(res) => return Ok(res),
@@ -355,6 +374,11 @@ async fn execute_single<E: Execute + Sync>(
355374
) -> retry::Result<ControlFlow<E::Response, Error>> {
356375
let (node_account_id, channel) = ctx.network.channel(node_index);
357376

377+
log::debug!(
378+
"Executing {} on node at index {node_index} / node id {node_account_id}",
379+
type_name::<E>()
380+
);
381+
358382
let (request, context) = executable
359383
.make_request(transaction_id.as_ref(), node_account_id)
360384
.map_err(crate::retry::Error::Permanent)?;

src/retry.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use futures_core::Future;
22
use tokio::time::sleep;
33

4+
#[derive(Debug)]
45
pub(crate) enum Error {
56
/// An error that may be resolved after backoff is applied (connection issues for example)
67
Transient(crate::Error),
@@ -39,7 +40,13 @@ where
3940
}
4041

4142
if let Some(duration) = backoff.next_backoff() {
43+
let duration_ms = duration.as_millis();
44+
let err_suffix =
45+
last_error.as_ref().map(|l| format!(" due to {l:?}")).unwrap_or_default();
46+
47+
log::warn!("Backing off for {duration_ms}ms after failure of attempt {attempt_number}{err_suffix}");
4248
sleep(duration).await;
49+
log::warn!("Backed off for {duration_ms}ms after failure of attempt {attempt_number}{err_suffix}");
4350
} else {
4451
let last_error = last_error.expect("timeout while network had no healthy nodes");
4552
return Err(crate::Error::TimedOut(last_error.into()));

0 commit comments

Comments
 (0)