Skip to content

Commit

Permalink
add endorsement cache in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
modship committed Jun 13, 2023
1 parent ec51acb commit 6f847f5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
32 changes: 32 additions & 0 deletions massa-metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ pub struct MassaMetrics {
consensus_state_discarded_index: IntGauge,
consensus_state_block_statuses: IntGauge,

// endorsement cache
endorsement_cache_checked_endorsements: IntGauge,
endorsement_cache_known_by_peer: IntGauge,

// blocks_counter: IntGauge,
// endorsements_counter: IntGauge,
// operations_counter: IntGauge,
Expand Down Expand Up @@ -196,6 +200,18 @@ impl MassaMetrics {
)
.unwrap();

let endorsement_cache_checked_endorsements = IntGauge::new(
"endorsement_cache_checked_endorsements",
"endorsement cache checked endorsements size",
)
.unwrap();

let endorsement_cache_known_by_peer = IntGauge::new(
"endorsement_cache_known_by_peer",
"endorsement cache know by peer size",
)
.unwrap();

if enabled {
for i in 0..nb_thread {
let gauge = Gauge::new(
Expand Down Expand Up @@ -239,6 +255,9 @@ impl MassaMetrics {
let _ = prometheus::register(Box::new(
operation_cache_checked_operations_prefix.clone(),
));
let _ =
prometheus::register(Box::new(endorsement_cache_checked_endorsements.clone()));
let _ = prometheus::register(Box::new(endorsement_cache_known_by_peer.clone()));
}
}

Expand All @@ -257,6 +276,8 @@ impl MassaMetrics {
consensus_state_incoming_index,
consensus_state_discarded_index,
consensus_state_block_statuses,
endorsement_cache_checked_endorsements,
endorsement_cache_known_by_peer,
// blocks_counter,
// endorsements_counter,
// operations_counter,
Expand Down Expand Up @@ -353,6 +374,17 @@ impl MassaMetrics {
self.operation_cache_ops_know_by_peer
.set(ops_know_by_peer as i64);
}

pub fn set_endorsements_cache_metrics(
&self,
checked_endorsements: usize,
known_by_peer: usize,
) {
self.endorsement_cache_checked_endorsements
.set(checked_endorsements as i64);
self.endorsement_cache_known_by_peer
.set(known_by_peer as i64);
}
}
// mod test {
// use massa_channel::MassaChannel;
Expand Down
1 change: 1 addition & 0 deletions massa-protocol-worker/src/connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub(crate) fn start_connectivity_thread(
sender_endorsements_propagation_ext,
protocol_channels.endorsement_handler_propagation.1.clone(),
peer_management_handler.sender.command_sender.clone(),
massa_metrics.clone(),
);
let mut block_handler = BlockHandler::new(
network_controller.get_active_connections(),
Expand Down
3 changes: 3 additions & 0 deletions massa-protocol-worker/src/handlers/endorsement_handler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::thread::JoinHandle;

use massa_channel::{receiver::MassaReceiver, sender::MassaSender};
use massa_metrics::MassaMetrics;
use massa_pool_exports::PoolController;
use massa_protocol_exports::ProtocolConfig;
use massa_storage::Storage;
Expand Down Expand Up @@ -49,6 +50,7 @@ impl EndorsementHandler {
local_sender: MassaSender<EndorsementHandlerPropagationCommand>,
local_receiver: MassaReceiver<EndorsementHandlerPropagationCommand>,
sender_peer_cmd: MassaSender<PeerManagementCmd>,
massa_metrics: MassaMetrics,
) -> Self {
let endorsement_retrieval_thread = start_retrieval_thread(
receiver,
Expand All @@ -59,6 +61,7 @@ impl EndorsementHandler {
pool_controller,
config.clone(),
storage.clone_without_refs(),
massa_metrics,
);

let endorsement_propagation_thread =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::thread::JoinHandle;
use std::{thread::JoinHandle, time::Duration};

use crossbeam::select;
use crossbeam::{channel::tick, select};
use massa_channel::{receiver::MassaReceiver, sender::MassaSender};
use massa_logging::massa_trace;
use massa_metrics::MassaMetrics;
use massa_models::{
endorsement::SecureShareEndorsement,
prehash::{CapacityAllocator, PreHashMap, PreHashSet},
Expand Down Expand Up @@ -41,6 +42,7 @@ pub struct RetrievalThread {
config: ProtocolConfig,
storage: Storage,
peer_cmd_sender: MassaSender<PeerManagementCmd>,
metrics: MassaMetrics,
}

impl RetrievalThread {
Expand All @@ -51,6 +53,8 @@ impl RetrievalThread {
max_length_endorsements: self.config.max_endorsements_per_message,
endorsement_count: self.config.endorsement_count,
});
let tick_metrics = tick(Duration::from_secs(5));

loop {
select! {
recv(self.receiver) -> msg => {
Expand Down Expand Up @@ -110,6 +114,17 @@ impl RetrievalThread {
return;
}
}
},
recv(tick_metrics) -> _ => {
// update metrics
let read = self.cache.read();
let count = read
.endorsements_known_by_peer
.iter()
.map(|(_peer_id, map)| map.len())
.sum();
self.metrics
.set_endorsements_cache_metrics(read.checked_endorsements.len(), count);
}
}
}
Expand Down Expand Up @@ -261,6 +276,7 @@ pub fn start_retrieval_thread(
pool_controller: Box<dyn PoolController>,
config: ProtocolConfig,
storage: Storage,
metrics: MassaMetrics,
) -> JoinHandle<()> {
std::thread::Builder::new()
.name("protocol-endorsement-handler-retrieval".to_string())
Expand All @@ -274,6 +290,7 @@ pub fn start_retrieval_thread(
pool_controller,
config,
storage,
metrics,
};
retrieval_thread.run();
})
Expand Down

0 comments on commit 6f847f5

Please sign in to comment.