From 08c704e106599440ebcb3436ddb65d792566d129 Mon Sep 17 00:00:00 2001 From: Maaz Ahmed <maaz.a@subcom.tech> Date: Mon, 8 Jan 2024 14:29:06 +0530 Subject: [PATCH] feat: timestamp and label_set fns --- src/query/fns/label.rs | 15 +++++++++++++++ src/query/fns/rollup.rs | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/query/fns/label.rs b/src/query/fns/label.rs index 15b0e28..6caa4bc 100644 --- a/src/query/fns/label.rs +++ b/src/query/fns/label.rs @@ -7,6 +7,15 @@ use crate::query::{ ops::Operable, }; +/// MetricsQL's label_set label manipulation query function +#[inline] +pub fn mql_label_set<'a>( + qry_expr: impl Operable + 'a, + label_value_pairs: &'a [&'a str], +) -> QryFunc<impl Fn(&mut fmt::Formatter) -> fmt::Result + 'a> { + basic_label_fn("label_set", qry_expr, label_value_pairs) +} + /// MetricsQL's label_map query function pub fn mql_label_map<'a>( qry_expr: impl Operable + 'a, @@ -111,4 +120,10 @@ mod tests { r#"sort_by_label_numeric_desc(metric,"label","label2")"# ); } + + #[test] + fn label_label_set() { + let qry = mql_label_set(Metric::new("metric"), &["label", "value"]).to_string(); + assert_eq!(qry, r#"label_set(metric,"label","value")"#); + } } diff --git a/src/query/fns/rollup.rs b/src/query/fns/rollup.rs index 29b0f26..6565e8a 100644 --- a/src/query/fns/rollup.rs +++ b/src/query/fns/rollup.rs @@ -4,6 +4,12 @@ use crate::query::ops::Operable; use super::{basic_fn, qry_fn, QryFunc}; +/// The timestamp rollup query function +#[inline] +pub fn timestamp(range_vec: impl Operable) -> QryFunc<impl Fn(&mut fmt::Formatter) -> fmt::Result> { + basic_fn("timestamp", range_vec) +} + /// The avg_over_time rollup query function #[inline] pub fn avg_over_time( @@ -150,4 +156,10 @@ mod tests { let string = last_over_time(test_metric()).to_string(); assert_eq!(string, "last_over_time(test_metric[15d])"); } + + #[test] + fn rollup_timestamp() { + let string = timestamp(test_metric()).to_string(); + assert_eq!(string, "timestamp(test_metric[15d])"); + } } -- GitLab