Struct prometheus_http_query::Selector
source · [−]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.
For final validation and further processing the selector is then converted to either a crate::InstantVector or crate::RangeVector.
Implementations
sourceimpl<'a> Selector<'a>
impl<'a> Selector<'a>
sourcepub fn new() -> Self
pub fn new() -> Self
Simply return an empty Selector to build on. A selector “must either specify a metric name or at least one label matcher that does not match the empty string” as per the Prometheus documentation.
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());
sourcepub fn metric(self, metric: &'a str) -> Self where
Self: Sized,
pub fn metric(self, metric: &'a str) -> Self where
Self: Sized,
Select a metric name for this Selector.
use prometheus_http_query::Selector;
let s = Selector::new().metric("http_requests_total");
sourcepub fn with(self, label: &'a str, value: &'a str) -> Self where
Self: Sized,
pub fn with(self, label: &'a str, value: &'a str) -> Self where
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;
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")
.with("job", "apiserver")
.try_into();
assert!(v.is_ok());
sourcepub fn without(self, label: &'a str, value: &'a str) -> Self where
Self: Sized,
pub fn without(self, label: &'a str, value: &'a str) -> Self where
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;
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")
.without("job", "apiserver")
.try_into();
assert!(v.is_ok());
sourcepub fn regex_match(self, label: &'a str, value: &'a str) -> Self where
Self: Sized,
pub fn regex_match(self, label: &'a str, value: &'a str) -> Self where
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;
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")
.regex_match("job", "apiserver")
.try_into();
assert!(v.is_ok());
sourcepub fn no_regex_match(self, label: &'a str, value: &'a str) -> Self where
Self: Sized,
pub fn no_regex_match(self, label: &'a str, value: &'a str) -> Self where
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;
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")
.no_regex_match("job", "apiserver")
.try_into();
assert!(v.is_ok());
sourcepub fn range(self, duration: &'a str) -> Result<Self, Error>
pub fn range(self, duration: &'a str) -> Result<Self, Error>
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").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").range("30s1m");
assert!(s.is_err());
sourcepub fn offset(self, duration: &'a str) -> Result<Self, Error>
pub fn offset(self, duration: &'a str) -> Result<Self, Error>
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").offset("1m30s");
assert!(s.is_ok());
// Negative offsets are allowed.
let s = Selector::new().metric("some_metric").offset("-1h30m");
assert!(s.is_ok());
// Providing invalid time durations will lead to an error.
let s = Selector::new().metric("some_metric").offset("30s1m");
assert!(s.is_err());
sourcepub fn at(self, time: i64) -> Self
pub fn at(self, time: i64) -> Self
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").at(1623855855).try_into();
assert!(s.is_ok());
Trait Implementations
sourceimpl TryFrom<Selector<'_>> for InstantVector
impl TryFrom<Selector<'_>> for InstantVector
sourcefn try_from(selector: Selector<'_>) -> Result<Self, Self::Error>
fn try_from(selector: Selector<'_>) -> Result<Self, Self::Error>
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(())
}
sourceimpl TryFrom<Selector<'_>> for RangeVector
impl TryFrom<Selector<'_>> for RangeVector
sourcefn try_from(selector: Selector<'_>) -> Result<RangeVector, Self::Error>
fn try_from(selector: Selector<'_>) -> Result<RangeVector, Self::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(())
}
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
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> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. 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