From 1e5599e5fc68fa77b3efcebd65fa90f35001dba6 Mon Sep 17 00:00:00 2001 From: Jamil Date: Thu, 23 Jan 2025 17:17:43 -0800 Subject: [PATCH] refactor(connlib): only log actual updates to the allocation (#7826) With #7819, these log messages appear at a ~10x higher rate than before - a day's worth of these would be over 3,000 messages. For BINDING requests, these only matter if the candidates change, therefore we can make the logging conditional to that. --------- Co-authored-by: Thomas Eizinger --- rust/connlib/snownet/src/allocation.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/rust/connlib/snownet/src/allocation.rs b/rust/connlib/snownet/src/allocation.rs index 413777a26..01eb9a583 100644 --- a/rust/connlib/snownet/src/allocation.rs +++ b/rust/connlib/snownet/src/allocation.rs @@ -513,9 +513,9 @@ impl Allocation { }; let maybe_candidate = message.attributes().find_map(|a| srflx_candidate(local, a)); - update_candidate(maybe_candidate, current_srflx_candidate, &mut self.events); - - self.log_update(now); + if update_candidate(maybe_candidate, current_srflx_candidate, &mut self.events) { + self.log_update(now); + } // Second, check if we have already determined which socket to use for this relay. // We send 2 BINDING requests to start with (one for each IP version) and the first one coming back wins. @@ -1184,22 +1184,29 @@ fn authenticate(message: Message, credentials: &Credentials) -> Messa message } +/// Updates the current candidate to the new one if it differs. +/// +/// Returns whether the candidate got updated. fn update_candidate( maybe_new: Option, maybe_current: &mut Option, events: &mut VecDeque, -) { +) -> bool { match (maybe_new, &maybe_current) { (Some(new), Some(current)) if &new != current => { events.push_back(Event::New(new.clone())); events.push_back(Event::Invalid(current.clone())); *maybe_current = Some(new); + + true } (Some(new), None) => { *maybe_current = Some(new.clone()); events.push_back(Event::New(new)); + + true } - _ => {} + _ => false, } }