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
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(())
}
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(())
}
Auto Trait Implementations
impl<'a> RefUnwindSafe for Selector<'a>
impl<'a> UnwindSafe for Selector<'a>
Blanket Implementations
Mutably borrows from an owned value. 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