From 4e11f64bb7960ba4d2e21d6679f82d16cbd02879 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Sun, 16 Jun 2024 19:57:08 +0200 Subject: [PATCH 1/2] add more logs 1 --- src/gateway.rs | 28 +++++++++++++++++++--------- src/lib.rs | 5 ++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/gateway.rs b/src/gateway.rs index 6fa4c5be..bc9f3822 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -139,7 +139,9 @@ impl Gateway { let ifname = self.config.ifname.clone(); let userspace = self.config.userspace; let stats_stream = async_stream::stream! { - let wgapi = WGApi::new(ifname, userspace).expect("Failed to initialize WireGuard interface API"); + let wgapi = WGApi::new(ifname, userspace).expect( + "Failed to initialize WireGuard interface API, interface name: {ifname}, userspace: {userspace}" + ); // helper map to track if peer data is actually changing // and avoid sending duplicate stats let mut peer_map = HashMap::new(); @@ -190,11 +192,12 @@ impl Gateway { } } }; - info!("Spawning stats thread"); + debug!("Spawning stats thread"); // Spawn the thread tokio::spawn(async move { let _ = client.stats(Request::new(stats_stream)).await; }); + info!("Stats thread spawned."); } /// Performs complete interface reconfiguration based on `configuration` object. @@ -269,10 +272,12 @@ impl Gateway { break Ok(stream.into_inner()); } (Err(err), _) => { - error!("Couldn't retrieve gateway configuration, retrying in 10s; {err}"); + error!("Couldn't retrieve gateway configuration from the core. Using gRPC url: {}. Retrying in 10s. Error: {err}", + self.config.grpc_url); } (_, Err(err)) => { - error!("Couldn't establish streaming connection, retrying in 10s; {err}"); + error!("Couldn't establish streaming connection to the core. Using gRPC url: {}. Retrying in 10s. Error: {err}", + self.config.grpc_url); } } sleep(TEN_SECS).await; @@ -308,7 +313,8 @@ impl Gateway { let token = MetadataValue::try_from(&self.config.token)?; let hostname = gethostname() .into_string() - .expect("Unable to get current hostname"); + .expect("Unable to get current hostname during gRPC connection setup."); + debug!("Using hostname: {hostname}"); let hostname = MetadataValue::try_from(hostname).unwrap(); let jwt_auth_interceptor = move |mut req: Request<()>| -> Result, Status> { req.metadata_mut().insert("authorization", token.clone()); @@ -316,6 +322,7 @@ impl Gateway { Ok(req) }; let client = GatewayServiceClient::with_interceptor(channel, jwt_auth_interceptor); + info!("gRPC server connection setup done.",); Ok(client) } @@ -336,12 +343,15 @@ impl Gateway { // Try to create network interface for WireGuard. // FIXME: check if the interface already exists, or somehow be more clever. if let Err(err) = wgapi.create_interface() { - warn!("Couldn't create network interface: {err}. Proceeding anyway."); + warn!( + "Couldn't create network interface {}: {err}. Proceeding anyway.", + self.config.ifname + ); } let mut updates_stream = self.connect(client.clone()).await?; if let Some(post_up) = &self.config.post_up { - info!("Executing specified POST_UP command: {post_up}"); + debug!("Executing specified POST_UP command: {post_up}"); execute_command(post_up)?; } loop { @@ -355,7 +365,7 @@ impl Gateway { } } Some(update::Update::Peer(peer_config)) => { - info!("Applying peer configuration: {peer_config:?}"); + debug!("Applying peer configuration: {peer_config:?}"); // UpdateType::Delete if update.update_type == 2 { debug!("Deleting peer {peer_config:?}"); @@ -379,7 +389,7 @@ impl Gateway { } }; } - _ => warn!("Unsupported kind of update"), + _ => warn!("Unsupported kind of update: {update:?}"), } } Ok(None) => { diff --git a/src/lib.rs b/src/lib.rs index 466752b8..37d71fc7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,7 +57,10 @@ pub fn execute_command(command: &str) -> Result<(), GatewayError> { let stdout = String::from_utf8_lossy(&output.stdout); let stderr = String::from_utf8_lossy(&output.stderr); - info!("Command executed successfully. Stdout:\n{}", stdout); + info!( + "Postup command {} executed successfully. Stdout:\n{}", + command, stdout + ); if !stderr.is_empty() { error!("Stderr:\n{stderr}"); } From 77ed3ac9d3f30a2e604954fdec78a38bc19f60a2 Mon Sep 17 00:00:00 2001 From: Aleksander <170264518+t-aleksander@users.noreply.github.com> Date: Mon, 17 Jun 2024 18:45:48 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Jacek Chmielewski --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 37d71fc7..673d7932 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,7 +58,7 @@ pub fn execute_command(command: &str) -> Result<(), GatewayError> { let stderr = String::from_utf8_lossy(&output.stderr); info!( - "Postup command {} executed successfully. Stdout:\n{}", + "Postup command {} executed successfully. Stdout: {}", command, stdout ); if !stderr.is_empty() {