Function prometheus_http_query::functions::clamp_min
source · [−]pub fn clamp_min(vector: InstantVector, min: f64) -> InstantVectorExpand description
Apply the PromQL clamp_min function.
use prometheus_http_query::{Client, Selector, InstantVector};
use prometheus_http_query::functions::clamp_min;
use std::convert::TryInto;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), prometheus_http_query::Error> {
let client = Client::default();
let vector: InstantVector = Selector::new()
.metric("up")
.with("job", "prometheus")
.try_into()?;
let q = clamp_min(vector, 5.0);
let response = client.query(q, None, None).await?;
let value = response.as_instant()
.unwrap()
.get(0)
.unwrap()
.sample()
.value();
assert_eq!(value, 5.0);
Ok(())
}