Function prometheus_http_query::functions::label_replace [−][src]
pub fn label_replace(
vector: InstantVector,
dst_label: &str,
replacement: &str,
src_label: &str,
regex: &str
) -> Result<InstantVector, Error>
Expand description
Apply the PromQL label_replace
function.
use prometheus_http_query::{Selector, InstantVector}; use prometheus_http_query::functions::label_replace; use std::convert::TryInto; fn main() -> Result<(), prometheus_http_query::Error> { let vector: InstantVector = Selector::new() .metric("some_metric")? .with("some_label", "some_value") .try_into()?; let result = label_replace(vector, "new_label", "$1", "some_label", "(.*):.*")?; let promql = r#"label_replace(some_metric{some_label="some_value"}, "new_label", "$1", "some_label", "(.*):.*")"#; assert_eq!(&result.to_string(), promql); Ok(()) }