Skip to content

bugfix: reduceSeries honors aliased names#933

Merged
npazosmendez merged 4 commits into
go-graphite:mainfrom
majedrze:work-reduceSeries-bug
Jun 26, 2026
Merged

bugfix: reduceSeries honors aliased names#933
npazosmendez merged 4 commits into
go-graphite:mainfrom
majedrze:work-reduceSeries-bug

Conversation

@majedrze

@majedrze majedrze commented May 29, 2026

Copy link
Copy Markdown
Contributor

Describe the bug
Applying reduce() function after any alias* family function results in an empty result. reduceSeries derives the grouping keys from series.Tags["name"] instead of series.Name, but alias function intentionally operate on (as far as I am able to understand) series.Name.
This causes the matchers to match against the original series name, and not the aliased series name, which in turn produce an empty (or in some corner cases) straight up wrong result.

AFAIU this behaviour is not in line with graphite-web and is a correctness bug. The bug was introduced in this refactor: 0d4ebf3

CarbonAPI Version
master

Simplified query (if applicable)

assume series like:

servers.us.dc1.host01.cpu.raw_used
servers.us.dc1.host01.cpu.raw_total
servers.us.dc1.host02.cpu.raw_used
servers.us.dc1.host02.cpu.raw_total
...

use the following query:

group(
  aliasSub(aliasByNode(servers.us.dc1.host[0-9]*.cpu.raw_used,  3, 5), 'raw_used',  'cpu.actual'),
  aliasSub(aliasByNode(servers.us.dc1.host[0-9]*.cpu.raw_total, 3, 5), 'raw_total', 'cpu.max')
) | reduceSeries('asPercent', 2, 'actual', 'max')

expected result is two reduced series.
actual result is empty due to the bug.

Additional context
The patch works for me, because I am not using tags. But I am unsure on how to handle them in this function.

Should you be able to reduce on tags? Any input on this would be appreciated.

For now, I used ExtractName utility function and I think it should work in the general case for matching on metric name, but not on tags.

@teqwve

teqwve commented Jun 11, 2026

Copy link
Copy Markdown

It looks like the applyByNode function has the same issue.

npazosmendez
npazosmendez previously approved these changes Jun 24, 2026

@npazosmendez npazosmendez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This makes sense to me

I can take care of adding a test. I am tackling another bug in this same function here #936

npazosmendez added a commit that referenced this pull request Jun 24, 2026
Builds on #933 (reduce on series.Name). Adds a bounds guard so an out-of-range reduceNode returns an error instead of panicking, and supports negative indices counted from the end.

Adds a reduce package test covering the aliased-name grouping (the #933 fix) and the out-of-range cases, and updates the existing reduceSeries expectations for the name tag now set by CopyNameWithVal.
@npazosmendez

Copy link
Copy Markdown
Collaborator

Looks like some tests are failing, would you mind taking a look @majedrze ?

@majedrze

majedrze commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@npazosmendez sure, tests should be clean now. I also fixed applyByNode as per @teqwve suggestion.

@npazosmendez

Copy link
Copy Markdown
Collaborator

Thank you! I do not see a fix for applyByNode though, did you forget to push that?
I will merge this as is now, feel free to send another PR

@npazosmendez npazosmendez merged commit e748c51 into go-graphite:main Jun 26, 2026
9 checks passed
npazosmendez added a commit that referenced this pull request Jun 26, 2026
Builds on #933 (reduce on series.Name). Adds a bounds guard so an out-of-range reduceNode returns an error instead of panicking, and supports negative indices counted from the end.

Adds a reduce package test covering the aliased-name grouping (the #933 fix) and the out-of-range cases, and updates the existing reduceSeries expectations for the name tag now set by CopyNameWithVal.
Sign up for free to 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.

3 participants