Struct metrics_util::layers::FilterLayer

source ·
pub struct FilterLayer { /* private fields */ }
Expand description

A layer for filtering and discarding metrics matching certain name patterns.

Uses an Aho-Corasick automaton to efficiently match a metric key against multiple patterns at once. Patterns are matched across the entire key i.e. they are matched as substrings.

If a metric key matches any of the configured patterns, it will be skipped entirely. This applies equally to metric registration and metric emission.

A number of options are exposed that control the underlying automaton, such as compilation to a DFA, or case sensitivity.

Implementations§

source§

impl FilterLayer

source

pub fn from_patterns<P, I>(patterns: P) -> Self
where P: IntoIterator<Item = I>, I: AsRef<str>,

Creates a FilterLayer from an existing set of patterns.

source

pub fn add_pattern<P>(&mut self, pattern: P) -> &mut FilterLayer
where P: AsRef<str>,

Adds a pattern to match.

source

pub fn case_insensitive(&mut self, case_insensitive: bool) -> &mut FilterLayer

Sets the case sensitivity used for pattern matching.

Defaults to false i.e. searches are case sensitive.

source

pub fn use_dfa(&mut self, dfa: bool) -> &mut FilterLayer

Sets whether or not to internally use a deterministic finite automaton.

The main benefit to a DFA is that it can execute searches more quickly than a NFA (perhaps 2-4 times as fast). The main drawback is that the DFA uses more space and can take much longer to build.

Enabling this option does not change the time complexity for constructing the underlying Aho-Corasick automaton (which is O(p) where p is the total number of patterns being compiled). Enabling this option does however reduce the time complexity of non-overlapping searches from O(n + p) to O(n), where n is the length of the haystack.

In general, it’s a good idea to enable this if you’re searching a small number of fairly short patterns, or if you want the fastest possible search without regard to compilation time or space usage.

Defaults to true.

Trait Implementations§

source§

impl Default for FilterLayer

source§

fn default() -> FilterLayer

Returns the “default value” for a type. Read more
source§

impl<R> Layer<R> for FilterLayer

§

type Output = Filter<R>

The output type after wrapping.
source§

fn layer(&self, inner: R) -> Self::Output

Wraps inner based on this layer.

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

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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.