Practical technical guides

Prometheus 3.13.6 Fixes Regex Matches That Can Distort Alerts

Use synthetic rule tests to check exact series membership across the December 3 release and its predecessor.

By Sandeep Belgavi · Published 2026-12-04

Flow from Expected labels, to Pinned promtool test, to Exact result set.
Original conceptual diagram by Sandeep Belgavi.

A matcher bug can change an alert without changing the rule

A synthetic metric labels a processing stage with a pipe-delimited set of component names. A PromQL selector tries to match the exact component parser within that string. The regular expression includes a capturing group directly next to escaped literal separators. If the engine returns false-positive matches, a sum can include series for parser-review or pre-parser that the rule intended to exclude.

Prometheus 3.13.6 includes a fix for false-positive regular-expression matches when a capturing group is adjacent to a literal. The release notes are headed December 2, 2026, while GitHub records publication on December 3. The upstream pull request identifies the affected matcher optimization. The practical implication is to test representative selectors when upgrading, especially rules whose totals depend on excluding near matches.

This article isolates the regex behavior from the release's other changes. It is not a comprehensive security-upgrade assessment. The companion uses promtool test rules with synthetic series and expected samples. It does not query a production server or claim an operational incident. An executable rule test is more useful than a screenshot showing that the regex looks plausible.

Write the intended set before writing the expression

Define four labels: |parser|, |lexer|parser|, |parser-review| and |pre-parser|. The intended selector includes the first two and excludes the last two. Give their metric values 5, 7, 40 and 11. The expected sum is therefore 12. A false-positive match is visible both in the selected series set and in the aggregate.

Testing only the sum is insufficient. Two errors can cancel numerically, and different series can carry equal values. Assert the exact label sets as well as the aggregate. This is particularly important for alerts, where a changed set can alter which component is blamed even when the overall total remains similar.

Use raw PromQL strings carefully in the YAML fixture so the backslash reaches the regex engine as intended. There are multiple parsing layers: YAML, PromQL string syntax and regular-expression syntax. A fixture that accidentally changes escaping can test a different expression. Preserve the exact file and run command alongside the result.

Build a minimal rule test

# Author: Sandeep Belgavi. Synthetic metric fixture.
rule_files: []
evaluation_interval: 1m
tests:
  - interval: 1m
    input_series:
      - series: 'artifact_backlog{components="|parser|"}'
        values: '5x3'
      - series: 'artifact_backlog{components="|lexer|parser|"}'
        values: '7x3'
      - series: 'artifact_backlog{components="|parser-review|"}'
        values: '40x3'
      - series: 'artifact_backlog{components="|pre-parser|"}'
        values: '11x3'
    promql_expr_test:
      - expr: 'sum(artifact_backlog{components=~`.*\|(parser)\|.*`})'
        eval_time: 2m
        exp_samples:
          - labels: '{}'
            value: 12

Run the fixture against pinned binaries for the previous and fixed versions. Record promtool --version, binary checksums and the full test output. A failed old-version test is useful evidence only if the same fixture passes in the fixed version and the expected semantics have been independently checked. Do not edit the expected value to make both versions pass.

The complete companion asserts selected series and includes a control expression without the redundant capturing group. The local fixture failed under promtool 3.13.5 and passed under 3.13.6; its recorded output retains both binary hashes and the fixture hash. The control helps isolate the triggering shape. This does not prove every rewritten regex is a safe workaround across all versions. Keep the conclusion tied to the exact tested expressions.

Separate regex meaning from optimizer behavior

The expression describes a component bounded by literal pipe characters, with arbitrary text before and after. The capturing group is unnecessary for this membership test; it groups the literal component name without consuming additional delimiters. A regex engine optimization must preserve that meaning. A false positive is an implementation error, not a different interpretation the application should accommodate.

When debugging, compare the intended set with the actual samples returned by the query engine. A standalone regex tester may confirm the expression's general meaning, but it does not exercise Prometheus's optimized matcher implementation. Use the actual affected binary for the regression test. Otherwise a test can pass while the deployed query remains wrong.

At the same time, do not blame every surprising selector result on this bug. Missing labels, empty-string matching, escaping and label-value design can produce legitimate surprises. Reduce the expression and fixture until the discrepancy is specific. A minimal failing case is easier to review than a large dashboard query containing several unrelated transformations.

Consider a better label model

A delimited set inside one label makes exact membership depend on string encoding. If the underlying measurement naturally belongs to one component, a plain component="parser" label is clearer. If one observation belongs to several components, decide whether emitting several series changes the aggregation semantics. A schema redesign can eliminate a regex dependency, but it can also double-count observations if applied mechanically.

Document the metric's unit and ownership. Is artifact_backlog a count of distinct artifacts, component associations or processing assignments? The same selector can be syntactically correct while summing a quantity the alert does not intend. A matcher fix addresses engine correctness; it does not resolve ambiguous metric semantics.

Do not introduce unbounded label values to make querying easier. An artifact identifier per series may create a cardinality problem. Choose bounded dimensions that support the intended aggregation and retain detailed identifiers in logs or traces when appropriate. The fixture uses a few fixed values to teach set membership, not to recommend arbitrary string sets as a metric schema.

Upgrade with semantic regression tests

Inventory recording and alerting rules that use regex matchers, then prioritize expressions with capturing groups adjacent to literals. Generate negative examples that are close to valid labels: prefixes, suffixes, missing separators and extra segments. These cases are more informative than another positive example matching the obvious path.

Run the rules against both binaries in a controlled environment and review changed outputs. Preserve the original expected semantics rather than treating the old binary as the oracle. The fixed version may legitimately alter an alert that depended on an erroneous match. Explain that change to the rule owner with the exact series difference and resulting aggregate.

Check the deployment's supported upgrade procedure and the release's full notes before changing servers. This article's fixture validates one query mechanism. It does not test storage replay, remote write, authentication, query load or every security fix in the release. Keep those checks in the deployment's normal validation process and record which version actually serves queries afterward.

Failure analysis and evidence limits

A rule-test pass proves the configured fixture produced the expected output in that binary. It does not establish that every live label is represented in the fixture. Add examples from the metric's documented schema and keep synthetic edge cases that exercise boundaries. When a new label form appears, update both the schema documentation and its regression tests.

Avoid summarizing the result as a percentage speedup or a broad reliability gain. The mechanism is correctness of set selection. Useful evidence consists of binary versions, fixture hash, selected labels and test exit status. Runtime may vary without affecting the conclusion, while one unexpected selected series invalidates it immediately.

For an alert, add a second fixture that evaluates the complete alerting rule across several timestamps. A selector-level test establishes membership at one instant; it does not test the rule's threshold, duration or behavior when series disappear. Keep that broader fixture distinct from the minimal matcher regression so a failure points to the correct layer. When reviewing results, inspect both the exact expression and the evaluation time rather than comparing screenshots from dashboards that may use different ranges.

The broader engineering habit is to test query semantics as code. Alerts and dashboards are executable decisions over data, and small library changes can expose assumptions hidden in strings. A compact synthetic fixture gives the upgrade a reviewable contract: these labels belong in the result, these near matches do not, and the expected aggregate follows from that set.

Primary references and authorship

Sources read December 4, 2026. Original explanations and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/promql_regex_adjacent_group. Views are my own and do not represent any employer, past or present.