Function prometheus_http_query::functions::label_join
source · [−]pub fn label_join(
vector: InstantVector,
dst_label: &str,
separator: &str,
src_labels: &[&str]
) -> Result<InstantVector, Error>Expand description
Apply the PromQL lable_join function.
use prometheus_http_query::{Client, Selector, InstantVector};
use prometheus_http_query::functions::label_join;
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 = label_join(vector, "example_label", " on ", &["job", "instance"])?;
let response = client.query(q, None, None).await?;
let label = response.as_instant()
.unwrap()
.get(0)
.unwrap()
.metric()
.get(&"example_label".to_string());
assert_eq!(label, Some(&"prometheus on localhost:9090".to_string()));
Ok(())
}