Skip to content

PromQL regex classes \d, \w, \s, \b match Unicode; Prometheus matches ASCII only #981

Open

Description

@zzylol

Problem, by example

Two series of x: instance="café" and instance="cafe". In an independent review probe on the branch of #974's PR, the executor's label matchers gave:

Matcher Executor (Rust regex) Prometheus (Go RE2)
x{instance=~"\\w+"} both series only cafe
x{instance=~"\\d+"} with instance="١٢" (Arabic-Indic digits) matches no match

Why it happens

  • Rust's regex crate makes the Perl classes \d, \w, \s and the word boundary \b Unicode-aware by default.
  • Go's RE2, which Prometheus uses, defines them over ASCII only.
  • The PromQL parser (promql-parser) and the executor (expressions::promql_anchored_regex) both compile patterns with Rust's regex, so the system is consistent with itself but not with Prometheus.
  • (?i), the anchoring ^(?s:…)$ and Go-style literal braces (/api/{id}) already match Prometheus.

Proposal

Compile label patterns with these classes made ASCII-only, so they match Go's RE2:

  • either rewrite \d, \w, \s, \b (and their negations) to (?-u:\d) and so on;
  • or build the regex with regex::RegexBuilder and unicode(false) where the pattern needs no other Unicode feature.

Do this in promql_anchored_regex, the one place the executor compiles PromQL patterns. Check whether the parser's matcher, used at planning time, needs the same change.

Scope and acceptance

  • Scope: executor label matchers and label_replace patterns.
  • Acceptance:
    • x{instance=~"\\w+"} selects cafe but not café;
    • \d+ does not match ١٢;
    • existing matcher tests still pass.

Related

#974 (regex label matchers in the executor).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpromqlPromQL front-end lowering (L1→L2)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions