Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/parser/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,23 @@ lazy_static! {
ValueType::Vector,
false
),
// MetricsQL extension.
function!(
"distinct_over_time",
vec![ValueType::Matrix],
0,
ValueType::Vector,
false
),
function!("end", vec![], 0, ValueType::Scalar, true),
// MetricsQL extension.
function!(
"entropy_over_time",
vec![ValueType::Matrix],
0,
ValueType::Vector,
false
),
function!("exp", vec![ValueType::Vector], 0, ValueType::Vector, false),
function!(
"first_over_time",
Expand Down Expand Up @@ -668,13 +684,20 @@ mod tests {
let rate = get_function("rate").unwrap();
assert_eq!(rate.variadic, 0);
assert!(!rate.experimental);

for func_name in ["max_of", "min_of"] {
let func = get_function(func_name).unwrap();
assert_eq!(func.arg_types, vec![ValueType::Scalar, ValueType::Scalar]);
assert_eq!(func.variadic, 0);
assert_eq!(func.return_type, ValueType::Scalar);
assert!(func.experimental);
}

for func_name in ["distinct_over_time", "entropy_over_time"] {
let func = get_function(func_name).unwrap();
assert_eq!(func.arg_types, vec![ValueType::Matrix]);
assert_eq!(func.variadic, 0);
assert_eq!(func.return_type, ValueType::Vector);
assert!(!func.experimental);
}
}
}
24 changes: 24 additions & 0 deletions src/parser/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,30 @@ mod tests {
Expr::new_call(get_function("rate").unwrap(), FunctionArgs::new_args(ex))
})
}),
("distinct_over_time(some_metric[5m])", {
Expr::new_matrix_selector(
Expr::from(VectorSelector::from("some_metric")),
duration::MINUTE_DURATION * 5,
)
.and_then(|ex| {
Expr::new_call(
get_function("distinct_over_time").unwrap(),
FunctionArgs::new_args(ex),
)
})
}),
("entropy_over_time(some_metric[5m])", {
Expr::new_matrix_selector(
Expr::from(VectorSelector::from("some_metric")),
duration::MINUTE_DURATION * 5,
)
.and_then(|ex| {
Expr::new_call(
get_function("entropy_over_time").unwrap(),
FunctionArgs::new_args(ex),
)
})
}),
("round(some_metric)", {
let ex = Expr::from(VectorSelector::from("some_metric"));
Expr::new_call(get_function("round").unwrap(), FunctionArgs::new_args(ex))
Expand Down
Loading