Struct prometheus_http_query::Selector[][src]

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

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

For final validation and further processing the selector is then converted to either a crate::InstantVector or crate::RangeVector.

Implementations

Simply return an empty Selector to build on.

use prometheus_http_query::Selector;
use prometheus_http_query::InstantVector;
use prometheus_http_query::Error;
use std::convert::TryInto;

let v: Result<InstantVector, Error> = Selector::new().try_into();

assert!(v.is_err());

Select a metric name for this Selector.

use prometheus_http_query::Selector;

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

assert!(s.is_ok());

… which must not be any reserved PromQL keyword.

use prometheus_http_query::Selector;

let s = Selector::new().metric("group_left");

assert!(s.is_err());

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;
use prometheus_http_query::InstantVector;
use prometheus_http_query::Error;
use std::convert::TryInto;

let v: Result<InstantVector, Error> = Selector::new()
    .metric("http_requests_total")
    .unwrap()
    .with("job", "apiserver")
    .try_into();

assert!(v.is_ok());

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;
use prometheus_http_query::InstantVector;
use prometheus_http_query::Error;
use std::convert::TryInto;

let v: Result<InstantVector, Error> = Selector::new()
    .metric("http_requests_total")
    .unwrap()
    .without("job", "apiserver")
    .try_into();

assert!(v.is_ok());

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;
use prometheus_http_query::InstantVector;
use prometheus_http_query::Error;
use std::convert::TryInto;

let v: Result<InstantVector, Error> = Selector::new()
    .metric("http_requests_total")
    .unwrap()
    .regex_match("job", "apiserver")
    .try_into();

assert!(v.is_ok());

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;
use prometheus_http_query::InstantVector;
use prometheus_http_query::Error;
use std::convert::TryInto;

let v: Result<InstantVector, Error> = Selector::new()
    .metric("http_requests_total")
    .unwrap()
    .no_regex_match("job", "apiserver")
    .try_into();

assert!(v.is_ok());

Add a time range to this Selector (effectively priming this Selector to be converted to a crate::RangeVector).
See the Prometheus reference for the correct time duration syntax.

use prometheus_http_query::Selector;

let s = Selector::new().metric("some_metric").unwrap().range("1m30s");

assert!(s.is_ok());

Providing invalid time durations will lead to an error.

use prometheus_http_query::Selector;

let s = Selector::new().metric("some_metric").unwrap().range("30s1m");

assert!(s.is_err());

Add a time offset to this Selector.
See the Prometheus reference regarding time durations and offsets for the correct time duration syntax.

use prometheus_http_query::Selector;

let s = Selector::new().metric("some_metric").unwrap().offset("1m30s");

assert!(s.is_ok());

Providing invalid time durations will lead to an error.

use prometheus_http_query::Selector;

let s = Selector::new().metric("some_metric").unwrap().offset("30s1m");

assert!(s.is_err());

Add a @ modifier to this Selector.
See the Prometheus reference regarding time durations and @ modifiers for details.

use prometheus_http_query::{Selector, InstantVector};
use std::convert::TryInto;

let s: Result<InstantVector, _> = Selector::new().metric("some_metric").unwrap().at(1623855855).try_into();

assert!(s.is_ok());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Convert a Selector to an InstantVector.

use prometheus_http_query::{Selector, InstantVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let v: Result<InstantVector, Error> = Selector::new()
        .metric("some_metric")?
        .try_into();

    assert!(v.is_ok());

    Ok(())
}

The type returned in the event of a conversion error.

Convert a Selector to a RangeVector.

use prometheus_http_query::{Selector, RangeVector, Error};
use std::convert::TryInto;

fn main() -> Result<(), Error> {
    let v: Result<RangeVector, Error> = Selector::new()
        .metric("some_metric")?
        .range("1m30s")?
        .try_into();

    assert!(v.is_ok());

    Ok(())
}

The type returned in the event of a conversion error.

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

Performs the conversion.

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

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Converts the given value to a String. Read more

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