Skip to content

Commit

Permalink
[store] Add Request Hints for Labels APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Goutham Veeramachaneni <[email protected]>
  • Loading branch information
gouthamve committed Nov 19, 2020
1 parent 7ff9ba1 commit 6b2d465
Show file tree
Hide file tree
Showing 6 changed files with 643 additions and 75 deletions.
34 changes: 34 additions & 0 deletions pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,11 +1074,28 @@ func (s *BucketStore) LabelNames(ctx context.Context, req *storepb.LabelNamesReq

var mtx sync.Mutex
var sets [][]string
var reqBlockMatchers []*labels.Matcher

if req.Hints != nil {
reqHints := &hintspb.LabelNamesRequestHints{}
err := types.UnmarshalAny(req.Hints, reqHints)
if err != nil {
return nil, status.Error(codes.InvalidArgument, errors.Wrap(err, "unmarshal label names request hints").Error())
}

reqBlockMatchers, err = storepb.TranslateFromPromMatchers(reqHints.BlockMatchers...)
if err != nil {
return nil, status.Error(codes.InvalidArgument, errors.Wrap(err, "translate request hints labels matchers").Error())
}
}

for _, b := range s.blocks {
if !b.overlapsClosedInterval(req.Start, req.End) {
continue
}
if len(reqBlockMatchers) > 0 && !b.matchRelabelLabels(reqBlockMatchers) {
continue
}

resHints.AddQueriedBlock(b.meta.ULID)

Expand Down Expand Up @@ -1141,11 +1158,28 @@ func (s *BucketStore) LabelValues(ctx context.Context, req *storepb.LabelValuesR

var mtx sync.Mutex
var sets [][]string
var reqBlockMatchers []*labels.Matcher

if req.Hints != nil {
reqHints := &hintspb.LabelValuesRequestHints{}
err := types.UnmarshalAny(req.Hints, reqHints)
if err != nil {
return nil, status.Error(codes.InvalidArgument, errors.Wrap(err, "unmarshal label names request hints").Error())
}

reqBlockMatchers, err = storepb.TranslateFromPromMatchers(reqHints.BlockMatchers...)
if err != nil {
return nil, status.Error(codes.InvalidArgument, errors.Wrap(err, "translate request hints labels matchers").Error())
}
}

for _, b := range s.blocks {
if !b.overlapsClosedInterval(req.Start, req.End) {
continue
}
if len(reqBlockMatchers) > 0 && !b.matchRelabelLabels(reqBlockMatchers) {
continue
}

resHints.AddQueriedBlock(b.meta.ULID)

Expand Down
35 changes: 35 additions & 0 deletions pkg/store/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,41 @@ func TestLabelNamesAndValuesHints(t *testing.T) {
{Id: block2.String()},
},
},
}, {
name: "querying a range containing multiple blocks but filtering a specific block should query only the requested block",

labelNamesReq: &storepb.LabelNamesRequest{
Start: 0,
End: 3,
Hints: mustMarshalAny(&hintspb.LabelNamesRequestHints{
BlockMatchers: []storepb.LabelMatcher{
{Type: storepb.LabelMatcher_EQ, Name: block.BlockIDLabel, Value: block1.String()},
},
}),
},
expectedNames: labelNamesFromSeriesSet(seriesSet1),
expectedNamesHints: hintspb.LabelNamesResponseHints{
QueriedBlocks: []hintspb.Block{
{Id: block1.String()},
},
},

labelValuesReq: &storepb.LabelValuesRequest{
Label: "ext1",
Start: 0,
End: 3,
Hints: mustMarshalAny(&hintspb.LabelValuesRequestHints{
BlockMatchers: []storepb.LabelMatcher{
{Type: storepb.LabelMatcher_EQ, Name: block.BlockIDLabel, Value: block1.String()},
},
}),
},
expectedValues: []string{"1"},
expectedValuesHints: hintspb.LabelValuesResponseHints{
QueriedBlocks: []hintspb.Block{
{Id: block1.String()},
},
},
},
}

Expand Down
Loading

0 comments on commit 6b2d465

Please sign in to comment.