Giter Site home page Giter Site logo

Comments (8)

fbs avatar fbs commented on August 18, 2024 1

For a bit of background (shouldve added that earlier):

We run a shared prometheus platform used by many teams. I want to do some analysis of those rules to help teams with some company specifics (architecture). As its an all python team I'm using this library as pyo3 makes it really easy.

So changing the regex isn't an option, they come from end users and are valid for prometheus itself.

I guess its hard to fix as its a regex implementation difference between go and rust. If there was a 'less strict' regex flag I would be ok with that. What do you think?

I'm open to implementing something for it

from promql-parser.

yuanbohan avatar yuanbohan commented on August 18, 2024

Maybe it's because the difference between regex implementation of Rust and Go. I will try to fix it.
Thanks for your report, and any PR is welcome.

from promql-parser.

fbs avatar fbs commented on August 18, 2024

hi @yuanbohan, wow faster answer than I expected <3. I was taking a quick look as well:

For reproducing:

use regex::Regex;
fn main() {
    let re = r#"/v[1-9]/.*/{gid}/{uid}"#;

    Regex::new(&re).unwrap();
}

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Syntax(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regex parse error:
    /v[1-9]/.*/{gid}/{uid}
                ^
error: repetition quantifier expects a valid decimal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
)', src/main.rs:20:21

Which makes sense, not sure what a good fix is here

from promql-parser.

fbs avatar fbs commented on August 18, 2024
promql

Just to verify that prometheus itself handles the regex as expected (or not expected), it shows series

from promql-parser.

yuanbohan avatar yuanbohan commented on August 18, 2024

Maybe you can try other symbols in your uri, like <, _?
Or just escape the curly brackets using \ in your regex?

from promql-parser.

yuanbohan avatar yuanbohan commented on August 18, 2024
let re = r#"/v[1-9]/.*/\{gid\}/\{uid\}"#;
let cap = Regex::new(&re).unwrap().captures("/v1/foo/{gid}/{uid}");
println!("{cap:?}");

==== output

Some(Captures({0: 0..19/"/v1/foo/{gid}/{uid}"}))

Is this what you want? @fbs

from promql-parser.

waynexia avatar waynexia commented on August 18, 2024

I guess its hard to fix as its a regex implementation difference between go and rust. If there was a 'less strict' regex flag I would be ok with that. What do you think?

From the regex lib's doc I can't find any configuration to control such behavior 🙁

Not a regex expert, but what do you think of adding some "preprocess" to modify the input regex rule like @yuanbohan said:

Maybe you can try other symbols in your uri, like <, _? Or just escape the curly brackets using \ in your regex?

I'm not sure if this is viable...

from promql-parser.

fbs avatar fbs commented on August 18, 2024

I indeed ended up adding some preprocessing in #76. Its not the nicest implementation but it seems to work. Bit worried about some other edge cases I've missed.

from promql-parser.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.