Skip to content

Commit 95cadba

Browse files
ma2bdjvff
andcommitted
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 a84cdd4 commit 95cadba

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
@@ -3148,7 +3148,9 @@ where
31483148
})
31493149
.filter_map(move |result| async move {
31503150
if let Err(error) = &result {
3151-
info!(?error, "Could not connect to validator {name}");
3151+
warn!(?error, "Could not connect to validator {name}");
3152+
} else {
3153+
info!("Connected to validator {name}");
31523154
}
31533155
result.ok()
31543156
})

linera-rpc/src/grpc/client.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ impl GrpcClient {
6767

6868
/// Returns whether this gRPC status means the server stream should be reconnected to, or not.
6969
/// Logs a warning on unexpected status codes.
70-
fn is_retryable(status: &Status) -> bool {
70+
fn is_retryable(status: &Status, address: &str) -> bool {
7171
match status.code() {
7272
Code::DeadlineExceeded | Code::Aborted | Code::Unavailable | Code::Unknown => {
73-
info!("gRPC request interrupted: {}; retrying", status);
73+
info!("gRPC request to {address} interrupted: {status}; retrying");
7474
true
7575
}
7676
Code::Ok
7777
| Code::Cancelled
7878
| Code::NotFound
7979
| Code::AlreadyExists
8080
| Code::ResourceExhausted => {
81-
error!("Unexpected gRPC status: {}; retrying", status);
81+
error!("gRPC request to {address} interrupted: {status}; retrying");
8282
true
8383
}
8484
Code::InvalidArgument
@@ -89,7 +89,7 @@ impl GrpcClient {
8989
| Code::Internal
9090
| Code::DataLoss
9191
| Code::Unauthenticated => {
92-
error!("Unexpected gRPC status: {}", status);
92+
error!("Unexpected gRPC status received from {address}: {status}");
9393
false
9494
}
9595
}
@@ -100,6 +100,7 @@ impl GrpcClient {
100100
f: F,
101101
request: impl TryInto<R> + fmt::Debug + Clone,
102102
handler: &str,
103+
address: &str,
103104
) -> Result<S, NodeError>
104105
where
105106
F: Fn(ValidatorNodeClient<transport::Channel>, Request<R>) -> Fut,
@@ -113,15 +114,17 @@ impl GrpcClient {
113114
})?;
114115
loop {
115116
match f(self.client.clone(), Request::new(request_inner.clone())).await {
116-
Err(s) if Self::is_retryable(&s) && retry_count < self.max_retries => {
117+
Err(s) if Self::is_retryable(&s, address) && retry_count < self.max_retries => {
117118
let delay = self.retry_delay.saturating_mul(retry_count);
118119
retry_count += 1;
119120
linera_base::time::timer::sleep(delay).await;
120121
continue;
121122
}
122123
Err(s) => {
123124
return Err(NodeError::GrpcError {
124-
error: format!("remote request [{handler}] failed with status: {s:?}",),
125+
error: format!(
126+
"remote request [{handler}] to {address} failed with status: {s:?}",
127+
),
125128
});
126129
}
127130
Ok(result) => return Ok(result.into_inner()),
@@ -160,6 +163,7 @@ macro_rules! client_delegate {
160163
|mut client, req| async move { client.$handler(req).await },
161164
$req,
162165
stringify!($handler),
166+
&$self.address,
163167
)
164168
.await
165169
}};
@@ -257,6 +261,7 @@ impl ValidatorNode for GrpcClient {
257261

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

0 commit comments

Comments
 (0)