mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-14 05:05:50 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -30,17 +30,18 @@
|
||||
//! [`OutChannels::push`] to put the sender within a [`OutChannels`].
|
||||
//! - Send events by calling [`OutChannels::send`]. Events are cloned for each sender in the
|
||||
//! collection.
|
||||
//!
|
||||
|
||||
use crate::Event;
|
||||
|
||||
use futures::{prelude::*, channel::mpsc, ready, stream::FusedStream};
|
||||
use futures::{channel::mpsc, prelude::*, ready, stream::FusedStream};
|
||||
use parking_lot::Mutex;
|
||||
use prometheus_endpoint::{register, CounterVec, GaugeVec, Opts, PrometheusError, Registry, U64};
|
||||
use std::{
|
||||
convert::TryFrom as _,
|
||||
fmt, pin::Pin, sync::Arc,
|
||||
task::{Context, Poll}
|
||||
fmt,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
/// Creates a new channel that can be associated to a [`OutChannels`].
|
||||
@@ -100,8 +101,10 @@ impl Stream for Receiver {
|
||||
let metrics = self.metrics.lock().clone();
|
||||
match metrics.as_ref().map(|m| m.as_ref()) {
|
||||
Some(Some(metrics)) => metrics.event_out(&ev, self.name),
|
||||
Some(None) => (), // no registry
|
||||
None => log::warn!("Inconsistency in out_events: event happened before sender associated"),
|
||||
Some(None) => (), // no registry
|
||||
None => log::warn!(
|
||||
"Inconsistency in out_events: event happened before sender associated"
|
||||
),
|
||||
}
|
||||
Poll::Ready(Some(ev))
|
||||
} else {
|
||||
@@ -136,16 +139,10 @@ pub struct OutChannels {
|
||||
impl OutChannels {
|
||||
/// Creates a new empty collection of senders.
|
||||
pub fn new(registry: Option<&Registry>) -> Result<Self, PrometheusError> {
|
||||
let metrics = if let Some(registry) = registry {
|
||||
Some(Metrics::register(registry)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let metrics =
|
||||
if let Some(registry) = registry { Some(Metrics::register(registry)?) } else { None };
|
||||
|
||||
Ok(OutChannels {
|
||||
event_streams: Vec::new(),
|
||||
metrics: Arc::new(metrics),
|
||||
})
|
||||
Ok(OutChannels { event_streams: Vec::new(), metrics: Arc::new(metrics) })
|
||||
}
|
||||
|
||||
/// Adds a new [`Sender`] to the collection.
|
||||
@@ -164,9 +161,8 @@ impl OutChannels {
|
||||
|
||||
/// Sends an event.
|
||||
pub fn send(&mut self, event: Event) {
|
||||
self.event_streams.retain(|sender| {
|
||||
sender.inner.unbounded_send(event.clone()).is_ok()
|
||||
});
|
||||
self.event_streams
|
||||
.retain(|sender| sender.inner.unbounded_send(event.clone()).is_ok());
|
||||
|
||||
if let Some(metrics) = &*self.metrics {
|
||||
for ev in &self.event_streams {
|
||||
@@ -223,20 +219,18 @@ impl Metrics {
|
||||
fn event_in(&self, event: &Event, num: u64, name: &str) {
|
||||
match event {
|
||||
Event::Dht(_) => {
|
||||
self.events_total
|
||||
.with_label_values(&["dht", "sent", name])
|
||||
.inc_by(num);
|
||||
}
|
||||
self.events_total.with_label_values(&["dht", "sent", name]).inc_by(num);
|
||||
},
|
||||
Event::SyncConnected { .. } => {
|
||||
self.events_total
|
||||
.with_label_values(&["sync-connected", "sent", name])
|
||||
.inc_by(num);
|
||||
}
|
||||
},
|
||||
Event::SyncDisconnected { .. } => {
|
||||
self.events_total
|
||||
.with_label_values(&["sync-disconnected", "sent", name])
|
||||
.inc_by(num);
|
||||
}
|
||||
},
|
||||
Event::NotificationStreamOpened { protocol, .. } => {
|
||||
self.events_total
|
||||
.with_label_values(&[&format!("notif-open-{:?}", protocol), "sent", name])
|
||||
@@ -247,36 +241,31 @@ impl Metrics {
|
||||
.with_label_values(&[&format!("notif-closed-{:?}", protocol), "sent", name])
|
||||
.inc_by(num);
|
||||
},
|
||||
Event::NotificationsReceived { messages, .. } => {
|
||||
Event::NotificationsReceived { messages, .. } =>
|
||||
for (protocol, message) in messages {
|
||||
self.events_total
|
||||
.with_label_values(&[&format!("notif-{:?}", protocol), "sent", name])
|
||||
.inc_by(num);
|
||||
self.notifications_sizes
|
||||
.with_label_values(&[protocol, "sent", name])
|
||||
.inc_by(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::MAX)));
|
||||
}
|
||||
},
|
||||
self.notifications_sizes.with_label_values(&[protocol, "sent", name]).inc_by(
|
||||
num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::MAX)),
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn event_out(&self, event: &Event, name: &str) {
|
||||
match event {
|
||||
Event::Dht(_) => {
|
||||
self.events_total
|
||||
.with_label_values(&["dht", "received", name])
|
||||
.inc();
|
||||
}
|
||||
self.events_total.with_label_values(&["dht", "received", name]).inc();
|
||||
},
|
||||
Event::SyncConnected { .. } => {
|
||||
self.events_total
|
||||
.with_label_values(&["sync-connected", "received", name])
|
||||
.inc();
|
||||
}
|
||||
self.events_total.with_label_values(&["sync-connected", "received", name]).inc();
|
||||
},
|
||||
Event::SyncDisconnected { .. } => {
|
||||
self.events_total
|
||||
.with_label_values(&["sync-disconnected", "received", name])
|
||||
.inc();
|
||||
}
|
||||
},
|
||||
Event::NotificationStreamOpened { protocol, .. } => {
|
||||
self.events_total
|
||||
.with_label_values(&[&format!("notif-open-{:?}", protocol), "received", name])
|
||||
@@ -287,7 +276,7 @@ impl Metrics {
|
||||
.with_label_values(&[&format!("notif-closed-{:?}", protocol), "received", name])
|
||||
.inc();
|
||||
},
|
||||
Event::NotificationsReceived { messages, .. } => {
|
||||
Event::NotificationsReceived { messages, .. } =>
|
||||
for (protocol, message) in messages {
|
||||
self.events_total
|
||||
.with_label_values(&[&format!("notif-{:?}", protocol), "received", name])
|
||||
@@ -295,8 +284,7 @@ impl Metrics {
|
||||
self.notifications_sizes
|
||||
.with_label_values(&[&protocol, "received", name])
|
||||
.inc_by(u64::try_from(message.len()).unwrap_or(u64::MAX));
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user