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:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+33 -22
View File
@@ -15,33 +15,34 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use futures_util::{FutureExt, future::Future};
use futures_util::{future::Future, FutureExt};
pub use prometheus::{
self,
Registry, Error as PrometheusError, Opts,
Histogram, HistogramOpts, HistogramVec,
exponential_buckets,
core::{
GenericGauge as Gauge, GenericCounter as Counter,
GenericGaugeVec as GaugeVec, GenericCounterVec as CounterVec,
AtomicF64 as F64, AtomicI64 as I64, AtomicU64 as U64,
}
AtomicF64 as F64, AtomicI64 as I64, AtomicU64 as U64, GenericCounter as Counter,
GenericCounterVec as CounterVec, GenericGauge as Gauge, GenericGaugeVec as GaugeVec,
},
exponential_buckets, Error as PrometheusError, Histogram, HistogramOpts, HistogramVec, Opts,
Registry,
};
use prometheus::{Encoder, TextEncoder, core::Collector};
use prometheus::{core::Collector, Encoder, TextEncoder};
use std::net::SocketAddr;
#[cfg(not(target_os = "unknown"))]
mod networking;
mod sourced;
pub use sourced::{SourcedCounter, SourcedGauge, MetricSource, SourcedMetric};
pub use sourced::{MetricSource, SourcedCounter, SourcedGauge, SourcedMetric};
#[cfg(target_os = "unknown")]
pub use unknown_os::init_prometheus;
#[cfg(not(target_os = "unknown"))]
pub use known_os::init_prometheus;
#[cfg(target_os = "unknown")]
pub use unknown_os::init_prometheus;
pub fn register<T: Clone + Collector + 'static>(metric: T, registry: &Registry) -> Result<T, PrometheusError> {
pub fn register<T: Clone + Collector + 'static>(
metric: T,
registry: &Registry,
) -> Result<T, PrometheusError> {
registry.register(Box::new(metric.clone()))?;
Ok(metric)
}
@@ -61,8 +62,11 @@ mod unknown_os {
#[cfg(not(target_os = "unknown"))]
mod known_os {
use super::*;
use hyper::http::StatusCode;
use hyper::{Server, Body, Request, Response, service::{service_fn, make_service_fn}};
use hyper::{
http::StatusCode,
service::{make_service_fn, service_fn},
Body, Request, Response, Server,
};
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
@@ -73,7 +77,7 @@ mod known_os {
/// i/o error.
Io(std::io::Error),
#[display(fmt = "Prometheus port {} already in use.", _0)]
PortInUse(SocketAddr)
PortInUse(SocketAddr),
}
impl std::error::Error for Error {
@@ -82,28 +86,32 @@ mod known_os {
Error::Hyper(error) => Some(error),
Error::Http(error) => Some(error),
Error::Io(error) => Some(error),
Error::PortInUse(_) => None
Error::PortInUse(_) => None,
}
}
}
async fn request_metrics(req: Request<Body>, registry: Registry) -> Result<Response<Body>, Error> {
async fn request_metrics(
req: Request<Body>,
registry: Registry,
) -> Result<Response<Body>, Error> {
if req.uri().path() == "/metrics" {
let metric_families = registry.gather();
let mut buffer = vec![];
let encoder = TextEncoder::new();
encoder.encode(&metric_families, &mut buffer).unwrap();
Response::builder().status(StatusCode::OK)
Response::builder()
.status(StatusCode::OK)
.header("Content-Type", encoder.format_type())
.body(Body::from(buffer))
.map_err(Error::Http)
} else {
Response::builder().status(StatusCode::NOT_FOUND)
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::from("Not found."))
.map_err(Error::Http)
}
}
#[derive(Clone)]
@@ -121,7 +129,10 @@ mod known_os {
/// Initializes the metrics context, and starts an HTTP server
/// to serve metrics.
pub async fn init_prometheus(prometheus_addr: SocketAddr, registry: Registry) -> Result<(), Error>{
pub async fn init_prometheus(
prometheus_addr: SocketAddr,
registry: Registry,
) -> Result<(), Error> {
use networking::Incoming;
let listener = async_std::net::TcpListener::bind(&prometheus_addr)
.await
+15 -13
View File
@@ -16,8 +16,11 @@
// limitations under the License.
use async_std::pin::Pin;
use std::task::{Poll, Context};
use futures_util::{stream::Stream, io::{AsyncRead, AsyncWrite}};
use futures_util::{
io::{AsyncRead, AsyncWrite},
stream::Stream,
};
use std::task::{Context, Poll};
pub struct Incoming<'a>(pub async_std::net::Incoming<'a>);
@@ -25,7 +28,10 @@ impl hyper::server::accept::Accept for Incoming<'_> {
type Conn = TcpStream;
type Error = async_std::io::Error;
fn poll_accept(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
fn poll_accept(
self: Pin<&mut Self>,
cx: &mut Context,
) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
Pin::new(&mut Pin::into_inner(self).0)
.poll_next(cx)
.map(|opt| opt.map(|res| res.map(TcpStream)))
@@ -38,10 +44,9 @@ impl tokio::io::AsyncRead for TcpStream {
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &mut [u8]
buf: &mut [u8],
) -> Poll<Result<usize, std::io::Error>> {
Pin::new(&mut Pin::into_inner(self).0)
.poll_read(cx, buf)
Pin::new(&mut Pin::into_inner(self).0).poll_read(cx, buf)
}
}
@@ -49,19 +54,16 @@ impl tokio::io::AsyncWrite for TcpStream {
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context,
buf: &[u8]
buf: &[u8],
) -> Poll<Result<usize, std::io::Error>> {
Pin::new(&mut Pin::into_inner(self).0)
.poll_write(cx, buf)
Pin::new(&mut Pin::into_inner(self).0).poll_write(cx, buf)
}
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), std::io::Error>> {
Pin::new(&mut Pin::into_inner(self).0)
.poll_flush(cx)
Pin::new(&mut Pin::into_inner(self).0).poll_flush(cx)
}
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), std::io::Error>> {
Pin::new(&mut Pin::into_inner(self).0)
.poll_close(cx)
Pin::new(&mut Pin::into_inner(self).0).poll_close(cx)
}
}
+28 -17
View File
@@ -17,8 +17,10 @@
//! Metrics that are collected from existing sources.
use prometheus::core::{Collector, Desc, Describer, Number, Opts};
use prometheus::proto;
use prometheus::{
core::{Collector, Desc, Describer, Number, Opts},
proto,
};
use std::{cmp::Ordering, marker::PhantomData};
/// A counter whose values are obtained from an existing source.
@@ -80,15 +82,15 @@ impl<T: SourcedType, S: MetricSource> Collector for SourcedMetric<T, S> {
let mut c = proto::Counter::default();
c.set_value(value.into_f64());
m.set_counter(c);
}
},
proto::MetricType::GAUGE => {
let mut g = proto::Gauge::default();
g.set_value(value.into_f64());
m.set_gauge(g);
}
},
t => {
log::error!("Unsupported sourced metric type: {:?}", t);
}
},
}
debug_assert_eq!(self.desc.variable_labels.len(), label_values.len());
@@ -97,18 +99,23 @@ impl<T: SourcedType, S: MetricSource> Collector for SourcedMetric<T, S> {
log::warn!("Missing label values for sourced metric {}", self.desc.fq_name),
Ordering::Less =>
log::warn!("Too many label values for sourced metric {}", self.desc.fq_name),
Ordering::Equal => {}
Ordering::Equal => {},
}
m.set_label(self.desc.variable_labels.iter().zip(label_values)
.map(|(l_name, l_value)| {
let mut l = proto::LabelPair::default();
l.set_name(l_name.to_string());
l.set_value(l_value.to_string());
l
})
.chain(self.desc.const_label_pairs.iter().cloned())
.collect::<Vec<_>>());
m.set_label(
self.desc
.variable_labels
.iter()
.zip(label_values)
.map(|(l_name, l_value)| {
let mut l = proto::LabelPair::default();
l.set_name(l_name.to_string());
l.set_value(l_value.to_string());
l
})
.chain(self.desc.const_label_pairs.iter().cloned())
.collect::<Vec<_>>(),
);
counters.push(m);
});
@@ -130,11 +137,15 @@ pub trait SourcedType: private::Sealed + Sync + Send {
}
impl SourcedType for Counter {
fn proto() -> proto::MetricType { proto::MetricType::COUNTER }
fn proto() -> proto::MetricType {
proto::MetricType::COUNTER
}
}
impl SourcedType for Gauge {
fn proto() -> proto::MetricType { proto::MetricType::GAUGE }
fn proto() -> proto::MetricType {
proto::MetricType::GAUGE
}
}
mod private {