Skip to content

Commit

Permalink
feat(papyrus_network): add broadcast and sqmr metrics structs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonLStarkWare committed Feb 9, 2025
1 parent af983bb commit 9daba93
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
use starknet_sequencer_metrics::metrics::MetricGauge;
use starknet_sequencer_metrics::metrics::{MetricCounter, MetricGauge};

pub struct BroadcastNetworkMetrics {
pub num_sent_broadcast_messages: MetricCounter,
pub num_received_broadcast_messages: MetricCounter,
}

impl BroadcastNetworkMetrics {
pub fn register(&self) {
self.num_sent_broadcast_messages.register();
self.num_received_broadcast_messages.register();
}
}

pub struct SqmrNetworkMetrics {}

impl SqmrNetworkMetrics {
pub fn register(&self) {}
}

pub struct NetworkManagerMetrics {
pub num_connected_peers: MetricGauge,
pub num_active_inbound_sessions: MetricGauge,
pub num_active_outbound_sessions: MetricGauge,
pub broadcast_metrics: Option<BroadcastNetworkMetrics>,
pub sqmr_metrics: Option<SqmrNetworkMetrics>,
}

impl NetworkManagerMetrics {
Expand All @@ -13,5 +34,11 @@ impl NetworkManagerMetrics {
num_active_inbound_sessions_metric.set(0f64);
let num_active_outbound_sessions_metric = self.num_active_outbound_sessions.register();
num_active_outbound_sessions_metric.set(0f64);
if let Some(broadcast_metrics) = self.broadcast_metrics.as_ref() {
broadcast_metrics.register();
}
if let Some(sqmr_metrics) = self.sqmr_metrics.as_ref() {
sqmr_metrics.register();
}
}
}
12 changes: 11 additions & 1 deletion crates/starknet_consensus_manager/src/consensus_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use std::sync::Arc;

use async_trait::async_trait;
use papyrus_network::gossipsub_impl::Topic;
use papyrus_network::network_manager::network_manager_metrics::NetworkManagerMetrics;
use papyrus_network::network_manager::network_manager_metrics::{
BroadcastNetworkMetrics,
NetworkManagerMetrics,
};
use papyrus_network::network_manager::{BroadcastTopicChannels, NetworkManager};
use papyrus_protobuf::consensus::{HeightAndRound, ProposalPart, StreamMessage, Vote};
use starknet_api::block::BlockNumber;
Expand All @@ -24,6 +27,8 @@ use starknet_sequencer_metrics::metric_definitions::{
CONSENSUS_NUM_ACTIVE_INBOUND_SESSIONS,
CONSENSUS_NUM_ACTIVE_OUTBOUND_SESSIONS,
CONSENSUS_NUM_CONNECTED_PEERS,
CONSENSUS_NUM_RECEIVED_MESSAGES,
CONSENSUS_NUM_SENT_MESSAGES,
};
use starknet_state_sync_types::communication::SharedStateSyncClient;
use tracing::{error, info};
Expand Down Expand Up @@ -60,6 +65,11 @@ impl ConsensusManager {
num_connected_peers: CONSENSUS_NUM_CONNECTED_PEERS,
num_active_inbound_sessions: CONSENSUS_NUM_ACTIVE_INBOUND_SESSIONS,
num_active_outbound_sessions: CONSENSUS_NUM_ACTIVE_OUTBOUND_SESSIONS,
broadcast_metrics: Some(BroadcastNetworkMetrics {
num_sent_broadcast_messages: CONSENSUS_NUM_SENT_MESSAGES,
num_received_broadcast_messages: CONSENSUS_NUM_RECEIVED_MESSAGES,
}),
sqmr_metrics: None,
});
let mut network_manager =
NetworkManager::new(self.config.network_config.clone(), None, network_manager_metrics);
Expand Down
12 changes: 11 additions & 1 deletion crates/starknet_mempool_p2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ pub mod runner;

use futures::FutureExt;
use papyrus_network::gossipsub_impl::Topic;
use papyrus_network::network_manager::network_manager_metrics::NetworkManagerMetrics;
use papyrus_network::network_manager::network_manager_metrics::{
BroadcastNetworkMetrics,
NetworkManagerMetrics,
};
use papyrus_network::network_manager::{BroadcastTopicChannels, NetworkManager};
use starknet_class_manager_types::transaction_converter::TransactionConverter;
use starknet_class_manager_types::SharedClassManagerClient;
Expand All @@ -13,6 +16,8 @@ use starknet_sequencer_metrics::metric_definitions::{
MEMPOOL_NUM_ACTIVE_INBOUND_SESSIONS,
MEMPOOL_NUM_ACTIVE_OUTBOUND_SESSIONS,
MEMPOOL_NUM_CONNECTED_PEERS,
MEMPOOL_NUM_RECEIVED_MESSAGES,
MEMPOOL_NUM_SENT_MESSAGES,
};

use crate::config::MempoolP2pConfig;
Expand All @@ -34,6 +39,11 @@ pub fn create_p2p_propagator_and_runner(
num_connected_peers: MEMPOOL_NUM_CONNECTED_PEERS,
num_active_inbound_sessions: MEMPOOL_NUM_ACTIVE_INBOUND_SESSIONS,
num_active_outbound_sessions: MEMPOOL_NUM_ACTIVE_OUTBOUND_SESSIONS,
broadcast_metrics: Some(BroadcastNetworkMetrics {
num_sent_broadcast_messages: MEMPOOL_NUM_SENT_MESSAGES,
num_received_broadcast_messages: MEMPOOL_NUM_RECEIVED_MESSAGES,
}),
sqmr_metrics: None,
});
let mut network_manager = NetworkManager::new(
mempool_p2p_config.network_config,
Expand Down
6 changes: 6 additions & 0 deletions crates/starknet_sequencer_metrics/src/metric_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,10 @@ define_counter_metrics!(
{ ADDED_TRANSACTIONS_SUCCESS, "ADDED_TRANSACTIONS_SUCCESS", "Number of successfully added transactions", 0 },
{ ADDED_TRANSACTIONS_FAILURE, "ADDED_TRANSACTIONS_FAILURE", "Number of faulty added transactions", 0 }
},
MetricScope::Network => {
{ MEMPOOL_NUM_SENT_MESSAGES, "apollo_mempool_num_sent_messages", "The number of messages sent by the mempool p2p component", 0 },
{ MEMPOOL_NUM_RECEIVED_MESSAGES, "apollo_mempool_num_received_messages", "The number of messages received by the mempool p2p component", 0 },
{ CONSENSUS_NUM_SENT_MESSAGES, "apollo_consensus_num_sent_messages", "The number of messages sent by the consensus p2p component", 0 },
{ CONSENSUS_NUM_RECEIVED_MESSAGES, "apollo_consensus_num_received_messages", "The number of messages received by the consensus p2p component", 0 },
}
);
3 changes: 3 additions & 0 deletions crates/starknet_state_sync/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ impl StateSyncRunner {
num_connected_peers: STATE_SYNC_NUM_CONNECTED_PEERS,
num_active_inbound_sessions: STATE_SYNC_NUM_ACTIVE_INBOUND_SESSIONS,
num_active_outbound_sessions: STATE_SYNC_NUM_ACTIVE_OUTBOUND_SESSIONS,
broadcast_metrics: None,
// TODO(alonl): Add metrics for SQMR.
sqmr_metrics: None,
});
let mut network_manager = network_manager::NetworkManager::new(
network_config,
Expand Down

0 comments on commit 9daba93

Please sign in to comment.