Skip to content

Commit

Permalink
Fix TSDB store
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
  • Loading branch information
fpetkovski committed Jul 29, 2023
1 parent 9d4628b commit 0ea795e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
11 changes: 0 additions & 11 deletions pkg/receive/multitsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import (

"github.com/thanos-io/objstore"

"github.com/thanos-io/thanos/pkg/stringset"

"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/component"
"github.com/thanos-io/thanos/pkg/errutil"
Expand Down Expand Up @@ -109,15 +107,6 @@ func newLocalClient(c storepb.StoreClient, store *store.TSDBStore) *localClient
}
}

func (l *localClient) LabelNamesSet() stringset.Set {
labelNames, err := l.store.LabelNames(context.Background(), &storepb.LabelNamesRequest{})
if err != nil {
return stringset.AllStrings()
}

return stringset.NewFromStrings(labelNames.Names...)
}

func (l *localClient) LabelSets() []labels.Labels {
return labelpb.ZLabelSetsToPromLabelSets(l.store.LabelSet()...)
}
Expand Down
27 changes: 19 additions & 8 deletions pkg/store/tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package store

import (
"context"
"fmt"
"hash"
"io"
"math"
Expand Down Expand Up @@ -210,14 +211,15 @@ func (s *TSDBStore) Series(r *storepb.SeriesRequest, srv storepb.Store_SeriesSer
for _, lbl := range r.WithoutReplicaLabels {
extLsetToRemove[lbl] = struct{}{}
}
finalExtLset := rmLabels(s.extLset.Copy(), extLsetToRemove)

if s.labelNamesSet.HasAny(r.WithoutReplicaLabels) {
fmt.Println(r.WithoutReplicaLabels)

Check failure on line 216 in pkg/store/tsdb.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

declaration "Println" from package "fmt" shouldn't be used
if s.LabelNamesSet().HasAny(r.WithoutReplicaLabels) {
fmt.Println("resorting")

Check failure on line 218 in pkg/store/tsdb.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

declaration "Println" from package "fmt" shouldn't be used
rs := &resortingServer{Store_SeriesServer: srv}
defer rs.Flush()
srv = rs
}

finalExtLset := rmLabels(s.extLset.Copy(), extLsetToRemove)
// Stream at most one series per frame; series may be split over multiple frames according to maxBytesInFrame.
for set.Next() {
series := set.At()
Expand Down Expand Up @@ -383,18 +385,27 @@ func (s *TSDBStore) LabelValues(ctx context.Context, r *storepb.LabelValuesReque

func (s *TSDBStore) UpdateLabelNames(ctx context.Context) {
newSet := stringset.New()
labelNames, err := s.LabelNames(ctx, &storepb.LabelNamesRequest{})
q, err := s.db.ChunkQuerier(ctx, math.MinInt64, math.MaxInt64)
if err != nil {
level.Warn(s.logger).Log("msg", "error creating tsdb querier", "err", err.Error())
s.setLabelNamesSet(stringset.AllStrings())
return
}
defer runutil.CloseWithLogOnErr(s.logger, q, "close tsdb querier label names")

res, _, err := q.LabelNames()
if err != nil {
level.Warn(s.logger).Log("msg", "error getting label names", "err", err.Error())
s.lmx.Lock()
s.labelNamesSet = stringset.AllStrings()
s.lmx.Unlock()
s.setLabelNamesSet(stringset.AllStrings())
return
}
for _, l := range labelNames.Names {
for _, l := range res {
newSet.Insert(l)
}
s.setLabelNamesSet(newSet)
}

func (s *TSDBStore) setLabelNamesSet(newSet stringset.Set) {
s.lmx.Lock()
s.labelNamesSet = newSet
s.lmx.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion pkg/stringset/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (e mutableSet) HasAny(strings []string) bool {

type allStringsSet struct{}

func (e allStringsSet) HasAny(strings []string) bool {
func (e allStringsSet) HasAny(_ []string) bool {
return true
}

Expand Down
1 change: 1 addition & 0 deletions test/e2e/receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/prometheus/prometheus/model/relabel"

"github.com/efficientgo/core/testutil"

"github.com/thanos-io/thanos/pkg/promclient"
"github.com/thanos-io/thanos/pkg/receive"
"github.com/thanos-io/thanos/test/e2e/e2ethanos"
Expand Down

0 comments on commit 0ea795e

Please sign in to comment.