Skip to content

Preserve upstream rate funcs as _rate when REPLACE_RATE_FUNCS is set - #26

Open
ColinDKelley wants to merge 2 commits into
invoca-2.55.1/align-yrate-to-3x-range-boundaryfrom
invoca-2.55.1/replace-rate-funcs-keep-orig
Open

Preserve upstream rate funcs as _rate when REPLACE_RATE_FUNCS is set#26
ColinDKelley wants to merge 2 commits into
invoca-2.55.1/align-yrate-to-3x-range-boundaryfrom
invoca-2.55.1/replace-rate-funcs-keep-orig

Conversation

@ColinDKelley

@ColinDKelleyColinDKelley commented Jul 8, 2026

Copy link
Copy Markdown

Summary

When REPLACE_RATE_FUNCS is x/X or 2/y/Y, keep the upstream Prometheus implementations available as _rate / _increase / _delta before repointing the standard names at the xrate or yrate family. Note that the xrate and yrate families are callable under their prefixed names in all cases.

Stacked on top of #20 (invoca-2.55.1/align-yrate-to-3x-range-boundary).

Why

With REPLACE_RATE_FUNCS=2, Grafana and existing queries calling rate / increase / delta get yrate semantics (desired). Operators still sometimes need a way to evaluate the original Prometheus extrapolators for comparison or escape hatches. Preserving them under underscored names keeps both available without inventing new function families.

Also fixes repointParserFunctions to copy the parser function struct instead of aliasing the pointer, so flipping the displayed name on rate does not rewrite the yrate entry's .Name.

Behavior with REPLACE_RATE_FUNCS=2

NameImplementation
rate / increase / deltayrate family
yrate / yincrease / ydeltastill available
xrate / xincrease / xdeltastill available
_rate / _increase / _deltaupstream originals

What changes

  • promql/functions.go: preserveOriginalRateFuncs + copy helpers; call them before repointing for the x/X and 2/y/Y cases; repointParserFunctions copies the struct.
  • promql/replace_rate_funcs_test.go: subprocess test that boots with REPLACE_RATE_FUNCS=2 and asserts the repoint / preserve pointers.

Test plan

@ColinDKelley
ColinDKelleyforce-pushed the invoca-2.55.1/align-yrate-to-3x-range-boundary branch from 4bf7c40 to fc4e2f3CompareJuly 8, 2026 23:16
@ColinDKelley
ColinDKelleyforce-pushed the invoca-2.55.1/replace-rate-funcs-keep-orig branch from 82a7847 to ce30e19CompareJuly 8, 2026 23:18
@ColinDKelley
ColinDKelley marked this pull request as ready for review July 9, 2026 00:16
Comment threadpromql/functions.go Outdated
Comment on lines +1971 to +1975
func copyParserFunction(fromName, toName string) {
result := *parser.Functions[fromName]
result.Name = toName
parser.Functions[toName] = &result
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a copy of repointParserFunctions but the arguments are reversed in how they are used? Maybe we consolidate them?

@ColinDKelleyColinDKelleyJul 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good call. I had asked the same thing! Cursor said they were different, so I moved on. But yeah, they're only different because of argument order. I pushed harder and now it's a lot simpler: 188621d

Comment threadpromql/functions.go Outdated
Comment on lines +1977 to +1979
func copyFunctionCall(fromName, toName string) {
FunctionCalls[toName] = FunctionCalls[fromName]
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a copy of repointFunction right, only difference is the order of the arguments?

@ColinDKelley
ColinDKelleyforce-pushed the invoca-2.55.1/align-yrate-to-3x-range-boundary branch from fc4e2f3 to e577fe0CompareJuly 9, 2026 22:27
@ColinDKelley
ColinDKelleyforce-pushed the invoca-2.55.1/replace-rate-funcs-keep-orig branch 2 times, most recently from 643268b to 9ee96b3CompareJuly 9, 2026 23:15
@ColinDKelley
ColinDKelleyforce-pushed the invoca-2.55.1/align-yrate-to-3x-range-boundary branch 2 times, most recently from 04db8ae to ac82c0aCompareJuly 10, 2026 00:04
@ColinDKelley
ColinDKelleyforce-pushed the invoca-2.55.1/replace-rate-funcs-keep-orig branch 2 times, most recently from ffaebb7 to db768cbCompareJuly 10, 2026 00:22
@ColinDKelley
ColinDKelleyforce-pushed the invoca-2.55.1/align-yrate-to-3x-range-boundary branch from ac82c0a to 366ca82CompareJuly 10, 2026 00:22
ColinDKelleyand others added 2 commits July 9, 2026 19:25
When REPLACE_RATE_FUNCS=x or =2, copy the original rate/increase/delta
parser and evaluator entries to _rate/_increase/_delta before repointing
the standard names at the xrate or yrate family. Fix repointParserFunctions
to copy the target struct so the source entry is not aliased.
Add TestReplaceRateFuncs2 to verify the registration layout in a subprocess
(REPLACE_RATE_FUNCS runs once at init).
Co-authored-by: Cursor <cursoragent@cursor.com>
Unify copyParserFunction/copyFunctionCall with repointParserFunctions/
repointFunction via setParserFunctionFrom and setFunctionCallFrom, then
call those helpers directly from init().
Co-authored-by: Cursor <cursoragent@cursor.com>
@ColinDKelley
ColinDKelleyforce-pushed the invoca-2.55.1/replace-rate-funcs-keep-orig branch from 3a55e7c to 66de80aCompareJuly 10, 2026 02:27
@ColinDKelley
ColinDKelleyforce-pushed the invoca-2.55.1/align-yrate-to-3x-range-boundary branch from 366ca82 to 8e94af7CompareJuly 10, 2026 02:27
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@ColinDKelley@ttstarck