mirror of
https://github.com/fluencelabs/kademlia-exporter
synced 2025-05-28 21:21:21 +00:00
src/exporter: Record whether node lookup failed or not
This commit is contained in:
parent
5f75e3b222
commit
a0a0f7e15f
@ -12,7 +12,7 @@ use log::info;
|
|||||||
use maxminddb::{geoip2, Reader};
|
use maxminddb::{geoip2, Reader};
|
||||||
use node_store::{Node, NodeStore};
|
use node_store::{Node, NodeStore};
|
||||||
use prometheus::{
|
use prometheus::{
|
||||||
exponential_buckets, CounterVec, HistogramOpts, HistogramTimer, HistogramVec, Opts, Registry,
|
exponential_buckets, CounterVec, HistogramOpts, HistogramVec, Opts, Registry,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
@ -20,7 +20,7 @@ use std::{
|
|||||||
net::IpAddr,
|
net::IpAddr,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
time::Duration,
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod client;
|
mod client;
|
||||||
@ -37,7 +37,7 @@ pub(crate) struct Exporter {
|
|||||||
///
|
///
|
||||||
/// When a lookup returns the entry is dropped and thus the duratation is
|
/// When a lookup returns the entry is dropped and thus the duratation is
|
||||||
/// observed through `<HistogramTimer as Drop>::drop`.
|
/// observed through `<HistogramTimer as Drop>::drop`.
|
||||||
in_flight_lookups: HashMap<PeerId, HistogramTimer>,
|
in_flight_lookups: HashMap<PeerId, Instant>,
|
||||||
tick: Delay,
|
tick: Delay,
|
||||||
metrics: Metrics,
|
metrics: Metrics,
|
||||||
/// An exporter periodically reconnects to each discovered node to probe
|
/// An exporter periodically reconnects to each discovered node to probe
|
||||||
@ -150,12 +150,18 @@ impl Exporter {
|
|||||||
.with_label_values(&[&name, "kad", "get_closest_peers"])
|
.with_label_values(&[&name, "kad", "get_closest_peers"])
|
||||||
.inc();
|
.inc();
|
||||||
|
|
||||||
|
// Record lookup latency.
|
||||||
|
let result_label = if res.is_ok() { "ok" } else { "error" };
|
||||||
let peer_id = PeerId::from_bytes(match res {
|
let peer_id = PeerId::from_bytes(match res {
|
||||||
Ok(GetClosestPeersOk { key, .. }) => key,
|
Ok(GetClosestPeersOk { key, .. }) => key,
|
||||||
Err(err) => err.into_key(),
|
Err(err) => err.into_key(),
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.in_flight_lookups.remove(&peer_id);
|
let duration = Instant::now() - self.in_flight_lookups.remove(&peer_id).unwrap();
|
||||||
|
self.metrics
|
||||||
|
.random_node_lookup_duration
|
||||||
|
.with_label_values(&[&name, result_label])
|
||||||
|
.observe(duration.as_secs_f64());
|
||||||
}
|
}
|
||||||
KademliaEvent::GetProvidersResult(_) => {
|
KademliaEvent::GetProvidersResult(_) => {
|
||||||
self.metrics
|
self.metrics
|
||||||
@ -296,15 +302,10 @@ impl Future for Exporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Trigger a random lookup for each client.
|
// Trigger a random lookup for each client.
|
||||||
for (name, client) in &mut this.clients {
|
for (_, client) in &mut this.clients {
|
||||||
let random_peer = PeerId::random();
|
let random_peer = PeerId::random();
|
||||||
let timer = this
|
|
||||||
.metrics
|
|
||||||
.random_node_lookup_duration
|
|
||||||
.with_label_values(&[&name])
|
|
||||||
.start_timer();
|
|
||||||
client.get_closest_peers(random_peer.clone());
|
client.get_closest_peers(random_peer.clone());
|
||||||
this.in_flight_lookups.insert(random_peer, timer);
|
this.in_flight_lookups.insert(random_peer, Instant::now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,10 +350,10 @@ impl Metrics {
|
|||||||
let random_node_lookup_duration = HistogramVec::new(
|
let random_node_lookup_duration = HistogramVec::new(
|
||||||
HistogramOpts::new(
|
HistogramOpts::new(
|
||||||
"random_node_lookup_duration",
|
"random_node_lookup_duration",
|
||||||
"Duration of random node lookups.",
|
"Duration of random node lookup.",
|
||||||
)
|
)
|
||||||
.buckets(exponential_buckets(0.1, 2.0, 10).unwrap()),
|
.buckets(exponential_buckets(0.1, 2.0, 10).unwrap()),
|
||||||
&["dht"],
|
&["dht", "result"],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
registry
|
registry
|
||||||
|
Loading…
x
Reference in New Issue
Block a user