mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 06:17:56 +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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user