Skip to content

Commit 8d0f284

Browse files
committed
Optimize zlabel usage for stringlabels
Using the ZLabelsToPromLabels hack is no longer free with stringlabels because the in-memory format of the two types is different. Because of this, using a stringlabels build in the Receiver can be more CPU intensive than the normal build. In order to allow for an efficient usage of stringlabels, this commit removes `ZLabelsToPromLabels` calls in TSDBStore and ProxyStore. There is now a specialized implementation of ZLabel conversion functions with a stringlabels build tag in order to avoid panics, but long term we should get rid of these functions if possible. Signed-off-by: Filip Petkovski <[email protected]>
1 parent 2367777 commit 8d0f284

11 files changed

+740
-467
lines changed

cmd/thanos/rule.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ func runRule(
726726
infoOptions = append(
727727
infoOptions,
728728
info.WithLabelSetFunc(func() []labelpb.ZLabelSet {
729-
return tsdbStore.LabelSet()
729+
return labelpb.ZLabelSetsFromPromLabels(tsdbStore.LabelSet()...)
730730
}),
731731
info.WithStoreInfoFunc(func() (*infopb.StoreInfo, error) {
732732
if httpProbe.IsReady() {

pkg/receive/multitsdb.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package receive
55

66
import (
77
"context"
8-
"fmt"
98
"os"
109
"path"
1110
"path/filepath"
@@ -217,7 +216,7 @@ func (l *localClient) Matches(matchers []*labels.Matcher) bool {
217216
}
218217

219218
func (l *localClient) LabelSets() []labels.Labels {
220-
return labelpb.ZLabelSetsToPromLabelSets(l.store.LabelSet()...)
219+
return l.store.LabelSet()
221220
}
222221

223222
func (l *localClient) TimeRange() (mint int64, maxt int64) {
@@ -233,19 +232,17 @@ func (l *localClient) TSDBInfos() []infopb.TSDBInfo {
233232
mint, maxt := l.store.TimeRange()
234233
return []infopb.TSDBInfo{
235234
{
236-
Labels: labelsets[0],
235+
Labels: labelpb.ZLabelSet{
236+
Labels: labelpb.ZLabelsFromPromLabels(labelsets[0]),
237+
},
237238
MinTime: mint,
238239
MaxTime: maxt,
239240
},
240241
}
241242
}
242243

243244
func (l *localClient) String() string {
244-
mint, maxt := l.store.TimeRange()
245-
return fmt.Sprintf(
246-
"LabelSets: %v MinTime: %d MaxTime: %d",
247-
labelpb.PromLabelSetsToString(l.LabelSets()), mint, maxt,
248-
)
245+
return l.store.String()
249246
}
250247

251248
func (l *localClient) Addr() (string, bool) {

pkg/receive/receive_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
"github.com/thanos-io/thanos/pkg/block/metadata"
1818
"github.com/thanos-io/thanos/pkg/store"
19-
"github.com/thanos-io/thanos/pkg/store/labelpb"
2019
"github.com/thanos-io/thanos/pkg/testutil/custom"
2120
)
2221

@@ -835,7 +834,7 @@ func setupSetsOfExpectedAndActualStoreClientLabelSets(
835834
testStore := store.TSDBStore{}
836835
testStore.SetExtLset(expectedExternalLabelSets[i])
837836

838-
expectedClientLabelSets := labelpb.ZLabelSetsToPromLabelSets(testStore.LabelSet()...)
837+
expectedClientLabelSets := testStore.LabelSet()
839838
setOfExpectedClientLabelSets = append(setOfExpectedClientLabelSets, expectedClientLabelSets)
840839

841840
actualClientLabelSets := actualStoreClients[i].LabelSets()

0 commit comments

Comments
 (0)