Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network: remove near_<msg-type>_{total,bytes} metrics #6661

Merged
merged 3 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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