Skip to content

Commit ec35637

Browse files
committed
Conditionally log to DEBUG if 0 delta delta_rx_bytes=0 delta_tx_bytes=0
1 parent 1ce3f48 commit ec35637

1 file changed

Lines changed: 41 additions & 11 deletions

File tree

src/userspace_helper.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ async fn wait_for_shutdown(running: &RunningDevice) -> anyhow::Result<()> {
491491
let mut next_reconcile_at = std::time::Instant::now();
492492
#[cfg(target_os = "macos")]
493493
let mut last_transfer: Option<(u64, u64)> = None;
494+
#[cfg(target_os = "macos")]
495+
let mut last_probe_sent: Option<(bool, bool)> = None;
494496

495497
#[cfg(target_os = "macos")]
496498
info!(
@@ -535,6 +537,7 @@ async fn wait_for_shutdown(running: &RunningDevice) -> anyhow::Result<()> {
535537
log_macos_dataplane_probe(
536538
&running.control_interface_name,
537539
&mut last_transfer,
540+
&mut last_probe_sent,
538541
)
539542
.await;
540543
}
@@ -547,13 +550,22 @@ async fn wait_for_shutdown(running: &RunningDevice) -> anyhow::Result<()> {
547550
}
548551

549552
#[cfg(target_os = "macos")]
550-
async fn log_macos_dataplane_probe(interface: &str, last_transfer: &mut Option<(u64, u64)>) {
553+
async fn log_macos_dataplane_probe(
554+
interface: &str,
555+
last_transfer: &mut Option<(u64, u64)>,
556+
last_probe_sent: &mut Option<(bool, bool)>,
557+
) {
551558
let ipv4_probe_sent = send_udp_probe(SocketAddr::from((Ipv4Addr::new(8, 8, 8, 8), 53)));
552559
let ipv6_probe_sent = send_udp_probe(SocketAddr::from((
553560
Ipv6Addr::new(0x2001, 0x4860, 0x4860, 0, 0, 0, 0, 0x8888),
554561
53,
555562
)));
556563

564+
// A probe-send flag flipping (a send starting or stopping to work) is worth
565+
// surfacing at INFO; an unchanged flag is not.
566+
let probe_sent_changed = *last_probe_sent != Some((ipv4_probe_sent, ipv6_probe_sent));
567+
*last_probe_sent = Some((ipv4_probe_sent, ipv6_probe_sent));
568+
557569
match read_wg_transfer_bytes(interface).await {
558570
Ok(Some((rx_bytes, tx_bytes))) => {
559571
let (delta_rx_bytes, delta_tx_bytes) = last_transfer
@@ -565,16 +577,34 @@ async fn log_macos_dataplane_probe(interface: &str, last_transfer: &mut Option<(
565577
})
566578
.unwrap_or((0, 0));
567579
*last_transfer = Some((rx_bytes, tx_bytes));
568-
info!(
569-
interface,
570-
ipv4_probe_sent,
571-
ipv6_probe_sent,
572-
rx_bytes,
573-
tx_bytes,
574-
delta_rx_bytes,
575-
delta_tx_bytes,
576-
"userspace_helper_dataplane_probe"
577-
);
580+
// Steady idle tunnels probe every 5s with no movement; keep that
581+
// heartbeat at DEBUG so default (INFO) logs stay quiet, and only
582+
// surface probes that actually moved bytes or changed send state.
583+
let noteworthy =
584+
delta_rx_bytes != 0 || delta_tx_bytes != 0 || probe_sent_changed;
585+
if noteworthy {
586+
info!(
587+
interface,
588+
ipv4_probe_sent,
589+
ipv6_probe_sent,
590+
rx_bytes,
591+
tx_bytes,
592+
delta_rx_bytes,
593+
delta_tx_bytes,
594+
"userspace_helper_dataplane_probe"
595+
);
596+
} else {
597+
debug!(
598+
interface,
599+
ipv4_probe_sent,
600+
ipv6_probe_sent,
601+
rx_bytes,
602+
tx_bytes,
603+
delta_rx_bytes,
604+
delta_tx_bytes,
605+
"userspace_helper_dataplane_probe"
606+
);
607+
}
578608
}
579609
Ok(None) => {
580610
info!(

0 commit comments

Comments
 (0)