|
|
|
@ -49,7 +49,15 @@ lazy_static! {
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn serve_req(_req: Request<Body>) -> std::result::Result<Response<Body>, hyper::Error> {
|
|
|
|
|
async fn serve_req(req: Request<Body>) -> std::result::Result<Response<Body>, hyper::Error> {
|
|
|
|
|
match req.uri().path() {
|
|
|
|
|
"/metrics" => serve_metrics().await,
|
|
|
|
|
"/health" => serve_health_check().await,
|
|
|
|
|
_ => serve_not_found().await,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn serve_metrics() -> std::result::Result<Response<Body>, hyper::Error> {
|
|
|
|
|
let encoder = TextEncoder::new();
|
|
|
|
|
|
|
|
|
|
HTTP_COUNTER.inc();
|
|
|
|
@ -71,6 +79,20 @@ async fn serve_req(_req: Request<Body>) -> std::result::Result<Response<Body>, h
|
|
|
|
|
Ok(response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn serve_health_check() -> std::result::Result<Response<Body>, hyper::Error> {
|
|
|
|
|
Ok(Response::builder()
|
|
|
|
|
.status(200)
|
|
|
|
|
.body(Body::from(vec![]))
|
|
|
|
|
.unwrap())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn serve_not_found() -> std::result::Result<Response<Body>, hyper::Error> {
|
|
|
|
|
Ok(Response::builder()
|
|
|
|
|
.status(404)
|
|
|
|
|
.body(Body::from(vec![]))
|
|
|
|
|
.unwrap())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) async fn start_serving_metrics(config: Config) -> std::result::Result<(), hyper::Error> {
|
|
|
|
|
let serve_future = Server::bind(&config.listener).serve(make_service_fn(|_| async {
|
|
|
|
|
Ok::<_, hyper::Error>(service_fn(serve_req))
|
|
|
|
|