pub fn minute(vector: InstantVector) -> InstantVector
Expand description

Apply the PromQL minute function.

use prometheus_http_query::{Client, Selector, InstantVector};
use prometheus_http_query::functions::{minute, timestamp};
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 = minute(timestamp(vector));

    let response = client.query(q, None, None).await?;
    let value = response.as_instant()
        .unwrap()
        .get(0)
        .unwrap()
        .sample()
        .value();

    assert!((0.0..=59.0).contains(&value));
    Ok(())
}