Function prometheus_http_query::functions::year
source · [−]pub fn year(vector: InstantVector) -> InstantVector
Expand description
Apply the PromQL year
function.
use prometheus_http_query::{Client, Selector, InstantVector};
use prometheus_http_query::functions::{timestamp, year};
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("prometheus_http_requests_total")
.try_into()?;
let q = year(timestamp(vector));
let response = client.query(q, None, None).await?;
let value = response.as_instant()
.unwrap()
.get(0)
.unwrap()
.sample()
.value();
assert!(value >= 2022.0);
Ok(())
}