From 2dbdad3b7cf922d77c3fa4ede0e10778df1025c1 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Wed, 11 May 2022 15:22:09 +0530 Subject: [PATCH 1/3] query both downloads and uploads manager when non-nil --- pkg/storage/stores/indexshipper/shipper.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/storage/stores/indexshipper/shipper.go b/pkg/storage/stores/indexshipper/shipper.go index fd433c424be29..335a10f15eb33 100644 --- a/pkg/storage/stores/indexshipper/shipper.go +++ b/pkg/storage/stores/indexshipper/shipper.go @@ -139,11 +139,15 @@ func (s *indexShipper) AddIndex(tableName, userID string, index index.Index) err func (s *indexShipper) ForEach(ctx context.Context, tableName, userID string, callback func(index index.Index) error) error { if s.downloadsManager != nil { - return s.downloadsManager.ForEach(ctx, tableName, userID, callback) + if err := s.downloadsManager.ForEach(ctx, tableName, userID, callback); err != nil { + return err + } } if s.uploadsManager != nil { - return s.uploadsManager.ForEach(tableName, userID, callback) + if err := s.uploadsManager.ForEach(tableName, userID, callback); err != nil { + return err + } } return nil From a034e5c94e02f16034cfefa4728a70386fd79800 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Wed, 11 May 2022 15:23:05 +0530 Subject: [PATCH 2/3] fix reading of index file with nodename having a `-` --- pkg/storage/stores/tsdb/identifier.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/storage/stores/tsdb/identifier.go b/pkg/storage/stores/tsdb/identifier.go index 14f9cf69ec59d..1c138adc7d387 100644 --- a/pkg/storage/stores/tsdb/identifier.go +++ b/pkg/storage/stores/tsdb/identifier.go @@ -186,7 +186,7 @@ func parseMultitenantTSDBNameFromBase(name string) (res MultitenantTSDBIdentifie } xs := strings.Split(trimmed, "-") - if len(xs) != 2 { + if len(xs) < 2 { return } @@ -197,6 +197,6 @@ func parseMultitenantTSDBNameFromBase(name string) (res MultitenantTSDBIdentifie return MultitenantTSDBIdentifier{ ts: time.Unix(int64(ts), 0), - nodeName: xs[1], + nodeName: strings.Join(xs[1:], "-"), }, true } From 8f4172fdf1fe75545e4d1e7e7b181949d8ef61d5 Mon Sep 17 00:00:00 2001 From: Sandeep Sukhani Date: Wed, 11 May 2022 15:36:00 +0530 Subject: [PATCH 3/3] remove __name__ matcher at a layer above to avoid passing it during tsdb head queries --- pkg/storage/stores/tsdb/index_client.go | 25 +++++++++++++++++++++++-- pkg/storage/stores/tsdb/manager.go | 22 ---------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/pkg/storage/stores/tsdb/index_client.go b/pkg/storage/stores/tsdb/index_client.go index d683c81fb6963..08f3d652ee099 100644 --- a/pkg/storage/stores/tsdb/index_client.go +++ b/pkg/storage/stores/tsdb/index_client.go @@ -57,6 +57,7 @@ func (c *IndexClient) shard(matchers ...*labels.Matcher) ([]*labels.Matcher, *in // They share almost the same fields, so we can add the missing `KB` field to the proto and then // use that within the tsdb package. func (c *IndexClient) GetChunkRefs(ctx context.Context, userID string, from, through model.Time, matchers ...*labels.Matcher) ([]logproto.ChunkRef, error) { + matchers = withoutNameLabel(matchers) matchers, shard, err := c.shard(matchers...) if err != nil { return nil, err @@ -83,6 +84,7 @@ func (c *IndexClient) GetChunkRefs(ctx context.Context, userID string, from, thr } func (c *IndexClient) GetSeries(ctx context.Context, userID string, from, through model.Time, matchers ...*labels.Matcher) ([]labels.Labels, error) { + matchers = withoutNameLabel(matchers) matchers, shard, err := c.shard(matchers...) if err != nil { return nil, err @@ -101,12 +103,13 @@ func (c *IndexClient) GetSeries(ctx context.Context, userID string, from, throug } // tsdb no longer uses the __metric_name__="logs" hack, so we can ignore metric names! -func (c *IndexClient) LabelValuesForMetricName(ctx context.Context, userID string, from, through model.Time, metricName string, labelName string, matchers ...*labels.Matcher) ([]string, error) { +func (c *IndexClient) LabelValuesForMetricName(ctx context.Context, userID string, from, through model.Time, _ string, labelName string, matchers ...*labels.Matcher) ([]string, error) { + matchers = withoutNameLabel(matchers) return c.idx.LabelValues(ctx, userID, from, through, labelName, matchers...) } // tsdb no longer uses the __metric_name__="logs" hack, so we can ignore metric names! -func (c *IndexClient) LabelNamesForMetricName(ctx context.Context, userID string, from, through model.Time, metricName string) ([]string, error) { +func (c *IndexClient) LabelNamesForMetricName(ctx context.Context, userID string, from, through model.Time, _ string) ([]string, error) { return c.idx.LabelNames(ctx, userID, from, through) } @@ -116,3 +119,21 @@ func (c *IndexClient) LabelNamesForMetricName(ctx context.Context, userID string func (c *IndexClient) SetChunkFilterer(chunkFilter chunk.RequestChunkFilterer) { c.idx.SetChunkFilterer(chunkFilter) } + +// TODO(owen-d): in the future, handle this by preventing passing the __name__="logs" label +// to TSDB indices at all. +func withoutNameLabel(matchers []*labels.Matcher) []*labels.Matcher { + if len(matchers) == 0 { + return nil + } + + dst := make([]*labels.Matcher, 0, len(matchers)-1) + for _, m := range matchers { + if m.Name == labels.MetricName { + continue + } + dst = append(dst, m) + } + + return dst +} diff --git a/pkg/storage/stores/tsdb/manager.go b/pkg/storage/stores/tsdb/manager.go index 5b9cffc4abe96..f96d6f3b9a0a0 100644 --- a/pkg/storage/stores/tsdb/manager.go +++ b/pkg/storage/stores/tsdb/manager.go @@ -318,7 +318,6 @@ func (m *tsdbManager) GetChunkRefs(ctx context.Context, userID string, from, thr if err != nil { return nil, err } - matchers = withoutNameLabel(matchers) return idx.GetChunkRefs(ctx, userID, from, through, res, shard, matchers...) } @@ -327,7 +326,6 @@ func (m *tsdbManager) Series(ctx context.Context, userID string, from, through m if err != nil { return nil, err } - matchers = withoutNameLabel(matchers) return idx.Series(ctx, userID, from, through, res, shard, matchers...) } @@ -336,7 +334,6 @@ func (m *tsdbManager) LabelNames(ctx context.Context, userID string, from, throu if err != nil { return nil, err } - matchers = withoutNameLabel(matchers) return idx.LabelNames(ctx, userID, from, through, matchers...) } @@ -345,24 +342,5 @@ func (m *tsdbManager) LabelValues(ctx context.Context, userID string, from, thro if err != nil { return nil, err } - matchers = withoutNameLabel(matchers) return idx.LabelValues(ctx, userID, from, through, name, matchers...) } - -// TODO(owen-d): in the future, handle this by preventing passing the __name__="logs" label -// to TSDB indices at all. -func withoutNameLabel(matchers []*labels.Matcher) []*labels.Matcher { - if len(matchers) == 0 { - return nil - } - - dst := make([]*labels.Matcher, 0, len(matchers)-1) - for _, m := range matchers { - if m.Name == labels.MetricName { - continue - } - dst = append(dst, m) - } - - return dst -}