Skip to content

Commit

Permalink
store: don't create intermediate labels (#7762)
Browse files Browse the repository at this point in the history
Just compare labelpb.Label directly instead of creating promlabels from
them.

Signed-off-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
GiedriusS authored Sep 19, 2024
1 parent 1625665 commit 8cd3fae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions pkg/store/labelpb/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.

package labelpb

func CompareLabels(a, b []*Label) int {
l := len(a)
if len(b) < l {
l = len(b)
}

for i := 0; i < l; i++ {
if a[i].Name != b[i].Name {
if a[i].Name < b[i].Name {
return -1
}
return 1
}
if a[i].Value != b[i].Value {
if a[i].Value < b[i].Value {
return -1
}
return 1
}
}
// If all labels so far were in common, the set with fewer labels comes first.
return len(a) - len(b)
}
2 changes: 1 addition & 1 deletion pkg/store/proxy_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (d *responseDeduplicator) Next() bool {
lbls := d.bufferedSameSeries[0].GetSeries().Labels
atLbls := s.GetSeries().Labels

if labels.Compare(labelpb.LabelpbLabelsToPromLabels(lbls), labelpb.LabelpbLabelsToPromLabels(atLbls)) == 0 {
if labelpb.CompareLabels(lbls, atLbls) == 0 {
d.bufferedSameSeries = append(d.bufferedSameSeries, s)
continue
}
Expand Down

0 comments on commit 8cd3fae

Please sign in to comment.