Add process feature to prometheus, and a timeout for clients

pull/12/head
Frank Denis 5 years ago
parent 42d361897b
commit 22d84a748c

@ -46,6 +46,7 @@ default_features = false
optional = true
version = "0.7.0"
default_features = false
features = ["process"]
[features]
default = ["metrics"]

@ -10,8 +10,11 @@ use hyper::{Body, Request, Response, StatusCode};
use prometheus::{self, Encoder, TextEncoder};
use std::sync::Arc;
use tokio::net::TcpListener;
use tokio::prelude::*;
use tokio::runtime::Runtime;
const METRICS_CONNECTION_TIMEOUT_SECS: u64 = 10;
async fn handle_client_connection(
req: Request<Body>,
varz: Varz,
@ -60,7 +63,13 @@ pub async fn prometheus_service(
let service =
service_fn(move |req| handle_client_connection(req, varz.clone(), path.clone()));
let connection = Http::new().serve_connection(client, service);
runtime.spawn(connection.map(|_| {}));
runtime.spawn(
connection
.timeout(std::time::Duration::from_secs(
METRICS_CONNECTION_TIMEOUT_SECS,
))
.map(|_| {}),
);
}
Ok(())
}

Loading…
Cancel
Save