diff --git a/common/wireguard/src/peer_controller/mod.rs b/common/wireguard/src/peer_controller/mod.rs index 9aae772a8f..19f936b93b 100644 --- a/common/wireguard/src/peer_controller/mod.rs +++ b/common/wireguard/src/peer_controller/mod.rs @@ -1,6 +1,7 @@ // Copyright 2024 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +pub use crate::ip_pool::IpPair; use crate::ip_pool::allocated_ip_pair; use crate::{ IpPool, @@ -23,6 +24,7 @@ use nym_credentials_interface::CredentialSpendingData; use nym_gateway_requests::models::CredentialSpendingRequest; use nym_gateway_storage::traits::BandwidthGatewayStorage; use nym_node_metrics::NymNodeMetrics; +use nym_node_metrics::prometheus_wrapper::{PROMETHEUS_METRICS, PrometheusMetric}; use nym_wireguard_types::{ DEFAULT_IP_CLEANUP_INTERVAL, DEFAULT_IP_STALE_AGE, DEFAULT_PEER_TIMEOUT_CHECK, }; @@ -35,8 +37,6 @@ use tokio::sync::{RwLock, mpsc}; use tokio_stream::{StreamExt, wrappers::IntervalStream}; use tracing::{debug, error, info, trace}; -pub use crate::ip_pool::IpPair; - #[cfg(feature = "mock")] pub mod mock; @@ -261,6 +261,10 @@ impl PeerController { } async fn handle_add_request(&mut self, peer: &Peer) -> Result<()> { + // observation will get automatically added once dropped + let _metric_timer = + PROMETHEUS_METRICS.start_timer(PrometheusMetric::WireguardDefguardPeerCreation); + nym_metrics::inc!("wg_peer_addition_attempts"); // confirm ip allocation so that it wouldn't be released for as long as the peer exists diff --git a/gateway/src/node/wireguard/new_peer_registration/mod.rs b/gateway/src/node/wireguard/new_peer_registration/mod.rs index b2f89accf7..ddb53b5517 100644 --- a/gateway/src/node/wireguard/new_peer_registration/mod.rs +++ b/gateway/src/node/wireguard/new_peer_registration/mod.rs @@ -32,6 +32,7 @@ use nym_crypto::asymmetric::x25519; use nym_gateway_requests::models::CredentialSpendingRequest; use nym_gateway_storage::models::PersistedBandwidth; use nym_lp::peer_config::LpReceiverIndex; +use nym_node_metrics::prometheus_wrapper::{PrometheusMetric, PROMETHEUS_METRICS}; use nym_registration_common::dvpn::{ LpDvpnRegistrationFinalisation, LpDvpnRegistrationInitialRequest, }; @@ -126,6 +127,9 @@ impl PeerRegistrator { credential: CredentialSpendingData, client_id: i64, ) -> Result { + let _metric_timer = PROMETHEUS_METRICS + .start_timer(PrometheusMetric::PeerRegistrationCredentialVerification); + let bandwidth = self.credential_storage_preparation(client_id).await?; let client_bandwidth = ClientBandwidth::new(bandwidth.into()); let mut verifier = CredentialVerifier::new( @@ -232,6 +236,9 @@ impl PeerRegistrator { request_id: u64, reply_to: Option, ) -> Result { + let _metric_timer = PROMETHEUS_METRICS + .start_timer(PrometheusMetric::DvpnAuthenticatorClientRegistrationMsg1); + let remote_public = init_message.pub_key(); // 1. check if there's any pending registration already in progress, @@ -269,6 +276,9 @@ impl PeerRegistrator { request_id: u64, reply_to: Option, ) -> Result { + let _metric_timer = PROMETHEUS_METRICS + .start_timer(PrometheusMetric::DvpnAuthenticatorClientRegistrationMsg2); + let peer = final_message.gateway_client_pub_key(); // 1. check if there's any pending registration associated with this peer let pending_data = self @@ -312,6 +322,9 @@ impl PeerRegistrator { init_msg: LpDvpnRegistrationInitialRequest, receiver_index: LpReceiverIndex, ) -> Result { + let _metric_timer = + PROMETHEUS_METRICS.start_timer(PrometheusMetric::DvpnLpClientRegistrationMsg1); + let remote_public = init_msg.wg_public_key; let psk = Key::new(init_msg.psk); @@ -343,6 +356,9 @@ impl PeerRegistrator { final_msg: LpDvpnRegistrationFinalisation, receiver_index: LpReceiverIndex, ) -> Result { + let _metric_timer = + PROMETHEUS_METRICS.start_timer(PrometheusMetric::DvpnLpClientRegistrationMsg2); + // 1. check if there's any pending registration associated with this peer let pending_data = self .pending_registrations diff --git a/nym-node/nym-node-metrics/src/prometheus_wrapper.rs b/nym-node/nym-node-metrics/src/prometheus_wrapper.rs index 4102e82c98..ffdb66e5c0 100644 --- a/nym-node/nym-node-metrics/src/prometheus_wrapper.rs +++ b/nym-node/nym-node-metrics/src/prometheus_wrapper.rs @@ -24,6 +24,18 @@ const CLIENT_SESSION_DURATION_BUCKETS: &[f64] = &[ 259200., // 72h+ (implicitly) ]; +const REG_LATENCY_BUCKETS: &[f64] = &[ + 0.001, // 1ms + 0.005, // 5ms + 0.01, // 10ms + 0.05, // 50ms + 0.1, // 100ms + 0.25, // 250ms + 0.5, // 500ms + 1.0, // 1s + 2.0, // 2s +]; + #[derive(Clone, Debug, EnumIter, Display, EnumProperty, EnumCount, Eq, Hash, PartialEq)] #[strum(serialize_all = "snake_case", prefix = "nym_node_")] pub enum PrometheusMetric { @@ -139,6 +151,34 @@ pub enum PrometheusMetric { #[strum(props(help = "The current receiving rate of wireguard"))] WireguardBytesRxRate, + #[strum(props(help = "The distribution of defguard peer creation time"))] + WireguardDefguardPeerCreation, + + #[strum(props( + help = "The distribution of time it takes to verify a credential during peer registration" + ))] + PeerRegistrationCredentialVerification, + + #[strum(props( + help = "The distribution of time for client dvpn registration through the authenticator for msg1" + ))] + DvpnAuthenticatorClientRegistrationMsg1, + + #[strum(props( + help = "The distribution of time for client dvpn registration through the authenticator for msg2" + ))] + DvpnAuthenticatorClientRegistrationMsg2, + + #[strum(props( + help = "The distribution of time for client dvpn registration through the lp for msg1" + ))] + DvpnLpClientRegistrationMsg1, + + #[strum(props( + help = "The distribution of time for client dvpn registration through the lp for msg2" + ))] + DvpnLpClientRegistrationMsg2, + // # NETWORK #[strum(props(help = "The number of active ingress mixnet connections"))] NetworkActiveIngressMixnetConnections, @@ -271,6 +311,24 @@ impl PrometheusMetric { PrometheusMetric::WireguardActivePeers => Metric::new_int_gauge(&name, help), PrometheusMetric::WireguardBytesTxRate => Metric::new_float_gauge(&name, help), PrometheusMetric::WireguardBytesRxRate => Metric::new_float_gauge(&name, help), + PrometheusMetric::WireguardDefguardPeerCreation => { + Metric::new_histogram(&name, help, Some(REG_LATENCY_BUCKETS)) + } + PrometheusMetric::DvpnAuthenticatorClientRegistrationMsg1 => { + Metric::new_histogram(&name, help, Some(REG_LATENCY_BUCKETS)) + } + PrometheusMetric::DvpnAuthenticatorClientRegistrationMsg2 => { + Metric::new_histogram(&name, help, Some(REG_LATENCY_BUCKETS)) + } + PrometheusMetric::DvpnLpClientRegistrationMsg1 => { + Metric::new_histogram(&name, help, Some(REG_LATENCY_BUCKETS)) + } + PrometheusMetric::DvpnLpClientRegistrationMsg2 => { + Metric::new_histogram(&name, help, Some(REG_LATENCY_BUCKETS)) + } + PrometheusMetric::PeerRegistrationCredentialVerification => { + Metric::new_histogram(&name, help, Some(REG_LATENCY_BUCKETS)) + } PrometheusMetric::NetworkActiveIngressMixnetConnections => { Metric::new_int_gauge(&name, help) } @@ -388,7 +446,7 @@ mod tests { // a sanity check for anyone adding new metrics. if this test fails, // make sure any methods on `PrometheusMetric` enum don't need updating // or require custom Display impl - assert_eq!(39, PrometheusMetric::COUNT) + assert_eq!(45, PrometheusMetric::COUNT) } #[test]