Skip to content

Commit

Permalink
"sample text"
Browse files Browse the repository at this point in the history
  • Loading branch information
vthriller committed Jan 25, 2018
1 parent bb6913f commit 35080ee
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
/*!
This crate allows one to parse PromQL query into some AST.
See [official documentation](https://prometheus.io/docs/prometheus/latest/querying/basics/) for query syntax description.
## Example
```
# extern crate nom;
# extern crate promql;
# fn main() {
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
").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\"");
}
# }
```
*/

#[macro_use]
extern crate nom;
#[macro_use]
Expand Down

0 comments on commit 35080ee

Please sign in to comment.