Skip to content

Conversation

@yeya24
Copy link
Contributor

@yeya24 yeya24 commented Jan 7, 2026

What this PR does:

Unoptimized regex matchers in PromQL queries can be extremely expensive to evaluate, especially when applied to high-cardinality labels. These queries can cause significant resource consumption and impact cluster performance. While Prometheus optimizes certain regex patterns (like .*, .+, prefix/suffix matches), unoptimized patterns must be evaluated against every label value, making the cost proportional to:

  • The complexity of the regex pattern
  • The cardinality of the label
  • The total length of all label values
    This PR introduces per-tenant configurable limits to reject such expensive queries before they consume excessive resources.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@dosubot dosubot bot added the type/production Issues related to the production use of Cortex, inc. configuration, alerting and operating. label Jan 7, 2026
Signed-off-by: Ben Ye <[email protected]>
@yeya24 yeya24 force-pushed the reject-regex-matcher-cardinality branch from f4840f7 to 102732d Compare January 7, 2026 18:51
@pull-request-size pull-request-size bot added size/XL and removed size/L labels Jan 8, 2026
yeya24 added 2 commits January 8, 2026 01:21
Signed-off-by: Ben Ye <[email protected]>
Signed-off-by: yeya24 <[email protected]>
yeya24 added 2 commits January 7, 2026 18:16
Signed-off-by: yeya24 <[email protected]>
Signed-off-by: yeya24 <[email protected]>
Copy link
Contributor

@danielblando danielblando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Copy link
Member

@friedrichg friedrichg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 9, 2026
@yeya24 yeya24 merged commit fd56451 into cortexproject:master Jan 9, 2026
97 of 102 checks passed
@yeya24 yeya24 deleted the reject-regex-matcher-cardinality branch January 9, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size/XL type/production Issues related to the production use of Cortex, inc. configuration, alerting and operating.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants