-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A0-3060: Separate network metrics (#1371)
# Description Move the network metrics out of the global metrics, the last ones that are there and shouldn't be. ## Type of change # Checklist: Co-authored-by: timorl <[email protected]>
- Loading branch information
Showing
6 changed files
with
168 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::collections::HashMap; | ||
|
||
use substrate_prometheus_endpoint::{ | ||
exponential_buckets, prometheus::HistogramTimer, register, Histogram, HistogramOpts, Opts, | ||
PrometheusError, Registry, | ||
}; | ||
|
||
use crate::Protocol; | ||
|
||
fn protocol_name(protocol: Protocol) -> String { | ||
use Protocol::*; | ||
match protocol { | ||
Authentication => "authentication", | ||
BlockSync => "block_sync", | ||
} | ||
.to_string() | ||
} | ||
|
||
#[derive(Clone)] | ||
pub enum Metrics { | ||
Prometheus { | ||
send_times: HashMap<Protocol, Histogram>, | ||
}, | ||
Noop, | ||
} | ||
|
||
impl Metrics { | ||
pub fn new(registry: Option<Registry>) -> Result<Self, PrometheusError> { | ||
use Protocol::*; | ||
let registry = match registry { | ||
Some(registry) => registry, | ||
None => return Ok(Metrics::Noop), | ||
}; | ||
|
||
let mut send_times = HashMap::new(); | ||
for protocol in [Authentication, BlockSync] { | ||
send_times.insert( | ||
protocol, | ||
register( | ||
Histogram::with_opts(HistogramOpts { | ||
common_opts: Opts { | ||
namespace: "gossip_network".to_string(), | ||
subsystem: protocol_name(protocol), | ||
name: "send_duration".to_string(), | ||
help: "How long did it take for substrate to send a message." | ||
.to_string(), | ||
const_labels: Default::default(), | ||
variable_labels: Default::default(), | ||
}, | ||
buckets: exponential_buckets(0.001, 1.26, 30)?, | ||
})?, | ||
®istry, | ||
)?, | ||
); | ||
} | ||
Ok(Metrics::Prometheus { send_times }) | ||
} | ||
|
||
pub fn noop() -> Self { | ||
Metrics::Noop | ||
} | ||
|
||
pub fn start_sending_in(&self, protocol: Protocol) -> Option<HistogramTimer> { | ||
match self { | ||
Metrics::Prometheus { send_times } => send_times | ||
.get(&protocol) | ||
.map(|histogram| histogram.start_timer()), | ||
Metrics::Noop => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ use bytes::Bytes; | |
|
||
use crate::network::Data; | ||
|
||
mod metrics; | ||
#[cfg(test)] | ||
pub mod mock; | ||
mod service; | ||
|
Oops, something went wrong.