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
impl MetricsHooks
Sourcepub fn new(metrics: &TransactionMetrics) -> Self
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
impl RunnerHooks for MetricsHooks
Source§fn on_attempt_start(&self, trx: &Transaction, _attempt: usize)
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<()>
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 moreSource§fn on_error_duration(&self, duration_ms: u64, _attempt: usize)
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,
)
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)
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
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)
fn on_hook_error(&self, _err: &FdbError, _attempt: usize)
Called with the error of a hook that failed, right after it failed.
Auto Trait Implementations§
impl Freeze for MetricsHooks
impl RefUnwindSafe for MetricsHooks
impl Send for MetricsHooks
impl Sync for MetricsHooks
impl Unpin for MetricsHooks
impl UnwindSafe for MetricsHooks
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more