Skip to content

Commit

Permalink
Optimize zlabel usage for stringlabels
Browse files Browse the repository at this point in the history
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 <filip.petkovsky@gmail.com>
  • Loading branch information
fpetkovski committed Jan 29, 2025
1 parent 2367777 commit 8d0f284
Show file tree
Hide file tree
Showing 11 changed files with 740 additions and 467 deletions.
2 changes: 1 addition & 1 deletion cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ func runRule(
infoOptions = append(
infoOptions,
info.WithLabelSetFunc(func() []labelpb.ZLabelSet {
return tsdbStore.LabelSet()
return labelpb.ZLabelSetsFromPromLabels(tsdbStore.LabelSet()...)
}),
info.WithStoreInfoFunc(func() (*infopb.StoreInfo, error) {
if httpProbe.IsReady() {
Expand Down
13 changes: 5 additions & 8 deletions pkg/receive/multitsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package receive

import (
"context"
"fmt"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -217,7 +216,7 @@ func (l *localClient) Matches(matchers []*labels.Matcher) bool {
}

func (l *localClient) LabelSets() []labels.Labels {
return labelpb.ZLabelSetsToPromLabelSets(l.store.LabelSet()...)
return l.store.LabelSet()
}

func (l *localClient) TimeRange() (mint int64, maxt int64) {
Expand All @@ -233,19 +232,17 @@ func (l *localClient) TSDBInfos() []infopb.TSDBInfo {
mint, maxt := l.store.TimeRange()
return []infopb.TSDBInfo{
{
Labels: labelsets[0],
Labels: labelpb.ZLabelSet{
Labels: labelpb.ZLabelsFromPromLabels(labelsets[0]),
},
MinTime: mint,
MaxTime: maxt,
},
}
}

func (l *localClient) String() string {
mint, maxt := l.store.TimeRange()
return fmt.Sprintf(
"LabelSets: %v MinTime: %d MaxTime: %d",
labelpb.PromLabelSetsToString(l.LabelSets()), mint, maxt,
)
return l.store.String()
}

func (l *localClient) Addr() (string, bool) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/receive/receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/store"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/testutil/custom"
)

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

expectedClientLabelSets := labelpb.ZLabelSetsToPromLabelSets(testStore.LabelSet()...)
expectedClientLabelSets := testStore.LabelSet()
setOfExpectedClientLabelSets = append(setOfExpectedClientLabelSets, expectedClientLabelSets)

actualClientLabelSets := actualStoreClients[i].LabelSets()
Expand Down
Loading

0 comments on commit 8d0f284

Please sign in to comment.