Skip to content

Commit 7bb7077

Browse files
committed
Improve logging
1 parent 9480f32 commit 7bb7077

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

redis/src/aio/connection.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,16 @@ pub(crate) async fn get_socket_addrs(
444444
}
445445
}
446446

447+
fn log_conn_creation<T>(conn_type: &str, node: T, ip: Option<IpAddr>)
448+
where
449+
T: std::fmt::Debug,
450+
{
451+
info!(
452+
"Creating {conn_type} connection for node: {node:?}{}",
453+
ip.map(|ip| format!(", IP: {:?}", ip)).unwrap_or_default()
454+
);
455+
}
456+
447457
pub(crate) async fn connect_simple<T: RedisRuntime>(
448458
connection_info: &ConnectionInfo,
449459
_socket_addr: Option<SocketAddr>,
@@ -458,7 +468,7 @@ pub(crate) async fn connect_simple<T: RedisRuntime>(
458468
}
459469
let socket_addrs = get_socket_addrs(host, port).await?;
460470
select_ok(socket_addrs.map(|socket_addr| {
461-
info!("IP of node {:?} is {:?}", host, socket_addr.ip());
471+
log_conn_creation("TCP", host, Some(socket_addr.ip()));
462472
Box::pin(async move {
463473
Ok::<_, RedisError>((
464474
<T>::connect_tcp(socket_addr).await?,
@@ -485,7 +495,7 @@ pub(crate) async fn connect_simple<T: RedisRuntime>(
485495
}
486496
let socket_addrs = get_socket_addrs(host, port).await?;
487497
select_ok(socket_addrs.map(|socket_addr| {
488-
info!("IP of node {:?} is {:?}", host, socket_addr.ip());
498+
log_conn_creation("TCP with TLS", host, Some(socket_addr.ip()));
489499
Box::pin(async move {
490500
Ok::<_, RedisError>((
491501
<T>::connect_tcp_tls(host, socket_addr, insecure, tls_params).await?,
@@ -506,7 +516,10 @@ pub(crate) async fn connect_simple<T: RedisRuntime>(
506516
}
507517

508518
#[cfg(unix)]
509-
ConnectionAddr::Unix(ref path) => (<T>::connect_unix(path).await?, None),
519+
ConnectionAddr::Unix(ref path) => {
520+
log_conn_creation("UDS", path, None);
521+
(<T>::connect_unix(path).await?, None)
522+
}
510523

511524
#[cfg(not(unix))]
512525
ConnectionAddr::Unix(_) => {

redis/src/cluster_topology.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::sync::Arc;
1616
use std::time::{Duration, SystemTime};
1717
#[cfg(all(feature = "cluster-async", feature = "tokio-comp"))]
1818
use tokio::sync::RwLock;
19+
use tracing::info;
1920

2021
// Exponential backoff constants for retrying a slot refresh
2122
/// The default number of refresh topology retries in the same call
@@ -260,8 +261,11 @@ pub(crate) fn calculate_topology<'a>(
260261
}
261262

262263
let parse_and_built_result = |most_frequent_topology: TopologyView| {
264+
info!(
265+
"calculate_topology found topology map:\n{:?}",
266+
most_frequent_topology
267+
);
263268
let slots_data = most_frequent_topology.slots_and_count.1;
264-
265269
Ok((
266270
SlotMap::new(slots_data, read_from_replica),
267271
most_frequent_topology.hash_value,

0 commit comments

Comments
 (0)