foundationdb::runner

Struct MetricsHooks

Source
pub struct MetricsHooks { /* private fields */ }
Expand description

Hooks collecting a MetricsReport into a TransactionMetrics.

They are what Database::instrumented_run is made of, and can be stacked on any other hooks to get the same report out of a plain run:

let metrics = TransactionMetrics::new();
db.run_with_hooks(&(MetricsHooks::new(&metrics), MyHooks), |trx, _| async move {
    trx.set(b"key", b"value");
    Ok::<_, FdbBindingError>(())
})
.await?;

let report = metrics.get_metrics_data();

The run is timed from the construction of the hooks, so build one per run.

The collector is attached to the transaction when the first attempt starts, which is what makes the counters of a plain run land in the report. A transaction only ever reports to one collector: stacking two MetricsHooks leaves the second one empty.

Implementations§

Source§

impl MetricsHooks

Source

pub fn new(metrics: &TransactionMetrics) -> Self

Collects the metrics of a run into metrics.

The handle is cloned, so the caller keeps reading the report from its own TransactionMetrics once the run is over.

Trait Implementations§

Source§

impl RunnerHooks for MetricsHooks

Source§

fn on_attempt_start(&self, trx: &Transaction, _attempt: usize)

Called when an attempt starts, before the closure runs.
Source§

async fn on_commit_error( &self, err: &TransactionCommitError, _attempt: usize, ) -> FdbResult<()>

Called when the commit failed, before on_error resets the transaction. This is the only window to read conflicting keys or inspect the state of the failed attempt. Read more
Source§

fn on_error_duration(&self, duration_ms: u64, _attempt: usize)

Called after on_error returned, with the time it took, backoff included.
Source§

fn on_commit_success( &self, committed: &TransactionCommitted, _commit_duration_ms: u64, _attempt: usize, )

Called after a successful commit, with the time the commit took.
Source§

fn on_complete(&self)

Called exactly once when the run ends, whatever its outcome.
Source§

fn before_commit( &self, _trx: &Transaction, _attempt: usize, ) -> impl Future<Output = FdbResult<()>> + Send

Called after the closure succeeded, before the transaction is committed. Read more
Source§

fn on_hook_error(&self, _err: &FdbError, _attempt: usize)

Called with the error of a hook that failed, right after it failed.
Source§

fn on_closure_error(&self, _err: &FdbError, _attempt: usize)

Called when a closure error is about to be handed to on_error. Read more
Source§

fn on_retry(&self, _attempt: usize)

Called when the attempt is about to be retried, that is once on_error accepted to retry it.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.