Skip to content
Snippets Groups Projects
Commit 08c704e1 authored by Maaz Ahmed's avatar Maaz Ahmed
Browse files

feat: timestamp and label_set fns

parent e06188d0
No related branches found
No related tags found
1 merge request!25Resolve "Add support for more features in query builder API"
Pipeline #14881 passed with stages
in 2 minutes and 13 seconds
......@@ -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")"#);
}
}
......@@ -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])");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment