Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsdb query fixes #6142

Merged
merged 3 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/storage/stores/indexshipper/shipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was by design: only using either the downloads mgr or the uploads mgr so we didn't query the same indices in R/W mode for the shipper.

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
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/stores/tsdb/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func parseMultitenantTSDBNameFromBase(name string) (res MultitenantTSDBIdentifie
}

xs := strings.Split(trimmed, "-")
if len(xs) != 2 {
if len(xs) < 2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

return
}

Expand All @@ -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
}
25 changes: 23 additions & 2 deletions pkg/storage/stores/tsdb/index_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}

Expand All @@ -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
}
22 changes: 0 additions & 22 deletions pkg/storage/stores/tsdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}

Expand All @@ -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...)
}

Expand All @@ -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...)
}

Expand All @@ -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
}