Skip to content

Register xfunctions in global parser for rule file loading#7621

Open
PaurushGarg wants to merge 1 commit into
cortexproject:masterfrom
PaurushGarg:fix-ruler-xfunctions-loading
Open

Register xfunctions in global parser for rule file loading#7621
PaurushGarg wants to merge 1 commit into
cortexproject:masterfrom
PaurushGarg:fix-ruler-xfunctions-loading

Conversation

@PaurushGarg

@PaurushGarg PaurushGarg commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

What this PR does:
When the Thanos engine xfunctions flag is enabled, the ruler's query engine
correctly supports xincrease/xrate/xdelta for evaluating expressions. However,
the rule file loader (rulefmt.ParseFile) uses the global parser.Functions
registry which did not include xfunctions. This caused the ruler to silently
drop recording rules containing xfunctions during S3/disk loading.

Fix: Register xfunctions in parser.Functions at ruler startup when
-querier.enable-x-functions=true, so rulefmt.ParseFile can parse rule
expressions that use these functions.

Which issue(s) this PR fixes:

Checklist:

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated
  • docs/configuration/v1-guarantees.md updated (not applicable - no new flags)

@PaurushGarg PaurushGarg force-pushed the fix-ruler-xfunctions-loading branch 2 times, most recently from e73662c to f97c199 Compare June 12, 2026 00:57
Signed-off-by: Paurush Garg <paurushg@amazon.com>
@PaurushGarg PaurushGarg force-pushed the fix-ruler-xfunctions-loading branch from f97c199 to e3052e3 Compare June 12, 2026 01:12
@PaurushGarg PaurushGarg marked this pull request as ready for review June 12, 2026 01:29
@dosubot dosubot Bot added component/rules Bits & bobs todo with rules and alerts: the ruler, config service etc. go Pull requests that update Go code type/bug labels Jun 12, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 12, 2026
Comment thread pkg/cortex/modules.go
Comment on lines +667 to +670
// Register xfunctions (xincrease, xrate, xdelta) in the global parser
if t.Cfg.Querier.ThanosEngine.EnableXFunctions {
maps.Copy(parser.Functions, parse.XFunctions)
}

@SungJin1212 SungJin1212 Jun 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Register xfunctions (xincrease, xrate, xdelta) in the global parser
if t.Cfg.Querier.ThanosEngine.EnableXFunctions {
maps.Copy(parser.Functions, parse.XFunctions)
}
// Register xfunctions (xincrease, xrate, xdelta) in the global parser
if t.Cfg.Querier.ThanosEngine.Enabled && t.Cfg.Querier.ThanosEngine.EnableXFunctions {
maps.Copy(parser.Functions, parse.XFunctions)
}

nit: should we add an enabled condition?

Comment thread CHANGELOG.md
* [FEATURE] Querier: Add timeout classification to classify query timeouts as 4XX (user error) or 5XX (system error) based on phase timing. When enabled, queries that spend most of their time in PromQL evaluation return `422 Unprocessable Entity` instead of `503 Service Unavailable`. #7374
* [FEATURE] Querier: Implement Resource Based Throttling in Querier. #7442
* [FEATURE] Querier: Add resource-based query eviction that automatically cancels the heaviest running query when CPU or heap utilization exceeds configured thresholds. #7488
* [BUGFIX] Ruler: Register xfunctions (xincrease, xrate, xdelta) in the global parser before loading rule files. #7621

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changelog entry needs to be properly sorted

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

Labels

component/rules Bits & bobs todo with rules and alerts: the ruler, config service etc. go Pull requests that update Go code lgtm This PR has been approved by a maintainer size/M type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants