Crate promql[−][src]
Expand description
This crate allows one to parse PromQL query into some AST.
See official documentation for query syntax description.
Example
use promql::*;
let ast = parse(b"
sum(1 - something_used{env=\"production\"} / something_total) by (instance)
and ignoring (instance)
sum(rate(some_queries{instance=~\"localhost\\\\d+\"} [5m])) > 100
", false).unwrap(); // or show user that their query is invalid
// now we can look for all sorts of things
// AST can represent an operator
if let Node::Operator { x, op: Op::And(op_mod), y } = ast {
// operators can have modifiers
assert_eq!(op_mod, Some(OpMod {
action: OpModAction::Ignore,
labels: vec!["instance".to_string()],
group: None,
}));
// aggregation functions like sum are represented as functions with optional modifiers (`by (label1, …)`/`without (…)`)
if let Node::Function { ref name, ref aggregation, ref args } = *x {
assert_eq!(*name, "sum".to_string());
assert_eq!(*aggregation, Some(AggregationMod {
action: AggregationAction::By,
labels: vec!["instance".to_string()],
}));
// …
}
} else {
panic!("top operator is not an \"and\"");
}
Macros
Structs
Single label filter.
Vector grouping operator modifier (group_left(…)
/group_right(…)
).
Vector matching operator modifier (on (…)
/ignoring (…)
).
This struct represents both instant and range vectors.
Enums
Label filter operators.
AST node.
PromQL operators
Functions
Parse expression string into an AST.