mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-22 14:21:33 +00:00
chore(metrics): Upgrade to prometheus-client v0.19.0 (#3207)
This commit is contained in:
@ -1,11 +1,13 @@
|
|||||||
# 0.12.0 [unreleased]
|
# 0.12.0 [unreleased]
|
||||||
|
|
||||||
- Update to `libp2p-core` `v0.39.0`.
|
- Update to `prometheus-client` `v0.19.0`. See [PR 3207].
|
||||||
|
|
||||||
- Add `connections_establishment_duration` metric. See [PR 3134].
|
- Add `connections_establishment_duration` metric. See [PR 3134].
|
||||||
|
|
||||||
- Bump MSRV to 1.65.0.
|
- Bump MSRV to 1.65.0.
|
||||||
|
|
||||||
|
- Update to `libp2p-core` `v0.39.0`.
|
||||||
|
|
||||||
- Update to `libp2p-dcutr` `v0.9.0`.
|
- Update to `libp2p-dcutr` `v0.9.0`.
|
||||||
|
|
||||||
- Update to `libp2p-ping` `v0.42.0`.
|
- Update to `libp2p-ping` `v0.42.0`.
|
||||||
@ -19,6 +21,7 @@
|
|||||||
- Update to `libp2p-swarm` `v0.42.0`.
|
- Update to `libp2p-swarm` `v0.42.0`.
|
||||||
|
|
||||||
[PR 3134]: https://github.com/libp2p/rust-libp2p/pull/3134/
|
[PR 3134]: https://github.com/libp2p/rust-libp2p/pull/3134/
|
||||||
|
[PR 3207]: https://github.com/libp2p/rust-libp2p/pull/3207/
|
||||||
|
|
||||||
# 0.11.0
|
# 0.11.0
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ libp2p-kad = { version = "0.43.0", path = "../../protocols/kad", optional = true
|
|||||||
libp2p-ping = { version = "0.42.0", path = "../../protocols/ping", optional = true }
|
libp2p-ping = { version = "0.42.0", path = "../../protocols/ping", optional = true }
|
||||||
libp2p-relay = { version = "0.15.0", path = "../../protocols/relay", optional = true }
|
libp2p-relay = { version = "0.15.0", path = "../../protocols/relay", optional = true }
|
||||||
libp2p-swarm = { version = "0.42.0", path = "../../swarm" }
|
libp2p-swarm = { version = "0.42.0", path = "../../swarm" }
|
||||||
prometheus-client = "0.18.0"
|
prometheus-client = "0.19.0"
|
||||||
|
|
||||||
[target.'cfg(not(target_os = "unknown"))'.dependencies]
|
[target.'cfg(not(target_os = "unknown"))'.dependencies]
|
||||||
libp2p-gossipsub = { version = "0.44.0", path = "../../protocols/gossipsub", optional = true }
|
libp2p-gossipsub = { version = "0.44.0", path = "../../protocols/gossipsub", optional = true }
|
||||||
@ -52,4 +52,4 @@ rustc-args = ["--cfg", "docsrs"]
|
|||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "metrics"
|
name = "metrics"
|
||||||
required-features = ["ping"]
|
required-features = ["ping", "identify"]
|
||||||
|
@ -29,6 +29,8 @@ use std::pin::Pin;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
|
const METRICS_CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;version=1.0.0";
|
||||||
|
|
||||||
pub async fn metrics_server(registry: Registry) -> Result<(), std::io::Error> {
|
pub async fn metrics_server(registry: Registry) -> Result<(), std::io::Error> {
|
||||||
// Serve on localhost.
|
// Serve on localhost.
|
||||||
let addr = ([127, 0, 0, 1], 0).into();
|
let addr = ([127, 0, 0, 1], 0).into();
|
||||||
@ -55,27 +57,31 @@ impl MetricService {
|
|||||||
fn get_reg(&mut self) -> SharedRegistry {
|
fn get_reg(&mut self) -> SharedRegistry {
|
||||||
Arc::clone(&self.reg)
|
Arc::clone(&self.reg)
|
||||||
}
|
}
|
||||||
fn respond_with_metrics(&mut self) -> Response<Body> {
|
fn respond_with_metrics(&mut self) -> Response<String> {
|
||||||
let mut encoded: Vec<u8> = Vec::new();
|
let mut response: Response<String> = Response::default();
|
||||||
|
|
||||||
|
response.headers_mut().insert(
|
||||||
|
hyper::header::CONTENT_TYPE,
|
||||||
|
METRICS_CONTENT_TYPE.try_into().unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
let reg = self.get_reg();
|
let reg = self.get_reg();
|
||||||
encode(&mut encoded, ®.lock().unwrap()).unwrap();
|
encode(&mut response.body_mut(), ®.lock().unwrap()).unwrap();
|
||||||
let metrics_content_type = "application/openmetrics-text;charset=utf-8;version=1.0.0";
|
|
||||||
Response::builder()
|
*response.status_mut() = StatusCode::OK;
|
||||||
.status(StatusCode::OK)
|
|
||||||
.header(hyper::header::CONTENT_TYPE, metrics_content_type)
|
response
|
||||||
.body(Body::from(encoded))
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
fn respond_with_404_not_found(&mut self) -> Response<Body> {
|
fn respond_with_404_not_found(&mut self) -> Response<String> {
|
||||||
Response::builder()
|
Response::builder()
|
||||||
.status(StatusCode::NOT_FOUND)
|
.status(StatusCode::NOT_FOUND)
|
||||||
.body(Body::from("Not found try localhost:[port]/metrics"))
|
.body("Not found try localhost:[port]/metrics".to_string())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service<Request<Body>> for MetricService {
|
impl Service<Request<Body>> for MetricService {
|
||||||
type Response = Response<Body>;
|
type Response = Response<String>;
|
||||||
type Error = hyper::Error;
|
type Error = hyper::Error;
|
||||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use prometheus_client::encoding::text::Encode;
|
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
|
||||||
use prometheus_client::metrics::counter::Counter;
|
use prometheus_client::metrics::counter::Counter;
|
||||||
use prometheus_client::metrics::family::Family;
|
use prometheus_client::metrics::family::Family;
|
||||||
use prometheus_client::registry::Registry;
|
use prometheus_client::registry::Registry;
|
||||||
@ -35,19 +35,19 @@ impl Metrics {
|
|||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"events",
|
"events",
|
||||||
"Events emitted by the relay NetworkBehaviour",
|
"Events emitted by the relay NetworkBehaviour",
|
||||||
Box::new(events.clone()),
|
events.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Self { events }
|
Self { events }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, Encode)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, EncodeLabelSet)]
|
||||||
struct EventLabels {
|
struct EventLabels {
|
||||||
event: EventType,
|
event: EventType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, Encode)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, EncodeLabelValue)]
|
||||||
enum EventType {
|
enum EventType {
|
||||||
InitiateDirectConnectionUpgrade,
|
InitiateDirectConnectionUpgrade,
|
||||||
RemoteInitiatedDirectConnectionUpgrade,
|
RemoteInitiatedDirectConnectionUpgrade,
|
||||||
|
@ -30,11 +30,7 @@ impl Metrics {
|
|||||||
let sub_registry = registry.sub_registry_with_prefix("gossipsub");
|
let sub_registry = registry.sub_registry_with_prefix("gossipsub");
|
||||||
|
|
||||||
let messages = Counter::default();
|
let messages = Counter::default();
|
||||||
sub_registry.register(
|
sub_registry.register("messages", "Number of messages received", messages.clone());
|
||||||
"messages",
|
|
||||||
"Number of messages received",
|
|
||||||
Box::new(messages.clone()),
|
|
||||||
);
|
|
||||||
|
|
||||||
Self { messages }
|
Self { messages }
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
use crate::protocol_stack;
|
use crate::protocol_stack;
|
||||||
use libp2p_core::PeerId;
|
use libp2p_core::PeerId;
|
||||||
use prometheus_client::encoding::text::{Encode, EncodeMetric, Encoder};
|
use prometheus_client::encoding::{EncodeLabelSet, EncodeMetric, MetricEncoder};
|
||||||
use prometheus_client::metrics::counter::Counter;
|
use prometheus_client::metrics::counter::Counter;
|
||||||
use prometheus_client::metrics::family::Family;
|
use prometheus_client::metrics::family::Family;
|
||||||
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
|
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
|
||||||
@ -51,14 +51,14 @@ impl Metrics {
|
|||||||
"Number of connected nodes supporting a specific protocol, with \
|
"Number of connected nodes supporting a specific protocol, with \
|
||||||
\"unrecognized\" for each peer supporting one or more unrecognized \
|
\"unrecognized\" for each peer supporting one or more unrecognized \
|
||||||
protocols",
|
protocols",
|
||||||
Box::new(protocols.clone()),
|
protocols.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let error = Counter::default();
|
let error = Counter::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"errors",
|
"errors",
|
||||||
"Number of errors while attempting to identify the remote",
|
"Number of errors while attempting to identify the remote",
|
||||||
Box::new(error.clone()),
|
error.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let pushed = Counter::default();
|
let pushed = Counter::default();
|
||||||
@ -66,7 +66,7 @@ impl Metrics {
|
|||||||
"pushed",
|
"pushed",
|
||||||
"Number of times identification information of the local node has \
|
"Number of times identification information of the local node has \
|
||||||
been actively pushed to a peer.",
|
been actively pushed to a peer.",
|
||||||
Box::new(pushed.clone()),
|
pushed.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let received = Counter::default();
|
let received = Counter::default();
|
||||||
@ -74,7 +74,7 @@ impl Metrics {
|
|||||||
"received",
|
"received",
|
||||||
"Number of times identification information has been received from \
|
"Number of times identification information has been received from \
|
||||||
a peer",
|
a peer",
|
||||||
Box::new(received.clone()),
|
received.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let received_info_listen_addrs =
|
let received_info_listen_addrs =
|
||||||
@ -83,7 +83,7 @@ impl Metrics {
|
|||||||
"received_info_listen_addrs",
|
"received_info_listen_addrs",
|
||||||
"Number of listen addresses for remote peer received in \
|
"Number of listen addresses for remote peer received in \
|
||||||
identification information",
|
identification information",
|
||||||
Box::new(received_info_listen_addrs.clone()),
|
received_info_listen_addrs.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let received_info_protocols =
|
let received_info_protocols =
|
||||||
@ -92,7 +92,7 @@ impl Metrics {
|
|||||||
"received_info_protocols",
|
"received_info_protocols",
|
||||||
"Number of protocols supported by the remote peer received in \
|
"Number of protocols supported by the remote peer received in \
|
||||||
identification information",
|
identification information",
|
||||||
Box::new(received_info_protocols.clone()),
|
received_info_protocols.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let sent = Counter::default();
|
let sent = Counter::default();
|
||||||
@ -100,14 +100,14 @@ impl Metrics {
|
|||||||
"sent",
|
"sent",
|
||||||
"Number of times identification information of the local node has \
|
"Number of times identification information of the local node has \
|
||||||
been sent to a peer in response to an identification request",
|
been sent to a peer in response to an identification request",
|
||||||
Box::new(sent.clone()),
|
sent.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let listen_addresses = Family::default();
|
let listen_addresses = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"listen_addresses",
|
"listen_addresses",
|
||||||
"Number of listen addresses for remote peer per protocol stack",
|
"Number of listen addresses for remote peer per protocol stack",
|
||||||
Box::new(listen_addresses.clone()),
|
listen_addresses.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -208,12 +208,12 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct AddressLabels {
|
struct AddressLabels {
|
||||||
protocols: String,
|
protocols: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone, Debug)]
|
||||||
struct Protocols {
|
struct Protocols {
|
||||||
peers: Arc<Mutex<HashMap<PeerId, Vec<String>>>>,
|
peers: Arc<Mutex<HashMap<PeerId, Vec<String>>>>,
|
||||||
}
|
}
|
||||||
@ -235,14 +235,14 @@ impl Protocols {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EncodeMetric for Protocols {
|
impl EncodeMetric for Protocols {
|
||||||
fn encode(&self, mut encoder: Encoder) -> Result<(), std::io::Error> {
|
fn encode(&self, mut encoder: MetricEncoder) -> Result<(), std::fmt::Error> {
|
||||||
let count_by_protocol = self
|
let count_by_protocol = self
|
||||||
.peers
|
.peers
|
||||||
.lock()
|
.lock()
|
||||||
.expect("Lock not to be poisoned")
|
.expect("Lock not to be poisoned")
|
||||||
.iter()
|
.iter()
|
||||||
.fold(
|
.fold(
|
||||||
HashMap::<String, u64>::default(),
|
HashMap::<String, i64>::default(),
|
||||||
|mut acc, (_, protocols)| {
|
|mut acc, (_, protocols)| {
|
||||||
for protocol in protocols {
|
for protocol in protocols {
|
||||||
let count = acc.entry(protocol.to_string()).or_default();
|
let count = acc.entry(protocol.to_string()).or_default();
|
||||||
@ -254,11 +254,8 @@ impl EncodeMetric for Protocols {
|
|||||||
|
|
||||||
for (protocol, count) in count_by_protocol {
|
for (protocol, count) in count_by_protocol {
|
||||||
encoder
|
encoder
|
||||||
.with_label_set(&("protocol", protocol))
|
.encode_family(&[("protocol", protocol)])?
|
||||||
.no_suffix()?
|
.encode_gauge(&count)?;
|
||||||
.no_bucket()?
|
|
||||||
.encode_value(count)?
|
|
||||||
.no_exemplar()?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use prometheus_client::encoding::text::Encode;
|
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
|
||||||
use prometheus_client::metrics::counter::Counter;
|
use prometheus_client::metrics::counter::Counter;
|
||||||
use prometheus_client::metrics::family::Family;
|
use prometheus_client::metrics::family::Family;
|
||||||
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
|
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
|
||||||
@ -52,42 +52,42 @@ impl Metrics {
|
|||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"query_result_get_record_ok",
|
"query_result_get_record_ok",
|
||||||
"Number of records returned by a successful Kademlia get record query.",
|
"Number of records returned by a successful Kademlia get record query.",
|
||||||
Box::new(query_result_get_record_ok.clone()),
|
query_result_get_record_ok.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let query_result_get_record_error = Family::default();
|
let query_result_get_record_error = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"query_result_get_record_error",
|
"query_result_get_record_error",
|
||||||
"Number of failed Kademlia get record queries.",
|
"Number of failed Kademlia get record queries.",
|
||||||
Box::new(query_result_get_record_error.clone()),
|
query_result_get_record_error.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let query_result_get_closest_peers_ok = Histogram::new(exponential_buckets(1.0, 2.0, 10));
|
let query_result_get_closest_peers_ok = Histogram::new(exponential_buckets(1.0, 2.0, 10));
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"query_result_get_closest_peers_ok",
|
"query_result_get_closest_peers_ok",
|
||||||
"Number of closest peers returned by a successful Kademlia get closest peers query.",
|
"Number of closest peers returned by a successful Kademlia get closest peers query.",
|
||||||
Box::new(query_result_get_closest_peers_ok.clone()),
|
query_result_get_closest_peers_ok.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let query_result_get_closest_peers_error = Family::default();
|
let query_result_get_closest_peers_error = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"query_result_get_closest_peers_error",
|
"query_result_get_closest_peers_error",
|
||||||
"Number of failed Kademlia get closest peers queries.",
|
"Number of failed Kademlia get closest peers queries.",
|
||||||
Box::new(query_result_get_closest_peers_error.clone()),
|
query_result_get_closest_peers_error.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let query_result_get_providers_ok = Histogram::new(exponential_buckets(1.0, 2.0, 10));
|
let query_result_get_providers_ok = Histogram::new(exponential_buckets(1.0, 2.0, 10));
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"query_result_get_providers_ok",
|
"query_result_get_providers_ok",
|
||||||
"Number of providers returned by a successful Kademlia get providers query.",
|
"Number of providers returned by a successful Kademlia get providers query.",
|
||||||
Box::new(query_result_get_providers_ok.clone()),
|
query_result_get_providers_ok.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let query_result_get_providers_error = Family::default();
|
let query_result_get_providers_error = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"query_result_get_providers_error",
|
"query_result_get_providers_error",
|
||||||
"Number of failed Kademlia get providers queries.",
|
"Number of failed Kademlia get providers queries.",
|
||||||
Box::new(query_result_get_providers_error.clone()),
|
query_result_get_providers_error.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let query_result_num_requests: Family<_, _> =
|
let query_result_num_requests: Family<_, _> =
|
||||||
@ -95,7 +95,7 @@ impl Metrics {
|
|||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"query_result_num_requests",
|
"query_result_num_requests",
|
||||||
"Number of requests started for a Kademlia query.",
|
"Number of requests started for a Kademlia query.",
|
||||||
Box::new(query_result_num_requests.clone()),
|
query_result_num_requests.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let query_result_num_success: Family<_, _> =
|
let query_result_num_success: Family<_, _> =
|
||||||
@ -103,7 +103,7 @@ impl Metrics {
|
|||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"query_result_num_success",
|
"query_result_num_success",
|
||||||
"Number of successful requests of a Kademlia query.",
|
"Number of successful requests of a Kademlia query.",
|
||||||
Box::new(query_result_num_success.clone()),
|
query_result_num_success.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let query_result_num_failure: Family<_, _> =
|
let query_result_num_failure: Family<_, _> =
|
||||||
@ -111,7 +111,7 @@ impl Metrics {
|
|||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"query_result_num_failure",
|
"query_result_num_failure",
|
||||||
"Number of failed requests of a Kademlia query.",
|
"Number of failed requests of a Kademlia query.",
|
||||||
Box::new(query_result_num_failure.clone()),
|
query_result_num_failure.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let query_result_duration: Family<_, _> =
|
let query_result_duration: Family<_, _> =
|
||||||
@ -120,21 +120,21 @@ impl Metrics {
|
|||||||
"query_result_duration",
|
"query_result_duration",
|
||||||
"Duration of a Kademlia query.",
|
"Duration of a Kademlia query.",
|
||||||
Unit::Seconds,
|
Unit::Seconds,
|
||||||
Box::new(query_result_duration.clone()),
|
query_result_duration.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let routing_updated = Family::default();
|
let routing_updated = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"routing_updated",
|
"routing_updated",
|
||||||
"Number of peers added, updated or evicted to, in or from a specific kbucket in the routing table",
|
"Number of peers added, updated or evicted to, in or from a specific kbucket in the routing table",
|
||||||
Box::new(routing_updated.clone()),
|
routing_updated.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let inbound_requests = Family::default();
|
let inbound_requests = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"inbound_requests",
|
"inbound_requests",
|
||||||
"Number of inbound requests",
|
"Number of inbound requests",
|
||||||
Box::new(inbound_requests.clone()),
|
inbound_requests.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -258,12 +258,12 @@ impl super::Recorder<libp2p_kad::KademliaEvent> for Metrics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct QueryResult {
|
struct QueryResult {
|
||||||
r#type: QueryType,
|
r#type: QueryType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum QueryType {
|
enum QueryType {
|
||||||
Bootstrap,
|
Bootstrap,
|
||||||
GetClosestPeers,
|
GetClosestPeers,
|
||||||
@ -306,12 +306,12 @@ impl From<&libp2p_kad::QueryResult> for QueryResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct GetRecordResult {
|
struct GetRecordResult {
|
||||||
error: GetRecordError,
|
error: GetRecordError,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum GetRecordError {
|
enum GetRecordError {
|
||||||
NotFound,
|
NotFound,
|
||||||
QuorumFailed,
|
QuorumFailed,
|
||||||
@ -334,12 +334,12 @@ impl From<&libp2p_kad::GetRecordError> for GetRecordResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct GetClosestPeersResult {
|
struct GetClosestPeersResult {
|
||||||
error: GetClosestPeersError,
|
error: GetClosestPeersError,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum GetClosestPeersError {
|
enum GetClosestPeersError {
|
||||||
Timeout,
|
Timeout,
|
||||||
}
|
}
|
||||||
@ -354,12 +354,12 @@ impl From<&libp2p_kad::GetClosestPeersError> for GetClosestPeersResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct GetProvidersResult {
|
struct GetProvidersResult {
|
||||||
error: GetProvidersError,
|
error: GetProvidersError,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum GetProvidersError {
|
enum GetProvidersError {
|
||||||
Timeout,
|
Timeout,
|
||||||
}
|
}
|
||||||
@ -374,20 +374,20 @@ impl From<&libp2p_kad::GetProvidersError> for GetProvidersResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct RoutingUpdated {
|
struct RoutingUpdated {
|
||||||
action: RoutingAction,
|
action: RoutingAction,
|
||||||
bucket: u32,
|
bucket: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum RoutingAction {
|
enum RoutingAction {
|
||||||
Added,
|
Added,
|
||||||
Updated,
|
Updated,
|
||||||
Evicted,
|
Evicted,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct InboundRequest {
|
struct InboundRequest {
|
||||||
request: Request,
|
request: Request,
|
||||||
}
|
}
|
||||||
@ -406,7 +406,7 @@ impl From<&libp2p_kad::InboundRequest> for InboundRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum Request {
|
enum Request {
|
||||||
FindNode,
|
FindNode,
|
||||||
GetProvider,
|
GetProvider,
|
||||||
|
@ -18,13 +18,13 @@
|
|||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use prometheus_client::encoding::text::Encode;
|
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
|
||||||
use prometheus_client::metrics::counter::Counter;
|
use prometheus_client::metrics::counter::Counter;
|
||||||
use prometheus_client::metrics::family::Family;
|
use prometheus_client::metrics::family::Family;
|
||||||
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
|
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
|
||||||
use prometheus_client::registry::{Registry, Unit};
|
use prometheus_client::registry::{Registry, Unit};
|
||||||
|
|
||||||
#[derive(Clone, Hash, PartialEq, Eq, Encode)]
|
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
|
||||||
struct FailureLabels {
|
struct FailureLabels {
|
||||||
reason: Failure,
|
reason: Failure,
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ impl From<&libp2p_ping::Failure> for FailureLabels {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Hash, PartialEq, Eq, Encode)]
|
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
|
||||||
enum Failure {
|
enum Failure {
|
||||||
Timeout,
|
Timeout,
|
||||||
Unsupported,
|
Unsupported,
|
||||||
@ -67,21 +67,21 @@ impl Metrics {
|
|||||||
"rtt",
|
"rtt",
|
||||||
"Round-trip time sending a 'ping' and receiving a 'pong'",
|
"Round-trip time sending a 'ping' and receiving a 'pong'",
|
||||||
Unit::Seconds,
|
Unit::Seconds,
|
||||||
Box::new(rtt.clone()),
|
rtt.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let failure = Family::default();
|
let failure = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"failure",
|
"failure",
|
||||||
"Failure while sending a 'ping' or receiving a 'pong'",
|
"Failure while sending a 'ping' or receiving a 'pong'",
|
||||||
Box::new(failure.clone()),
|
failure.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let pong_received = Counter::default();
|
let pong_received = Counter::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"pong_received",
|
"pong_received",
|
||||||
"Number of 'pong's received",
|
"Number of 'pong's received",
|
||||||
Box::new(pong_received.clone()),
|
pong_received.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use prometheus_client::encoding::text::Encode;
|
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
|
||||||
use prometheus_client::metrics::counter::Counter;
|
use prometheus_client::metrics::counter::Counter;
|
||||||
use prometheus_client::metrics::family::Family;
|
use prometheus_client::metrics::family::Family;
|
||||||
use prometheus_client::registry::Registry;
|
use prometheus_client::registry::Registry;
|
||||||
@ -35,19 +35,19 @@ impl Metrics {
|
|||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"events",
|
"events",
|
||||||
"Events emitted by the relay NetworkBehaviour",
|
"Events emitted by the relay NetworkBehaviour",
|
||||||
Box::new(events.clone()),
|
events.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Self { events }
|
Self { events }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, Encode)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, EncodeLabelSet)]
|
||||||
struct EventLabels {
|
struct EventLabels {
|
||||||
event: EventType,
|
event: EventType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, Encode)]
|
#[derive(Debug, Clone, Hash, PartialEq, Eq, EncodeLabelValue)]
|
||||||
enum EventType {
|
enum EventType {
|
||||||
ReservationReqAccepted,
|
ReservationReqAccepted,
|
||||||
ReservationReqAcceptFailed,
|
ReservationReqAcceptFailed,
|
||||||
|
@ -19,12 +19,10 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
use crate::protocol_stack;
|
use crate::protocol_stack;
|
||||||
use prometheus_client::encoding::text::Encode;
|
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
|
||||||
use prometheus_client::metrics::{
|
use prometheus_client::metrics::counter::Counter;
|
||||||
counter::Counter,
|
use prometheus_client::metrics::family::Family;
|
||||||
family::Family,
|
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
|
||||||
histogram::{exponential_buckets, Histogram},
|
|
||||||
};
|
|
||||||
use prometheus_client::registry::Registry;
|
use prometheus_client::registry::Registry;
|
||||||
|
|
||||||
pub struct Metrics {
|
pub struct Metrics {
|
||||||
@ -54,77 +52,77 @@ impl Metrics {
|
|||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"connections_incoming",
|
"connections_incoming",
|
||||||
"Number of incoming connections per address stack",
|
"Number of incoming connections per address stack",
|
||||||
Box::new(connections_incoming.clone()),
|
connections_incoming.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let connections_incoming_error = Family::default();
|
let connections_incoming_error = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"connections_incoming_error",
|
"connections_incoming_error",
|
||||||
"Number of incoming connection errors",
|
"Number of incoming connection errors",
|
||||||
Box::new(connections_incoming_error.clone()),
|
connections_incoming_error.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let new_listen_addr = Family::default();
|
let new_listen_addr = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"new_listen_addr",
|
"new_listen_addr",
|
||||||
"Number of new listen addresses",
|
"Number of new listen addresses",
|
||||||
Box::new(new_listen_addr.clone()),
|
new_listen_addr.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expired_listen_addr = Family::default();
|
let expired_listen_addr = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"expired_listen_addr",
|
"expired_listen_addr",
|
||||||
"Number of expired listen addresses",
|
"Number of expired listen addresses",
|
||||||
Box::new(expired_listen_addr.clone()),
|
expired_listen_addr.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let listener_closed = Family::default();
|
let listener_closed = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"listener_closed",
|
"listener_closed",
|
||||||
"Number of listeners closed",
|
"Number of listeners closed",
|
||||||
Box::new(listener_closed.clone()),
|
listener_closed.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let listener_error = Counter::default();
|
let listener_error = Counter::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"listener_error",
|
"listener_error",
|
||||||
"Number of listener errors",
|
"Number of listener errors",
|
||||||
Box::new(listener_error.clone()),
|
listener_error.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let dial_attempt = Counter::default();
|
let dial_attempt = Counter::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"dial_attempt",
|
"dial_attempt",
|
||||||
"Number of dial attempts",
|
"Number of dial attempts",
|
||||||
Box::new(dial_attempt.clone()),
|
dial_attempt.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let outgoing_connection_error = Family::default();
|
let outgoing_connection_error = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"outgoing_connection_error",
|
"outgoing_connection_error",
|
||||||
"Number outgoing connection errors",
|
"Number outgoing connection errors",
|
||||||
Box::new(outgoing_connection_error.clone()),
|
outgoing_connection_error.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let connected_to_banned_peer = Family::default();
|
let connected_to_banned_peer = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"connected_to_banned_peer",
|
"connected_to_banned_peer",
|
||||||
"Number of connection attempts to banned peer",
|
"Number of connection attempts to banned peer",
|
||||||
Box::new(connected_to_banned_peer.clone()),
|
connected_to_banned_peer.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let connections_established = Family::default();
|
let connections_established = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"connections_established",
|
"connections_established",
|
||||||
"Number of connections established",
|
"Number of connections established",
|
||||||
Box::new(connections_established.clone()),
|
connections_established.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let connections_closed = Family::default();
|
let connections_closed = Family::default();
|
||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"connections_closed",
|
"connections_closed",
|
||||||
"Number of connections closed",
|
"Number of connections closed",
|
||||||
Box::new(connections_closed.clone()),
|
connections_closed.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let connections_establishment_duration = Family::new_with_constructor(
|
let connections_establishment_duration = Family::new_with_constructor(
|
||||||
@ -133,7 +131,7 @@ impl Metrics {
|
|||||||
sub_registry.register(
|
sub_registry.register(
|
||||||
"connections_establishment_duration",
|
"connections_establishment_duration",
|
||||||
"Time it took (locally) to establish connections",
|
"Time it took (locally) to establish connections",
|
||||||
Box::new(connections_establishment_duration.clone()),
|
connections_establishment_duration.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -293,7 +291,7 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct ConnectionEstablishedLabels {
|
struct ConnectionEstablishedLabels {
|
||||||
role: Role,
|
role: Role,
|
||||||
protocols: String,
|
protocols: String,
|
||||||
@ -301,18 +299,18 @@ struct ConnectionEstablishedLabels {
|
|||||||
|
|
||||||
type ConnectionEstablishmentDurationLabels = ConnectionEstablishedLabels;
|
type ConnectionEstablishmentDurationLabels = ConnectionEstablishedLabels;
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct ConnectionClosedLabels {
|
struct ConnectionClosedLabels {
|
||||||
role: Role,
|
role: Role,
|
||||||
protocols: String,
|
protocols: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct AddressLabels {
|
struct AddressLabels {
|
||||||
protocols: String,
|
protocols: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum Role {
|
enum Role {
|
||||||
Dialer,
|
Dialer,
|
||||||
Listener,
|
Listener,
|
||||||
@ -327,19 +325,19 @@ impl From<&libp2p_core::ConnectedPoint> for Role {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct OutgoingConnectionErrorLabels {
|
struct OutgoingConnectionErrorLabels {
|
||||||
peer: PeerStatus,
|
peer: PeerStatus,
|
||||||
error: OutgoingConnectionErrorError,
|
error: OutgoingConnectionErrorError,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq, Copy)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Copy, Debug)]
|
||||||
enum PeerStatus {
|
enum PeerStatus {
|
||||||
Known,
|
Known,
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum OutgoingConnectionErrorError {
|
enum OutgoingConnectionErrorError {
|
||||||
Banned,
|
Banned,
|
||||||
ConnectionLimit,
|
ConnectionLimit,
|
||||||
@ -354,13 +352,13 @@ enum OutgoingConnectionErrorError {
|
|||||||
TransportOther,
|
TransportOther,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
struct IncomingConnectionErrorLabels {
|
struct IncomingConnectionErrorLabels {
|
||||||
error: PendingInboundConnectionError,
|
error: PendingInboundConnectionError,
|
||||||
protocols: String,
|
protocols: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Encode, Hash, Clone, Eq, PartialEq)]
|
#[derive(EncodeLabelValue, Hash, Clone, Eq, PartialEq, Debug)]
|
||||||
enum PendingInboundConnectionError {
|
enum PendingInboundConnectionError {
|
||||||
WrongPeerId,
|
WrongPeerId,
|
||||||
TransportErrorMultiaddrNotSupported,
|
TransportErrorMultiaddrNotSupported,
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
# 0.44.0 [unreleased]
|
# 0.44.0 [unreleased]
|
||||||
|
|
||||||
|
- Update to `prometheus-client` `v0.19.0`. See [PR 3207].
|
||||||
|
|
||||||
- Update to `libp2p-core` `v0.39.0`.
|
- Update to `libp2p-core` `v0.39.0`.
|
||||||
|
|
||||||
- Update to `libp2p-swarm` `v0.42.0`.
|
- Update to `libp2p-swarm` `v0.42.0`.
|
||||||
|
|
||||||
|
[PR 3207]: https://github.com/libp2p/rust-libp2p/pull/3207/
|
||||||
|
|
||||||
# 0.43.0
|
# 0.43.0
|
||||||
|
|
||||||
- Update to `libp2p-core` `v0.38.0`.
|
- Update to `libp2p-core` `v0.38.0`.
|
||||||
|
@ -33,7 +33,7 @@ thiserror = "1.0"
|
|||||||
wasm-timer = "0.2.5"
|
wasm-timer = "0.2.5"
|
||||||
instant = "0.1.11"
|
instant = "0.1.11"
|
||||||
# Metrics dependencies
|
# Metrics dependencies
|
||||||
prometheus-client = "0.18.0"
|
prometheus-client = "0.19.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
async-std = "1.6.3"
|
async-std = "1.6.3"
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use prometheus_client::encoding::text::Encode;
|
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
|
||||||
use prometheus_client::metrics::counter::Counter;
|
use prometheus_client::metrics::counter::Counter;
|
||||||
use prometheus_client::metrics::family::{Family, MetricConstructor};
|
use prometheus_client::metrics::family::{Family, MetricConstructor};
|
||||||
use prometheus_client::metrics::gauge::Gauge;
|
use prometheus_client::metrics::gauge::Gauge;
|
||||||
@ -188,7 +188,7 @@ impl Metrics {
|
|||||||
macro_rules! register_family {
|
macro_rules! register_family {
|
||||||
($name:expr, $help:expr) => {{
|
($name:expr, $help:expr) => {{
|
||||||
let fam = Family::default();
|
let fam = Family::default();
|
||||||
registry.register($name, $help, Box::new(fam.clone()));
|
registry.register($name, $help, fam.clone());
|
||||||
fam
|
fam
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ impl Metrics {
|
|||||||
registry.register(
|
registry.register(
|
||||||
"score_per_mesh",
|
"score_per_mesh",
|
||||||
"Histogram of scores per mesh topic",
|
"Histogram of scores per mesh topic",
|
||||||
Box::new(score_per_mesh.clone()),
|
score_per_mesh.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let scoring_penalties = register_family!(
|
let scoring_penalties = register_family!(
|
||||||
@ -285,7 +285,7 @@ impl Metrics {
|
|||||||
registry.register(
|
registry.register(
|
||||||
"heartbeat_duration",
|
"heartbeat_duration",
|
||||||
"Histogram of observed heartbeat durations",
|
"Histogram of observed heartbeat durations",
|
||||||
Box::new(heartbeat_duration.clone()),
|
heartbeat_duration.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let topic_iwant_msgs = register_family!(
|
let topic_iwant_msgs = register_family!(
|
||||||
@ -297,7 +297,7 @@ impl Metrics {
|
|||||||
registry.register(
|
registry.register(
|
||||||
"memcache_misses",
|
"memcache_misses",
|
||||||
"Number of times a message is not found in the duplicate cache when validating",
|
"Number of times a message is not found in the duplicate cache when validating",
|
||||||
Box::new(metric.clone()),
|
metric.clone(),
|
||||||
);
|
);
|
||||||
metric
|
metric
|
||||||
};
|
};
|
||||||
@ -360,7 +360,7 @@ impl Metrics {
|
|||||||
if self.register_topic(topic).is_ok() {
|
if self.register_topic(topic).is_ok() {
|
||||||
self.topic_peers_count
|
self.topic_peers_count
|
||||||
.get_or_create(topic)
|
.get_or_create(topic)
|
||||||
.set(count as u64);
|
.set(count as i64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,7 +417,7 @@ impl Metrics {
|
|||||||
pub fn set_mesh_peers(&mut self, topic: &TopicHash, count: usize) {
|
pub fn set_mesh_peers(&mut self, topic: &TopicHash, count: usize) {
|
||||||
if self.register_topic(topic).is_ok() {
|
if self.register_topic(topic).is_ok() {
|
||||||
// Due to limits, this topic could have not been allowed, so we check.
|
// Due to limits, this topic could have not been allowed, so we check.
|
||||||
self.mesh_peer_counts.get_or_create(topic).set(count as u64);
|
self.mesh_peer_counts.get_or_create(topic).set(count as i64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,7 +525,7 @@ impl Metrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reasons why a peer was included in the mesh.
|
/// Reasons why a peer was included in the mesh.
|
||||||
#[derive(PartialEq, Eq, Hash, Encode, Clone)]
|
#[derive(PartialEq, Eq, Hash, EncodeLabelValue, Clone, Debug)]
|
||||||
pub enum Inclusion {
|
pub enum Inclusion {
|
||||||
/// Peer was a fanaout peer.
|
/// Peer was a fanaout peer.
|
||||||
Fanout,
|
Fanout,
|
||||||
@ -538,7 +538,7 @@ pub enum Inclusion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reasons why a peer was removed from the mesh.
|
/// Reasons why a peer was removed from the mesh.
|
||||||
#[derive(PartialEq, Eq, Hash, Encode, Clone)]
|
#[derive(PartialEq, Eq, Hash, EncodeLabelValue, Clone, Debug)]
|
||||||
pub enum Churn {
|
pub enum Churn {
|
||||||
/// Peer disconnected.
|
/// Peer disconnected.
|
||||||
Dc,
|
Dc,
|
||||||
@ -553,7 +553,7 @@ pub enum Churn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Kinds of reasons a peer's score has been penalized
|
/// Kinds of reasons a peer's score has been penalized
|
||||||
#[derive(PartialEq, Eq, Hash, Encode, Clone)]
|
#[derive(PartialEq, Eq, Hash, EncodeLabelValue, Clone, Debug)]
|
||||||
pub enum Penalty {
|
pub enum Penalty {
|
||||||
/// A peer grafted before waiting the back-off time.
|
/// A peer grafted before waiting the back-off time.
|
||||||
GraftBackoff,
|
GraftBackoff,
|
||||||
@ -566,27 +566,27 @@ pub enum Penalty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Label for the mesh inclusion event metrics.
|
/// Label for the mesh inclusion event metrics.
|
||||||
#[derive(PartialEq, Eq, Hash, Encode, Clone)]
|
#[derive(PartialEq, Eq, Hash, EncodeLabelSet, Clone, Debug)]
|
||||||
struct InclusionLabel {
|
struct InclusionLabel {
|
||||||
hash: String,
|
hash: String,
|
||||||
reason: Inclusion,
|
reason: Inclusion,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Label for the mesh churn event metrics.
|
/// Label for the mesh churn event metrics.
|
||||||
#[derive(PartialEq, Eq, Hash, Encode, Clone)]
|
#[derive(PartialEq, Eq, Hash, EncodeLabelSet, Clone, Debug)]
|
||||||
struct ChurnLabel {
|
struct ChurnLabel {
|
||||||
hash: String,
|
hash: String,
|
||||||
reason: Churn,
|
reason: Churn,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Label for the kinds of protocols peers can connect as.
|
/// Label for the kinds of protocols peers can connect as.
|
||||||
#[derive(PartialEq, Eq, Hash, Encode, Clone)]
|
#[derive(PartialEq, Eq, Hash, EncodeLabelSet, Clone, Debug)]
|
||||||
struct ProtocolLabel {
|
struct ProtocolLabel {
|
||||||
protocol: PeerKind,
|
protocol: PeerKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Label for the kinds of scoring penalties that can occur
|
/// Label for the kinds of scoring penalties that can occur
|
||||||
#[derive(PartialEq, Eq, Hash, Encode, Clone)]
|
#[derive(PartialEq, Eq, Hash, EncodeLabelSet, Clone, Debug)]
|
||||||
struct PenaltyLabel {
|
struct PenaltyLabel {
|
||||||
penalty: Penalty,
|
penalty: Penalty,
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
use crate::rpc_proto;
|
use crate::rpc_proto;
|
||||||
use base64::encode;
|
use base64::encode;
|
||||||
use prometheus_client::encoding::text::Encode;
|
use prometheus_client::encoding::EncodeLabelSet;
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@ -61,7 +61,7 @@ impl Hasher for Sha256Hash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Encode)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, EncodeLabelSet)]
|
||||||
pub struct TopicHash {
|
pub struct TopicHash {
|
||||||
/// The topic hash. Stored as a string to align with the protobuf API.
|
/// The topic hash. Stored as a string to align with the protobuf API.
|
||||||
hash: String,
|
hash: String,
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
use crate::rpc_proto;
|
use crate::rpc_proto;
|
||||||
use crate::TopicHash;
|
use crate::TopicHash;
|
||||||
use libp2p_core::{connection::ConnectionId, PeerId};
|
use libp2p_core::{connection::ConnectionId, PeerId};
|
||||||
use prometheus_client::encoding::text::Encode;
|
use prometheus_client::encoding::EncodeLabelValue;
|
||||||
use prost::Message;
|
use prost::Message;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
@ -95,7 +95,7 @@ pub struct PeerConnections {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Describes the types of peers that can exist in the gossipsub context.
|
/// Describes the types of peers that can exist in the gossipsub context.
|
||||||
#[derive(Debug, Clone, PartialEq, Hash, Encode, Eq)]
|
#[derive(Debug, Clone, PartialEq, Hash, EncodeLabelValue, Eq)]
|
||||||
pub enum PeerKind {
|
pub enum PeerKind {
|
||||||
/// A gossipsub 1.1 peer.
|
/// A gossipsub 1.1 peer.
|
||||||
Gossipsubv1_1,
|
Gossipsubv1_1,
|
||||||
|
Reference in New Issue
Block a user