pub struct MetricsWatcher {
    rx: Receiver<Vec<u8>>,
    messages: Vec<Message>,
}
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

Make a new metrics watcher, attach it to a StatsdClient and return both.

Consume any waiting events from rx and parse them as metrics.

Get a list of all the metrics seen by this watcher, primarily for debugging.

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)
}));

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.

Test if any metric this watcher increase in value for a given name.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more