Return time spent in query engine
As an x-elapsed header in the response, in microseconds.
@@ -52,7 +52,9 @@ impl HttpServer {
}
async fn routes(ctx: Arc<RequestContext>, req: Request<Body>) -> std::result::Result<Response<Body>, Error> {
- let res = match (req.method(), req.uri().path()) {
+ let start = Instant::now();
+
+ let mut res = match (req.method(), req.uri().path()) {
(&Method::POST, "/") => {
let (parts, body) = req.into_parts();
@@ -94,6 +96,9 @@ impl HttpServer {
}
};
+ let elapsed = Instant::now().duration_since(start).as_micros() as u64;
+ res.headers_mut().insert("x-elapsed", elapsed.into());
+
Ok(res)
}
