Trait mz_ore::metrics::MetricsFutureExt

source ·
pub trait MetricsFutureExt<F> {
    // Required methods
    fn wall_time(self) -> WallTimeFuture<F, UnspecifiedMetric> ;
    fn exec_time(self) -> ExecTimeFuture<F, UnspecifiedMetric> ;
}
Available on crate feature metrics only.
Expand description

Exposes combinators that report metrics related to the execution of a Future to prometheus.

Required Methods§

source

fn wall_time(self) -> WallTimeFuture<F, UnspecifiedMetric>

Records the number of seconds it takes a Future to complete according to “the clock on the wall”.

More specifically, it records the instant at which the Future was first polled, and the instant at which the Future completes. Then reports the duration between those two instances to the provided metric.

§Wall Time vs Execution Time

There is also MetricsFutureExt::exec_time, which measures how long a Future spent executing, instead of how long it took to complete. For example, a network request may have a wall time of 1 second, meanwhile it’s execution time may have only been 50ms. The 950ms delta would be how long the Future waited for a response from the network.

§Uses

Recording the wall time can be useful for monitoring latency, for example the latency of a SQL request.

Note: You must call either observe to record the execution time to a Histogram or inc_by to record to a Counter. The following will not compile:

use mz_ore::metrics::MetricsFutureExt;

async { Ok(()) }
    .wall_time()
    .await;
source

fn exec_time(self) -> ExecTimeFuture<F, UnspecifiedMetric>

Records the total number of seconds for which a Future was executing.

More specifically, every time the Future is polled it records how long that individual call took, and maintains a running sum until the Future completes. Then we report that duration to the provided metric.

§Wall Time vs Execution Time

There is also MetricsFutureExt::wall_time, which measures how long a Future took to complete, instead of how long it spent executing. For example, a network request may have a wall time of 1 second, meanwhile it’s execution time may have only been 50ms. The 950ms delta would be how long the Future waited for a response from the network.

§Uses

Recording execution time can be useful if you want to monitor Futures that could be sensitive to CPU usage. For example, if you have a single logical control thread you’ll want to make sure that thread never spends too long running a single Future. Reporting the execution time of Futures running on this thread can help ensure there is no unexpected blocking.

Note: You must call either observe to record the execution time to a Histogram or inc_by to record to a Counter. The following will not compile:

use mz_ore::metrics::MetricsFutureExt;

async { Ok(()) }
    .exec_time()
    .await;

Implementors§