Skip to content

Conversation

charleskorn
Copy link
Contributor

@charleskorn charleskorn commented Feb 3, 2025

What this PR does

This PR fixes a bug where MQE's implementation of group_left / group_right could sometimes return incorrect labels for a series.

In particular, this could happen if the number of additional labels in the group_left(...) or group_right(...) modifier was not a power of two. VectorMatching.Include was effectively being mutated in manySideGroupKeyFunc to include __name__ and drop the last label (rather than being copied to a new slice with __name__ appended), and so the incorrect set of additional label names was used in outputSeriesLabelsFunc.

If the list of additional labels had a length that was a power of two, then the append in manySideGroupKeyFunc caused a new underlying array to be created and so the bug was not triggered.

Which issue(s) this PR fixes or relates to

(none)

Checklist

  • Tests updated.
  • [n/a] Documentation added.
  • [covered by Mimir Query Engine #10067] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • [n/a] about-versioning.md updated with experimental features.

@charleskorn charleskorn marked this pull request as ready for review February 3, 2025 03:29
@charleskorn charleskorn requested a review from a team as a code owner February 3, 2025 03:29
Copy link
Contributor

@jhesketh jhesketh left a comment

Choose a reason for hiding this comment

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

Nice solve.

@@ -416,7 +416,9 @@ func (g *GroupedVectorVectorBinaryOperation) manySideGroupKeyFunc() func(manySid
labelsToRemove := g.VectorMatching.Include

if g.shouldRemoveMetricNameFromManySide() {
labelsToRemove = make([]string, 0, len(g.VectorMatching.Include)+1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this change, but should we consider using a string pool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be interesting to try, but I suspect the impact will be small given we tend to only use string slices for things that are created once per query (eg. this list of label names).

@charleskorn charleskorn merged commit 3cf0d49 into main Feb 3, 2025
28 checks passed
@charleskorn charleskorn deleted the charleskorn/mqe-group-left-right-bug branch February 3, 2025 04:35
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.

2 participants