Function prometheus_http_query::functions::label_replace
source · [−]pub fn label_replace(
vector: InstantVector,
dst_label: &str,
replacement: &str,
src_label: &str,
regex: &str
) -> Result<InstantVector, Error>
Expand description
Apply the PromQL lable_replace
function.
use prometheus_http_query::{Client, Selector, InstantVector};
use prometheus_http_query::functions::label_replace;
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_replace(vector, "example_label", "$1", "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(&"localhost".to_string()));
Ok(())
}