Skip to content

Commit

Permalink
network: remove near_<msg-type>_{total,bytes} metrics (#6661)
Browse files Browse the repository at this point in the history
Remove `near_<msg-type>_total` metrics.  Data in those metrics are
available in a `near_peer_message_received_by_type_total` metric with
a `type` label which is easier to deal with.

Similarly, `replace near_<msg-type>_bytes` metrics with a single new
`near_peer_message_received_by_type_bytes` metric using `type` label.

The `near_<msg-type>_dropped` metric is left as is for now but will be
dealt with in another change.
  • Loading branch information
mina86 committed Apr 21, 2022
1 parent f7561dd commit 14e6f39
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 45 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* Make RocksDB block_size configurable [#6631](https://github.com/near/nearcore/pull/6631)
* Increase default max_open_files RocksDB parameter from 512 to 10k [#6607](https://github.com/near/nearcore/pull/6607)
* Use kebab-case names for neard subcommands to make them consistent with flag names. snake_case names are still valid for existing subcommands but kebab-case will be used for new commands.
* Added `near_peer_message_received_by_type_bytes` metric [#6661](https://github.com/near/nearcore/pull/6661)
* Removed `near_<msg-type>_{total,bytes}` metrics in favour of `near_peer_message_received_by_type_{total,bytes}` metrics [#6661](https://github.com/near/nearcore/pull/6661)

## 1.25.0 [2022-03-16]

Expand Down
24 changes: 8 additions & 16 deletions chain/network/src/peer/peer_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::peer::utils;
use crate::private_actix::{
PeersRequest, RegisterPeer, RegisterPeerResponse, SendMessage, Unregister,
};
use crate::stats::metrics::{self, NetworkMetrics};
use crate::stats::metrics;
use crate::types::{
Handshake, HandshakeFailureReason, NetworkClientMessages, NetworkClientResponses,
NetworkRequests, NetworkResponses, PeerManagerMessageRequest, PeerMessage, PeerRequest,
Expand Down Expand Up @@ -96,8 +96,6 @@ pub(crate) struct PeerActor {
partial_edge_info: Option<PartialEdgeInfo>,
/// Last time an update of received message was sent to PeerManager
last_time_received_message_update: Instant,
/// Dynamic Prometheus metrics
network_metrics: Arc<NetworkMetrics>,
/// How many transactions we have received since the last block message
/// Note: Shared between multiple Peers.
txns_since_last_block: Arc<AtomicUsize>,
Expand Down Expand Up @@ -128,7 +126,6 @@ impl PeerActor {
client_addr: Recipient<NetworkClientMessages>,
view_client_addr: Recipient<NetworkViewClientMessages>,
partial_edge_info: Option<PartialEdgeInfo>,
network_metrics: Arc<NetworkMetrics>,
txns_since_last_block: Arc<AtomicUsize>,
peer_counter: Arc<AtomicUsize>,
throttle_controller: ThrottleController,
Expand All @@ -150,7 +147,6 @@ impl PeerActor {
chain_info: Default::default(),
partial_edge_info,
last_time_received_message_update: Clock::instant(),
network_metrics,
txns_since_last_block,
peer_counter,
routed_message_cache: LruCache::new(ROUTED_MESSAGE_CACHE_SIZE),
Expand Down Expand Up @@ -694,17 +690,13 @@ impl StreamHandler<Result<Vec<u8>, ReasonForBan>> for PeerActor {

self.on_receive_message();

self.network_metrics
.inc(NetworkMetrics::peer_message_total_rx(peer_msg.msg_variant()).as_ref());

self.network_metrics.inc_by(
NetworkMetrics::peer_message_bytes_rx(peer_msg.msg_variant()).as_ref(),
msg.len() as u64,
);

metrics::PEER_MESSAGE_RECEIVED_BY_TYPE_TOTAL
.with_label_values(&[peer_msg.msg_variant()])
.inc();
{
let labels = [peer_msg.msg_variant()];
metrics::PEER_MESSAGE_RECEIVED_BY_TYPE_TOTAL.with_label_values(&labels).inc();
metrics::PEER_MESSAGE_RECEIVED_BY_TYPE_BYTES
.with_label_values(&labels)
.inc_by(msg.len() as u64);
}

match (self.peer_status, peer_msg) {
(_, PeerMessage::HandshakeFailure(peer_info, reason)) => {
Expand Down
4 changes: 1 addition & 3 deletions chain/network/src/peer_manager/peer_manager_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,6 @@ impl PeerManagerActor {
}
};

let network_metrics = self.network_metrics.clone();
let txns_since_last_block = Arc::clone(&self.txns_since_last_block);

// Start every peer actor on separate thread.
Expand Down Expand Up @@ -914,7 +913,6 @@ impl PeerManagerActor {
client_addr,
view_client_addr,
partial_edge_info,
network_metrics,
txns_since_last_block,
peer_counter,
rate_limiter,
Expand Down Expand Up @@ -1144,7 +1142,7 @@ impl PeerManagerActor {
/// Check if the number of connections (excluding whitelisted ones) exceeds ideal_connections_hi.
/// If so, constructs a safe set of peers and selects one random peer outside of that set
/// and sends signal to stop connection to it gracefully.
///
///
/// Safe set contruction process:
/// 1. Add all whitelisted peers to the safe set.
/// 2. If the number of outbound connections is less or equal than minimum_outbound_connections,
Expand Down
39 changes: 13 additions & 26 deletions chain/network/src/stats/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ pub static PEER_DATA_RECEIVED_BYTES: Lazy<IntCounter> = Lazy::new(|| {
try_create_int_counter("near_peer_data_received_bytes", "Total data received from peers")
.unwrap()
});
pub static PEER_MESSAGE_RECEIVED_BY_TYPE_BYTES: Lazy<IntCounterVec> = Lazy::new(|| {
try_create_int_counter_vec(
"near_peer_message_received_by_type_bytes",
"Total data received from peers by message types",
&["type"],
)
.unwrap()
});
pub static PEER_MESSAGE_RECEIVED_TOTAL: Lazy<IntCounter> = Lazy::new(|| {
try_create_int_counter(
"near_peer_message_received_total",
Expand Down Expand Up @@ -126,19 +134,11 @@ impl NetworkMetrics {
.iter()
.filter(|&name| *name != "Routed")
.chain(RoutedMessageBody::VARIANTS.iter())
.flat_map(|name: &&str| {
[
NetworkMetrics::peer_message_total_rx,
NetworkMetrics::peer_message_bytes_rx,
NetworkMetrics::peer_message_dropped,
]
.into_iter()
.filter_map(|method| {
let counter_name = method(name);
try_create_int_counter(&counter_name, &counter_name)
.ok()
.map(|counter| (counter_name, counter))
})
.filter_map(|name: &&str| {
let counter_name = Self::peer_message_dropped(name);
try_create_int_counter(&counter_name, &counter_name)
.ok()
.map(|counter| (counter_name, counter))
})
.collect(),
broadcast_messages: do_create_int_counter_vec(
Expand All @@ -149,14 +149,6 @@ impl NetworkMetrics {
}
}

pub fn peer_message_total_rx(message_name: &str) -> String {
format!("near_{}_total", message_name.to_lowercase())
}

pub fn peer_message_bytes_rx(message_name: &str) -> String {
format!("near_{}_bytes", message_name.to_lowercase())
}

pub fn peer_message_dropped(message_name: &str) -> String {
format!("near_{}_dropped", message_name.to_lowercase())
}
Expand All @@ -167,11 +159,6 @@ impl NetworkMetrics {
}
}

pub fn inc_by(&self, message_name: &str, value: u64) {
if let Some(counter) = self.peer_messages.get(message_name) {
counter.inc_by(value);
}
}
pub fn inc_broadcast(&self, message_name: &str) {
self.broadcast_messages.with_label_values(&[message_name]).inc();
}
Expand Down

0 comments on commit 14e6f39

Please sign in to comment.