linkerd/tacho

Measuring latency hyper async (based on tokio-rs)

arpitsr opened this issue · 1 comments

Can you provide an example of how to use this to measure latency for hyper (0.0.11 async - based on tokio-rs) ?

Hi @arpitsr

Here's an example for a Hyper client.

First, we have to initialize tokio, hyper, and tacho. Metrics (in this case, latency) should be created during initialization if possible.

let core = tokio_core::Core::new().unwrap();
let (metrics, reporter) = tacho::new();
let latency = metrics.prefixed("client").timer_ms("latency_ms");
let client = hyper::Client::new(&core.handle());

Then, wrap the things you want to measure with latency.time to produce a Timed future that records latency.

latency.time(client.get(uri)).map(|rsp| {
  ...
})

To integrate this with a hyper server, you would just wrap the response future with latency.time.