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