pub struct Selector<'a> { /* private fields */ }
Expand description

A time series selector that is gradually built from a metric name and/or a set of label matchers.

Implementations§

source§

impl<'a> Selector<'a>

source

pub fn new() -> Self

Create a new instance of Selector.

source

pub fn metric(self, metric: &'a str) -> Selfwhere Self: Sized,

Select a metric name for this Selector.

use prometheus_http_query::Selector;

let select = Selector::new().metric("http_requests_total");

// This is equal to:
let other_select = Selector::new().eq("__name__", "http_requests_total");

assert_eq!(select, other_select);
source

pub fn eq(self, label: &'a str, value: &'a str) -> Selfwhere Self: Sized,

Append a label matcher to the set of matchers of Selector that selects labels that match the provided string.
PromQL equivalent: http_requests_total{job="apiserver"}

use prometheus_http_query::Selector;

let select = Selector::new()
    .metric("http_requests_total")
    .eq("job", "apiserver")
    .to_string();

let expected = r#"{__name__="http_requests_total",job="apiserver"}"#.to_string();

assert_eq!(select, expected);
source

pub fn ne(self, label: &'a str, value: &'a str) -> Selfwhere Self: Sized,

Append a label matcher to the set of matchers of Selector that selects labels that do not match the provided string.
PromQL equivalent: http_requests_total{job!="apiserver"}

use prometheus_http_query::Selector;

let select = Selector::new()
    .metric("http_requests_total")
    .ne("job", "apiserver")
    .to_string();

let expected = r#"{__name__="http_requests_total",job!="apiserver"}"#.to_string();

assert_eq!(select, expected);
source

pub fn regex_eq(self, label: &'a str, value: &'a str) -> Selfwhere Self: Sized,

Append a label matcher to the set of matchers of Selector that selects labels that regex-match the provided string. PromQL equivalent: http_requests_total{job=~"apiserver"}

use prometheus_http_query::Selector;

let select = Selector::new()
    .metric("http_requests_total")
    .regex_eq("job", "apiserver")
    .to_string();

let expected = r#"{__name__="http_requests_total",job=~"apiserver"}"#.to_string();

assert_eq!(select, expected);
source

pub fn regex_ne(self, label: &'a str, value: &'a str) -> Selfwhere Self: Sized,

Append a label matcher to the set of matchers of Selector that selects labels that do not regex-match the provided string.
PromQL equivalent: http_requests_total{job!~"apiserver"}

use prometheus_http_query::Selector;

let select = Selector::new()
    .metric("http_requests_total")
    .regex_ne("job", "apiserver")
    .to_string();

let expected = r#"{__name__="http_requests_total",job!~"apiserver"}"#.to_string();

assert_eq!(select, expected);

Trait Implementations§

source§

impl<'a> Clone for Selector<'a>

source§

fn clone(&self) -> Selector<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Selector<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Default for Selector<'a>

source§

fn default() -> Self

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

impl<'a> Display for Selector<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a> PartialEq for Selector<'a>

source§

fn eq(&self, other: &Selector<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> StructuralPartialEq for Selector<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Selector<'a>

§

impl<'a> Send for Selector<'a>

§

impl<'a> Sync for Selector<'a>

§

impl<'a> Unpin for Selector<'a>

§

impl<'a> UnwindSafe for Selector<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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