-
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-3058: Factor out clique metrics (#1362)
# Description First part of the metrics cleanup, for now in the clique network. ## Type of change # Checklist: --------- Co-authored-by: timorl <[email protected]>
- Loading branch information
Showing
15 changed files
with
188 additions
and
153 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,41 +1,99 @@ | ||
pub trait NetworkCliqueMetrics { | ||
fn set_incoming_connections(&self, present: u64); | ||
fn set_missing_incoming_connections(&self, missing: u64); | ||
fn set_outgoing_connections(&self, present: u64); | ||
fn set_missing_outgoing_connections(&self, missing: u64); | ||
use substrate_prometheus_endpoint::{register, Gauge, PrometheusError, Registry, U64}; | ||
|
||
#[derive(Clone)] | ||
pub enum Metrics { | ||
Prometheus { | ||
incoming_connections: Gauge<U64>, | ||
missing_incoming_connections: Gauge<U64>, | ||
outgoing_connections: Gauge<U64>, | ||
missing_outgoing_connections: Gauge<U64>, | ||
}, | ||
Noop, | ||
} | ||
|
||
impl<M: NetworkCliqueMetrics> NetworkCliqueMetrics for Option<M> { | ||
fn set_incoming_connections(&self, present: u64) { | ||
if let Some(m) = self { | ||
m.set_incoming_connections(present) | ||
} | ||
} | ||
pub enum Event { | ||
NewOutgoing, | ||
NewIncoming, | ||
DelOutgoing, | ||
DelIncoming, | ||
ConnectedOutgoing, | ||
ConnectedIncoming, | ||
DisconnectedOutgoing, | ||
DisconnectedIncoming, | ||
} | ||
|
||
fn set_missing_incoming_connections(&self, missing: u64) { | ||
if let Some(m) = self { | ||
m.set_missing_incoming_connections(missing) | ||
impl Metrics { | ||
pub fn new(registry: Option<Registry>) -> Result<Self, PrometheusError> { | ||
match registry { | ||
Some(registry) => Ok(Metrics::Prometheus { | ||
incoming_connections: register( | ||
Gauge::new( | ||
"clique_network_incoming_connections", | ||
"present incoming connections", | ||
)?, | ||
®istry, | ||
)?, | ||
missing_incoming_connections: register( | ||
Gauge::new( | ||
"clique_network_missing_incoming_connections", | ||
"difference between expected and present incoming connections", | ||
)?, | ||
®istry, | ||
)?, | ||
outgoing_connections: register( | ||
Gauge::new( | ||
"clique_network_outgoing_connections", | ||
"present outgoing connections", | ||
)?, | ||
®istry, | ||
)?, | ||
missing_outgoing_connections: register( | ||
Gauge::new( | ||
"clique_network_missing_outgoing_connections", | ||
"difference between expected and present outgoing connections", | ||
)?, | ||
®istry, | ||
)?, | ||
}), | ||
None => Ok(Metrics::Noop), | ||
} | ||
} | ||
|
||
fn set_outgoing_connections(&self, present: u64) { | ||
if let Some(m) = self { | ||
m.set_outgoing_connections(present) | ||
} | ||
pub fn noop() -> Self { | ||
Metrics::Noop | ||
} | ||
|
||
fn set_missing_outgoing_connections(&self, missing: u64) { | ||
if let Some(m) = self { | ||
m.set_missing_outgoing_connections(missing) | ||
pub fn report_event(&self, event: Event) { | ||
use Event::*; | ||
if let Metrics::Prometheus { | ||
incoming_connections, | ||
outgoing_connections, | ||
missing_incoming_connections, | ||
missing_outgoing_connections, | ||
} = self | ||
{ | ||
match event { | ||
NewIncoming => missing_incoming_connections.inc(), | ||
NewOutgoing => missing_outgoing_connections.inc(), | ||
DelIncoming => missing_incoming_connections.dec(), | ||
DelOutgoing => missing_outgoing_connections.dec(), | ||
ConnectedIncoming => { | ||
incoming_connections.inc(); | ||
missing_incoming_connections.dec(); | ||
} | ||
ConnectedOutgoing => { | ||
outgoing_connections.inc(); | ||
missing_outgoing_connections.dec(); | ||
} | ||
DisconnectedIncoming => { | ||
incoming_connections.dec(); | ||
missing_incoming_connections.inc(); | ||
} | ||
DisconnectedOutgoing => { | ||
outgoing_connections.dec(); | ||
missing_outgoing_connections.inc(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub struct NoopMetrics; | ||
|
||
impl NetworkCliqueMetrics for NoopMetrics { | ||
fn set_incoming_connections(&self, _: u64) {} | ||
fn set_missing_incoming_connections(&self, _: u64) {} | ||
fn set_outgoing_connections(&self, _: u64) {} | ||
fn set_missing_outgoing_connections(&self, _: u64) {} | ||
} |
Oops, something went wrong.