From 005dadb342c6a79d154d3eaf5a5fbb86f3a7e641 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Tue, 12 Oct 2021 22:51:30 +0400 Subject: tests, cleanup & rest base --- common/rust/src/monitoring.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'common/rust/src/monitoring.rs') diff --git a/common/rust/src/monitoring.rs b/common/rust/src/monitoring.rs index ded1d95..4bff043 100644 --- a/common/rust/src/monitoring.rs +++ b/common/rust/src/monitoring.rs @@ -1,19 +1,19 @@ use hyper::{ - Response, Body, Request, Server, - header::{CONTENT_TYPE}, + header::CONTENT_TYPE, service::{make_service_fn, service_fn}, + Body, Request, Response, Server, }; -use std::net::ToSocketAddrs; +use log::{error, info}; use prometheus::{Encoder, TextEncoder}; -use log::{info,error}; use serde::Deserialize; +use std::net::ToSocketAddrs; #[derive(Clone, Debug, Deserialize)] /// Options for the monitoring service pub struct MonitoringConfiguration { - enabled: bool, - address: Option, - port: Option, + pub enabled: bool, + pub address: Option, + pub port: Option, } /// Handler for the hyper http server @@ -37,17 +37,18 @@ pub fn start_monitoring(configuration: &MonitoringConfiguration) { let config = configuration.clone(); tokio::task::spawn(async move { if config.enabled { - let address = format!("{}:{}", - config.address.expect("a listening address must be specified for the metrics server"), - config.port.expect("a listening port must be specified for the metrics server") + let address = format!( + "{}:{}", + config + .address + .expect("a listening address must be specified for the metrics server"), + config + .port + .expect("a listening port must be specified for the metrics server") ); info!("Starting monitoring server on {}", address); - - let listen_address = address - .to_socket_addrs() - .unwrap() - .next() - .unwrap(); + + let listen_address = address.to_socket_addrs().unwrap().next().unwrap(); let server = Server::bind(&listen_address).serve(make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(serve_metrics)) })); @@ -57,4 +58,4 @@ pub fn start_monitoring(configuration: &MonitoringConfiguration) { } } }); -} \ No newline at end of file +} -- cgit v1.2.3