MetricsAssert

Struct MetricsAssert 

Source
pub struct MetricsAssert<T> { /* private fields */ }
Expand description

Provides fluent test assertions for metrics.

§Examples

use ic_metrics_assert::{MetricsAssert, PocketIcHttpQuery};
use pocket_ic::PocketIc;
use ic_management_canister_types::CanisterId;

struct Setup {
    env: PocketIc,
    canister_id : CanisterId,
}

impl Setup {
    pub fn check_metrics(self) -> MetricsAssert<Self> {
        MetricsAssert::from_http_query(self)
    }
}

impl PocketIcHttpQuery for Setup {
    fn get_pocket_ic(&self) -> &PocketIc {
        &self.env
    }

    fn get_canister_id(&self) -> CanisterId {
        self.canister_id
    }
}

fn assert_metrics () {
    use pocket_ic::PocketIcBuilder;
    use candid::Principal;

    let env = PocketIcBuilder::new().build();
    let canister_id = Principal::from_text("7hfb6-caaaa-aaaar-qadga-cai").unwrap();
    let setup = Setup {env, canister_id};

    setup
        .check_metrics()
        .assert_contains_metric_matching("started action \\d+")
        .assert_contains_metric_matching("completed action 1")
        .assert_does_not_contain_metric_matching(".*trap.*");
}

Implementations§

Source§

impl<T> MetricsAssert<T>

Source

pub fn from_http_query<E>(actual: T) -> Self
where T: CanisterHttpQuery<E>, E: Debug,

Initializes an instance of MetricsAssert by querying the metrics from the /metrics endpoint of a canister via the CanisterHttpQuery::http_query method.

Source

pub async fn from_async_http_query<E>(actual: T) -> Self
where T: AsyncCanisterHttpQuery<E>, E: Debug,

Initializes an instance of MetricsAssert by querying the metrics from the /metrics endpoint of a canister via the AsyncCanisterHttpQuery::http_query method.

Source

pub fn into(self) -> T

Returns the internal instance being tested.

Source

pub fn assert_contains_metric_matching<P: AsRef<str> + Display>( self, pattern: P, ) -> Self

Asserts that the metrics contain at least one entry matching the given Regex pattern.

Source

pub fn assert_does_not_contain_metric_matching(self, pattern: &str) -> Self

Asserts that the metrics do not contain any entries matching the given Regex pattern.

Auto Trait Implementations§

§

impl<T> Freeze for MetricsAssert<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for MetricsAssert<T>
where T: RefUnwindSafe,

§

impl<T> Send for MetricsAssert<T>
where T: Send,

§

impl<T> Sync for MetricsAssert<T>
where T: Sync,

§

impl<T> Unpin for MetricsAssert<T>
where T: Unpin,

§

impl<T> UnwindSafe for MetricsAssert<T>
where T: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.