-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat: adding gauge to track total peers connected #80
base: master
Are you sure you want to change the base?
Conversation
@@ -29,7 +29,7 @@ thiserror = "1.0" | |||
hyper = { version = "0.14", features = ["stream"] } | |||
http = "0.2" | |||
tokio = { version = "1.0", features = ["macros", "rt"] } | |||
prometheus_exporter_base = { version = "1.2", features = ["hyper_server"] } | |||
prometheus_exporter_base = { git = "https://github.com/gausnes/prometheus_exporter_base", branch = "ContentType", features = ["hyper_server"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: update when MindFlavor/prometheus_exporter_base#25 is merged
@@ -194,7 +201,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | |||
info!("using options: {:?}", options); | |||
|
|||
let bind = matches.value_of("port").unwrap(); | |||
let bind = (&bind).parse::<u16>().expect("port must be a valid number"); | |||
let bind = bind.parse::<u16>().expect("port must be a valid number"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed a number of issues the compiler complained about
src/metrics.rs
Outdated
.render(); | ||
} | ||
|
||
pub fn latest_handshake(&mut self, instance: &PrometheusInstance<u128, MissingValue>, latest: u128) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm been thinking decoupling these contracts from PrometheusInstance
and instead define structs that contain labels. This would:
- Decrease the amount of code in
wireguard.rs
- Make it easier to adopt a different exporter
- After working with prom a bit it'd be nice for this to support statsd or dogstats for my usage, the wireguard integration code could be shared
# HELP wireguard_peers_total Total number of peers | ||
# TYPE wireguard_peers_total gauge | ||
wireguard_peers_total{interface=\"Pippo\"} 1 | ||
"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like a function could be created to generate the expected output, tried to hold off on what refactoring to make this concise
pub handshake_timeout_seconds: Option<u64> | ||
} | ||
|
||
pub struct EndpointMetrics<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added these classes in an attempt to not add clutter to existing method signatures
) | ||
} | ||
|
||
pub(self) fn populate_interface_metrics( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method containers the core of the previous render_with_names
implementation. Tried to create a distinction between the two classifications of metrics.
# HELP wireguard_peers_total Total number of peers | ||
# TYPE wireguard_peers_total gauge | ||
wireguard_peers_total{{interface=\"Pippo\",seen_recently=\"true\"}} 1 | ||
wireguard_peers_total{{interface=\"Pippo\",seen_recently=\"false\"}} 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on this label name? Feels like there a number of better options than what is initially defined:
connected
recent_handshake
timed_out
and/or have enumerated values e.g.
state
:TIMED_OUT
,RECENT_SEEN
@@ -155,6 +156,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | |||
.help("exports peer's remote ip and port as labels (if available)") | |||
.takes_value(false), | |||
) | |||
.arg( | |||
Arg::with_name("handshake_timeout_seconds") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
900
(15 minutes) was the value was the initial value I was going to configure, I can add that as the default if desired
08fc037
to
f023843
Compare
src/wireguard.rs
Outdated
let tokens: Vec<&str> = ip_and_subnet.split('/').collect(); | ||
debug!("WireGuard::render_with_names tokens == {:?}", tokens); | ||
let addr = tokens[0]; | ||
let subnet = tokens[1]; | ||
(addr, subnet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is the potential here for a panic if ip_and_subnet
is malformed (as in, splitting on /
yields only a single value). You may consider a .map_filter()
just to safegaurd against bad data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did at adding a bit of hardening to the data handling here
if let Some(pehm) = pehm { | ||
if let Some(ep_friendly_description) = pehm.get(&ep.public_key as &str) { | ||
if let Some(friendly_description) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing inherently wrong with this, but another way this could be approached is through a .map()
and .flatten()
chain such as:
if let Some(pehm) = pehm { | |
if let Some(ep_friendly_description) = pehm.get(&ep.public_key as &str) { | |
if let Some(friendly_description) = | |
pehm | |
.map(|p| p.get(&ep.public_key as &str)) | |
.flatten() | |
.map(|ep_friendly_desc| &ep_friendly_desc.friendly_description) | |
.flatten() | |
.map(|friendly_desc| | |
match friendly_description { ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally find the existing implementation is a bit more clear to what is happening, however I can appreciate the horizontal space savings on using .map
🤔
f023843
to
bb91c5b
Compare
bb91c5b
to
0dfc007
Compare
Adding a new gauge to monitor the number of peers connected to Wireguard. This metric provides low cardinality context to the number of peers connected to the process. Label cardinality becomes notable for DataDog pricing.