Skip to content

Commit

Permalink
feat(net) Add TransactionsManager Metrics (paradigmxyz#769)
Browse files Browse the repository at this point in the history
* Added TransactionsManager Metrics

* Remove tracking of peers

* Add propagated_transactions
  • Loading branch information
Kuly14 authored Jan 8, 2023
1 parent 5085ac7 commit 05e9c79
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/net/network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ pub struct NetworkMetrics {
/// Number of invalid/malformed messages received from peers
pub(crate) invalid_messages_received: Counter,
}

/// Metrics for the TransactionManager
#[derive(Metrics)]
#[metrics(scope = "network")]
pub struct TransactionsManagerMetrics {
/// Total number of propagated transactions
pub(crate) propagated_transactions: Counter,
}
7 changes: 7 additions & 0 deletions crates/net/network/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
cache::LruCache,
manager::NetworkEvent,
message::{PeerRequest, PeerRequestSender},
metrics::TransactionsManagerMetrics,
network::NetworkHandleMessage,
peers::ReputationChangeKind,
NetworkHandle,
Expand Down Expand Up @@ -101,6 +102,8 @@ pub struct TransactionsManager<Pool> {
pending_transactions: ReceiverStream<TxHash>,
/// Incoming events from the [`NetworkManager`](crate::NetworkManager).
transaction_events: UnboundedReceiverStream<NetworkTransactionEvent>,
/// TransactionsManager metrics
metrics: TransactionsManagerMetrics,
}

impl<Pool: TransactionPool> TransactionsManager<Pool> {
Expand Down Expand Up @@ -130,6 +133,7 @@ impl<Pool: TransactionPool> TransactionsManager<Pool> {
command_rx: UnboundedReceiverStream::new(command_rx),
pending_transactions: ReceiverStream::new(pending),
transaction_events: UnboundedReceiverStream::new(from_network),
metrics: Default::default(),
}
}
}
Expand Down Expand Up @@ -235,6 +239,9 @@ where
}
}

// Update propagated transactions metrics
self.metrics.propagated_transactions.increment(propagated.0.len() as u64);

propagated
}

Expand Down
1 change: 1 addition & 0 deletions docs/design/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ This list may be non-exhaustive.
- `network.total_incoming_connections`: Total number of incoming connections handled
- `network.total_outgoing_connections`: Total number of outgoing connections established
- `network.invalid_messages_received`: Number of invalid/malformed messages received from peers
- `network.propagated_transactions`: Total number of propagated transactions

[metrics]: https://docs.rs/metrics
[metrics.Key]: https://docs.rs/metrics/latest/metrics/struct.Key.html
Expand Down

0 comments on commit 05e9c79

Please sign in to comment.