Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: infinite loop in index writer #3356

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

kolesnikovae
Copy link
Collaborator

@kolesnikovae kolesnikovae commented Jun 14, 2024

Manual backporting of prometheus/prometheus#12505. Thanks @pracucci!

I only wonder why it took so long to surface.

Comment on lines +71 to +106
func Test_LabelsBuilder_Unique(t *testing.T) {
tests := []struct {
name string
input Labels
add Labels
expected Labels
}{
{
name: "duplicates in input are preserved",
input: Labels{
{Name: "unique", Value: "yes"},
{Name: "unique", Value: "no"},
},
add: Labels{
{Name: "foo", Value: "bar"},
{Name: "foo", Value: "baz"},
},
expected: Labels{
{Name: "foo", Value: "baz"},
{Name: "unique", Value: "yes"},
{Name: "unique", Value: "no"},
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
builder := NewLabelsBuilder(test.input)
for _, l := range test.add {
builder.Set(l.Name, l.Value)
}
assert.Equal(t, test.expected, builder.Labels())
})
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do not see any practical sense in fixing LabelsBuilder we borrowed from prometheus. Instead, in our case, a reusable map would work way better (and I'm 99.(9)% sure, more efficiently).

To be addressed in a separate PR.

image

@@ -60,6 +60,7 @@ func CreateProfileLabels(enforceOrder bool, p *profilev1.Profile, externalLabels
} else {
sort.Sort(lbs)
}
lbs = lbs.Unique()
Copy link
Collaborator Author

@kolesnikovae kolesnikovae Jun 14, 2024

Choose a reason for hiding this comment

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

Just in case: Unique works fine with LabelsEnforcedOrder

@kolesnikovae kolesnikovae marked this pull request as ready for review June 14, 2024 08:36
@kolesnikovae kolesnikovae requested a review from a team as a code owner June 14, 2024 08:36
@kolesnikovae kolesnikovae merged commit 251d619 into main Jun 18, 2024
16 checks passed
@kolesnikovae kolesnikovae deleted the fix/infinite-loop-in-index-writer branch June 18, 2024 03:49
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