Remove necessity to pass ConsensusEngineId when registering notifications protocol (#7549)

* Remove necessity to pass ConsensusEngineId when registering notifications protocol

* Line width

* Fix tests protocol name

* Other renames

* Doc update

* Change issue in TODO
This commit is contained in:
Pierre Krieger
2020-11-18 16:05:35 +01:00
committed by GitHub
parent 22a02d3e7a
commit 1eae9f5792
18 changed files with 228 additions and 284 deletions
@@ -33,7 +33,6 @@
//!
use crate::Event;
use super::maybe_utf8_bytes_to_string;
use futures::{prelude::*, channel::mpsc, ready, stream::FusedStream};
use parking_lot::Mutex;
@@ -228,23 +227,23 @@ impl Metrics {
.with_label_values(&["dht", "sent", name])
.inc_by(num);
}
Event::NotificationStreamOpened { engine_id, .. } => {
Event::NotificationStreamOpened { protocol, .. } => {
self.events_total
.with_label_values(&[&format!("notif-open-{:?}", engine_id), "sent", name])
.with_label_values(&[&format!("notif-open-{:?}", protocol), "sent", name])
.inc_by(num);
},
Event::NotificationStreamClosed { engine_id, .. } => {
Event::NotificationStreamClosed { protocol, .. } => {
self.events_total
.with_label_values(&[&format!("notif-closed-{:?}", engine_id), "sent", name])
.with_label_values(&[&format!("notif-closed-{:?}", protocol), "sent", name])
.inc_by(num);
},
Event::NotificationsReceived { messages, .. } => {
for (engine_id, message) in messages {
for (protocol, message) in messages {
self.events_total
.with_label_values(&[&format!("notif-{:?}", engine_id), "sent", name])
.with_label_values(&[&format!("notif-{:?}", protocol), "sent", name])
.inc_by(num);
self.notifications_sizes
.with_label_values(&[&maybe_utf8_bytes_to_string(engine_id), "sent", name])
.with_label_values(&[protocol, "sent", name])
.inc_by(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::max_value())));
}
},
@@ -258,23 +257,23 @@ impl Metrics {
.with_label_values(&["dht", "received", name])
.inc();
}
Event::NotificationStreamOpened { engine_id, .. } => {
Event::NotificationStreamOpened { protocol, .. } => {
self.events_total
.with_label_values(&[&format!("notif-open-{:?}", engine_id), "received", name])
.with_label_values(&[&format!("notif-open-{:?}", protocol), "received", name])
.inc();
},
Event::NotificationStreamClosed { engine_id, .. } => {
Event::NotificationStreamClosed { protocol, .. } => {
self.events_total
.with_label_values(&[&format!("notif-closed-{:?}", engine_id), "received", name])
.with_label_values(&[&format!("notif-closed-{:?}", protocol), "received", name])
.inc();
},
Event::NotificationsReceived { messages, .. } => {
for (engine_id, message) in messages {
for (protocol, message) in messages {
self.events_total
.with_label_values(&[&format!("notif-{:?}", engine_id), "received", name])
.with_label_values(&[&format!("notif-{:?}", protocol), "received", name])
.inc();
self.notifications_sizes
.with_label_values(&[&maybe_utf8_bytes_to_string(engine_id), "received", name])
.with_label_values(&[&protocol, "received", name])
.inc_by(u64::try_from(message.len()).unwrap_or(u64::max_value()));
}
},