We should use hyper and tower-http to create a middleware to apply Prometheus metrics to every requests.
Since there is NO example for v1 of Hyper, we should wait.
This is an example (not working):
let listener = TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], config.port))).await?;
loop {
let (stream, _) = listener.accept().await?;
let io = TokioIo::new(stream);
let mut warp_svc = warp::service(
warp::any().map(|| "Hello From Warp!")
);
tokio::spawn(async move {
// N.B. should use hyper service_fn here, since it's required to be implemented hyper Service trait!
let svc = hyper::service::service_fn(move |req: Request<Incoming>| async move {
let mut warp_req = warp::http::Request::builder()
.method(req.method().to_string().as_str())
.uri(req.uri().to_string())
.body(req.body())
.unwrap();
println!("before request");
let resp = warp_svc.call(warp_req);
println!("after request");
resp
});
if let Err(err) = http1::Builder::new().serve_connection(io, svc) {
eprintln!("server error: {}", err);
}
});
}
Describe what you want in a new way for Autha:
We should use
hyper
andtower-http
to create a middleware to apply Prometheus metrics to every requests. Since there is NO example for v1 of Hyper, we should wait.This is an example (not working):
Which library/binary?
Autha