Struct merino_integration_tests::MetricsWatcher
source · [−]Expand description
Helper to collect metrics during tests, and make assertions about them.
Fields
rx: Receiver<Vec<u8>>
Crossbeam channel that receives metrics lines as bytes.
messages: Vec<Message>
Metrics received by the watcher from [rx
].
Implementations
sourceimpl MetricsWatcher
impl MetricsWatcher
sourcepub fn new_with_client() -> (Self, StatsdClient)
pub fn new_with_client() -> (Self, StatsdClient)
Make a new metrics watcher, attach it to a StatsdClient
and return both.
sourcefn process_events(&mut self)
fn process_events(&mut self)
Consume any waiting events from rx
and parse them as metrics.
sourcepub fn all_messages(&mut self) -> &[Message]
pub fn all_messages(&mut self) -> &[Message]
Get a list of all the metrics seen by this watcher, primarily for debugging.
sourcepub fn has<F>(&mut self, predicate: F) -> bool where
F: FnMut(&Message) -> bool,
pub fn has<F>(&mut self, predicate: F) -> bool where
F: FnMut(&Message) -> bool,
Test if any metric this watcher received matches predicate
.
Example
use statsd_parser::{Message, Metric, Counter};
metrics_client.incr("a-metric");
assert!(metrics_watcher.has(|msg| {
println!("@@@ msg: {:?}", msg);
msg.name == "a-metric"
&& matches!(msg.metric, Metric::Counter(Counter { value, .. }) if value == 1.0)
}));
sourcepub fn has_histogram(&mut self, name: &str, expected_value: f64) -> bool
pub fn has_histogram(&mut self, name: &str, expected_value: f64) -> bool
Test if any metric this watcher received was a histogram with the given name and value.
Values are compared by taking the absolute difference between them, and checking if it less than an epsilon of 0.0001.
Auto Trait Implementations
impl RefUnwindSafe for MetricsWatcher
impl Send for MetricsWatcher
impl Sync for MetricsWatcher
impl Unpin for MetricsWatcher
impl UnwindSafe for MetricsWatcher
Blanket Implementations
sourceimpl<'a, T, E> AsTaggedExplicit<'a, E> for T where
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for T where
T: 'a,
sourceimpl<'a, T, E> AsTaggedImplicit<'a, E> for T where
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for T where
T: 'a,
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more