diff --git a/ant-node-manager/src/lib.rs b/ant-node-manager/src/lib.rs index 5f690e3cca..c3e36b895d 100644 --- a/ant-node-manager/src/lib.rs +++ b/ant-node-manager/src/lib.rs @@ -39,8 +39,7 @@ impl From for VerbosityLevel { } use crate::error::{Error, Result}; -use ant_service_management::metric::MetricClient; -use ant_service_management::rpc::RpcActions; +use ant_service_management::metric::{MetricActions, MetricClient}; use ant_service_management::{ control::ServiceControl, error::Error as ServiceError, NodeRegistry, NodeService, NodeServiceData, ServiceStateActions, ServiceStatus, UpgradeOptions, diff --git a/ant-node-manager/src/local.rs b/ant-node-manager/src/local.rs index adf01a850d..bceec34760 100644 --- a/ant-node-manager/src/local.rs +++ b/ant-node-manager/src/local.rs @@ -14,10 +14,9 @@ use crate::helpers::{ use ant_bootstrap::PeersArgs; use ant_evm::{EvmNetwork, RewardsAddress}; use ant_logging::LogFormat; -use ant_service_management::metric::MetricClient; +use ant_service_management::metric::{MetricActions, MetricClient}; use ant_service_management::{ control::ServiceControl, - rpc::RpcActions, NodeRegistry, NodeServiceData, ServiceStatus, }; use color_eyre::eyre::OptionExt; @@ -382,7 +381,7 @@ pub struct RunNodeOptions { pub async fn run_node( run_options: RunNodeOptions, launcher: &dyn Launcher, - metric_client: &dyn RpcActions, + metric_client: &dyn MetricActions, ) -> Result { info!("Launching node {}...", run_options.number); println!("Launching node {}...", run_options.number); diff --git a/ant-service-management/src/metric.rs b/ant-service-management/src/metric.rs index ff9c8ac7a7..b8ee3d0205 100644 --- a/ant-service-management/src/metric.rs +++ b/ant-service-management/src/metric.rs @@ -1,7 +1,7 @@ // use ant_protocol::CLOSE_GROUP_SIZE; use async_trait::async_trait; use libp2p::PeerId; -use crate::rpc::{RpcActions, NodeInfo, NetworkInfo, RecordAddress}; +use crate::rpc::{NodeInfo, NetworkInfo}; use tokio::time::Duration; use std::path::PathBuf; use crate::error::{Result,Error}; @@ -9,6 +9,12 @@ use crate::error::{Result,Error}; // const MAX_CONNECTION_RETRY_ATTEMPTS: u8 = 5; //const CONNECTION_RETRY_DELAY_SEC: Duration = Duration::from_secs(1); +#[async_trait] +pub trait MetricActions: Sync { + async fn node_info(&self) -> Result; + async fn network_info(&self) -> Result; + async fn is_node_connected_to_network(&self, timeout: Duration) -> Result<()>; +} #[derive(Debug, Clone)] pub struct NodeInfoMetrics { peer_id: PeerId, @@ -158,7 +164,7 @@ impl MetricClient { } #[async_trait] -impl RpcActions for MetricClient { +impl MetricActions for MetricClient { async fn node_info(&self) -> Result { let scrape = self.get_endpoint_metrics("metadata_extended").await?; let mut node_info = NodeInfoMetrics::default(); @@ -202,21 +208,10 @@ impl RpcActions for MetricClient { }) } - async fn record_addresses(&self) -> Result> { - Ok(vec![]) - } - - async fn node_restart(&self, _delay_millis: u64, _retain_peer_id: bool) -> Result<()> { - Ok(()) - } - - async fn node_stop(&self, _delay_millis: u64) -> Result<()> { - Ok(()) - } - async fn is_node_connected_to_network(&self, _timeout: Duration) -> Result<()> { - // This is causing 5 mins delay during starting the node, - // need to debug and fix without this, nodes are starting normally + // Todo: This is causing 5 mins delay during starting the node, + // Todo: metrics server starts way later than the rpc server in node, need to refactor it further. + // let max_attempts = std::cmp::max(1, timeout.as_secs() / CONNECTION_RETRY_DELAY_SEC.as_secs()); // trace!( // "Metric conneciton max attempts set to: {max_attempts} with retry_delay of {:?}", @@ -254,12 +249,4 @@ impl RpcActions for MetricClient { // } Ok(()) } - - async fn update_log_level(&self, _log_levels: String) -> Result<()> { - Ok(()) - } - - async fn node_update(&self, _delay_millis: u64) -> Result<()> { - Ok(()) - } } diff --git a/ant-service-management/src/node.rs b/ant-service-management/src/node.rs index cd92f6bac0..786878a7ec 100644 --- a/ant-service-management/src/node.rs +++ b/ant-service-management/src/node.rs @@ -6,7 +6,7 @@ // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. -use crate::{error::Result, rpc::RpcActions, ServiceStateActions, ServiceStatus, UpgradeOptions}; +use crate::{error::Result, metric::MetricActions, ServiceStateActions, ServiceStatus, UpgradeOptions}; use ant_bootstrap::PeersArgs; use ant_evm::{AttoTokens, EvmNetwork, RewardsAddress}; use ant_logging::LogFormat; @@ -25,7 +25,7 @@ use std::{ pub struct NodeService<'a> { pub service_data: &'a mut NodeServiceData, - pub rpc_actions: Box, + pub metric_actions: Box, /// Used to enable dynamic startup delay based on the time it takes for a node to connect to the network. pub connection_timeout: Option, } @@ -33,10 +33,10 @@ pub struct NodeService<'a> { impl<'a> NodeService<'a> { pub fn new( service_data: &'a mut NodeServiceData, - rpc_actions: Box, + metric_actions: Box, ) -> NodeService<'a> { NodeService { - rpc_actions, + metric_actions, service_data, connection_timeout: None, } @@ -176,18 +176,18 @@ impl ServiceStateActions for NodeService<'_> { "Performing dynamic startup delay for {}", self.service_data.service_name ); - self.rpc_actions + self.metric_actions .is_node_connected_to_network(connection_timeout) .await?; } let node_info = self - .rpc_actions + .metric_actions .node_info() .await .inspect_err(|err| error!("Error obtaining node_info via RPC: {err:?}"))?; let network_info = self - .rpc_actions + .metric_actions .network_info() .await .inspect_err(|err| error!("Error obtaining network_info via RPC: {err:?}"))?;