Skip to content

Commit dadb27b

Browse files
ma2bdjvff
andauthored
Better logging for subscriptions (#2735)
* increase logging for subscriptions * Update linera-rpc/src/grpc/client.rs Co-authored-by: Janito Vaqueiro Ferreira Filho <[email protected]> Signed-off-by: Mathieu Baudet <[email protected]>
1 parent 652cc02 commit dadb27b

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

linera-core/src/client/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,9 @@ where
30343034
})
30353035
.filter_map(move |result| async move {
30363036
if let Err(error) = &result {
3037-
info!(?error, "Could not connect to validator {name}");
3037+
warn!(?error, "Could not connect to validator {name}");
3038+
} else {
3039+
info!("Connected to validator {name}");
30383040
}
30393041
result.ok()
30403042
})

linera-rpc/src/grpc/client.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ impl GrpcClient {
6666

6767
/// Returns whether this gRPC status means the server stream should be reconnected to, or not.
6868
/// Logs a warning on unexpected status codes.
69-
fn is_retryable(status: &Status) -> bool {
69+
fn is_retryable(status: &Status, address: &str) -> bool {
7070
match status.code() {
7171
Code::DeadlineExceeded | Code::Aborted | Code::Unavailable | Code::Unknown => {
72-
info!("gRPC request interrupted: {}; retrying", status);
72+
info!("gRPC request to {address} interrupted: {status}; retrying");
7373
true
7474
}
7575
Code::Ok
7676
| Code::Cancelled
7777
| Code::NotFound
7878
| Code::AlreadyExists
7979
| Code::ResourceExhausted => {
80-
error!("Unexpected gRPC status: {}; retrying", status);
80+
error!("gRPC request to {address} interrupted: {status}; retrying");
8181
true
8282
}
8383
Code::InvalidArgument
@@ -88,7 +88,7 @@ impl GrpcClient {
8888
| Code::Internal
8989
| Code::DataLoss
9090
| Code::Unauthenticated => {
91-
error!("Unexpected gRPC status: {}", status);
91+
error!("Unexpected gRPC status received from {address}: {status}");
9292
false
9393
}
9494
}
@@ -99,6 +99,7 @@ impl GrpcClient {
9999
f: F,
100100
request: impl TryInto<R> + fmt::Debug + Clone,
101101
handler: &str,
102+
address: &str,
102103
) -> Result<S, NodeError>
103104
where
104105
F: Fn(ValidatorNodeClient<transport::Channel>, Request<R>) -> Fut,
@@ -112,15 +113,17 @@ impl GrpcClient {
112113
})?;
113114
loop {
114115
match f(self.client.clone(), Request::new(request_inner.clone())).await {
115-
Err(s) if Self::is_retryable(&s) && retry_count < self.max_retries => {
116+
Err(s) if Self::is_retryable(&s, address) && retry_count < self.max_retries => {
116117
let delay = self.retry_delay.saturating_mul(retry_count);
117118
retry_count += 1;
118119
tokio::time::sleep(delay).await;
119120
continue;
120121
}
121122
Err(s) => {
122123
return Err(NodeError::GrpcError {
123-
error: format!("remote request [{handler}] failed with status: {s:?}",),
124+
error: format!(
125+
"remote request [{handler}] to {address} failed with status: {s:?}",
126+
),
124127
});
125128
}
126129
Ok(result) => return Ok(result.into_inner()),
@@ -159,6 +162,7 @@ macro_rules! client_delegate {
159162
|mut client, req| async move { client.$handler(req).await },
160163
$req,
161164
stringify!($handler),
165+
&$self.address,
162166
)
163167
.await
164168
}};
@@ -256,6 +260,7 @@ impl ValidatorNode for GrpcClient {
256260

257261
// The stream of `Notification`s that inserts increasing delays after retriable errors, and
258262
// terminates after unexpected or fatal errors.
263+
let address = self.address.clone();
259264
let notification_stream = endlessly_retrying_notification_stream
260265
.map(|result| {
261266
Option::<Notification>::try_from(result?).map_err(|err| {
@@ -268,7 +273,7 @@ impl ValidatorNode for GrpcClient {
268273
retry_count = 0;
269274
return future::Either::Left(future::ready(true));
270275
};
271-
if !Self::is_retryable(status) || retry_count >= max_retries {
276+
if !Self::is_retryable(status, &address) || retry_count >= max_retries {
272277
return future::Either::Left(future::ready(false));
273278
}
274279
let delay = retry_delay.saturating_mul(retry_count);

0 commit comments

Comments
 (0)