promql-rs

Crates.iopromql-rs
lib.rspromql-rs
version0.1.1
sourcesrc
created_at2023-06-19 14:13:56.065742
updated_at2023-06-22 12:26:08.504577
descriptionA PromQL parser
homepagehttps://github.com/yuankunzhang/promql-rs
repositoryhttps://github.com/yuankunzhang/promql-rs
max_upload_size
id894145
size75,113
Yuankun Zhang (yuankunzhang)

documentation

https://github.com/yuankunzhang/promql-rs

README

promql-rs

A PromQL parser written in Rust.

Example

The minimal usage example:

use promql_rs::parser;

fn main() {
    let ast = parser::parse(r#"sum(rate(http_request_total{app="prometheus"}[5m])) by (host)"#);
    println!("{:#?}", ast.unwrap());
}

This will produce the following output:

AggregateExpr(
    AggregateExpr {
        op: Sum,
        expr: FunctionCall(
            FunctionCall {
                func: Function {
                    name: "rate",
                    arg_types: [
                        Matrix,
                    ],
                    return_type: Vector,
                },
                args: [
                    MatrixSelector(
                        MatrixSelector {
                            vector_selector: VectorSelector(
                                VectorSelector {
                                    metric: "http_request_total",
                                    label_matchers: [
                                        LabelMatcher {
                                            op: Equal,
                                            name: "app",
                                            value: "prometheus",
                                        },
                                    ],
                                    original_offset: 0ns,
                                    offset: 0ns,
                                    at: None,
                                },
                            ),
                            range: 300s,
                        },
                    ),
                ],
            },
        ),
        param: None,
        modifier: By(
            [
                "host",
            ],
        ),
    },
)

TODOs

  • Documentations.
  • Support VictoriaMetrics extensions.
Commit count: 37

cargo fmt