diff --git a/crates/http/src/workers/swarm/storage.rs b/crates/http/src/workers/swarm/storage.rs index eab15be..a6419fc 100644 --- a/crates/http/src/workers/swarm/storage.rs +++ b/crates/http/src/workers/swarm/storage.rs @@ -99,6 +99,7 @@ impl TorrentMaps { } } + #[cfg(feature = "metrics")] pub fn update_torrent_metrics(&self) { self.ipv4.torrent_gauge.set(self.ipv4.torrents.len() as f64); self.ipv6.torrent_gauge.set(self.ipv6.torrents.len() as f64); diff --git a/crates/ws/src/workers/socket/connection.rs b/crates/ws/src/workers/socket/connection.rs index 00de5c6..2587ca1 100644 --- a/crates/ws/src/workers/socket/connection.rs +++ b/crates/ws/src/workers/socket/connection.rs @@ -42,6 +42,7 @@ use crate::workers::socket::calculate_in_message_consumer_index; use crate::workers::socket::{ip_version_to_metrics_str, WORKER_INDEX}; /// Optional second tuple field is for peer id hex representation +#[cfg(feature = "metrics")] type PeerClientGauge = (Gauge, Option); pub struct ConnectionRunner { @@ -68,6 +69,7 @@ impl ConnectionRunner { let clean_up_data = ConnectionCleanupData { announced_info_hashes: Default::default(), ip_version: self.ip_version, + #[cfg(feature = "metrics")] opt_peer_client: Default::default(), #[cfg(feature = "metrics")] active_connections_gauge: ::metrics::gauge!( @@ -597,6 +599,7 @@ impl ConnectionWriter { struct ConnectionCleanupData { announced_info_hashes: Rc>>, ip_version: IpVersion, + #[cfg(feature = "metrics")] opt_peer_client: Rc>>, #[cfg(feature = "metrics")] active_connections_gauge: Gauge, diff --git a/crates/ws/src/workers/socket/mod.rs b/crates/ws/src/workers/socket/mod.rs index 040fce7..8d79679 100644 --- a/crates/ws/src/workers/socket/mod.rs +++ b/crates/ws/src/workers/socket/mod.rs @@ -240,14 +240,14 @@ async fn clean_connections( } }); - ::log::info!( - "cleaned connections in worker {}, {} references remaining", - WORKER_INDEX.get(), - connection_slab.borrow_mut().len() - ); - #[cfg(feature = "metrics")] { + ::log::info!( + "cleaned connections in worker {}, {} references remaining", + WORKER_INDEX.get(), + connection_slab.borrow_mut().len() + ); + // Increment gauges by zero to prevent them from being removed due to // idleness diff --git a/crates/ws/src/workers/swarm/storage.rs b/crates/ws/src/workers/swarm/storage.rs index abb6a22..43820b4 100644 --- a/crates/ws/src/workers/swarm/storage.rs +++ b/crates/ws/src/workers/swarm/storage.rs @@ -176,6 +176,7 @@ impl TorrentMap { server_start_instant, request_sender_meta, &request, + #[cfg(feature = "metrics")] &self.peer_gauge, ); @@ -260,7 +261,11 @@ impl TorrentMap { pub fn handle_connection_closed(&mut self, info_hash: InfoHash, peer_id: PeerId) { if let Some(torrent_data) = self.torrents.get_mut(&info_hash) { - torrent_data.handle_connection_closed(peer_id, &self.peer_gauge); + torrent_data.handle_connection_closed( + peer_id, + #[cfg(feature = "metrics")] + &self.peer_gauge, + ); } }