Skip to content

Commit

Permalink
[store] Add Request Hints for Labels APIs (#3469)
Browse files Browse the repository at this point in the history
Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
  • Loading branch information
gouthamve committed Nov 19, 2020
1 parent fe123b2 commit c73143d
Show file tree
Hide file tree
Showing 7 changed files with 644 additions and 75 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ We use _breaking :warning:_ to mark changes that are not backward compatible (re
- [#3431](https://github.com/thanos-io/thanos/pull/3431) Store: Added experimental support to lazy load index-headers at query time. When enabled via `--store.enable-index-header-lazy-reader` flag, the store-gateway will load into memory an index-header only once it's required at query time. Index-header will be automatically released after `--store.index-header-lazy-reader-idle-timeout` of inactivity.
- This, generally, reduces baseline memory usage of store when inactive, as well as a total number of mapped files (which is limited to 64k in some systems.
- [#3437](https://github.com/thanos-io/thanos/pull/3437) StoreAPI: Added `hints` field to `LabelNamesResponse` and `LabelValuesResponse`. Hints in an opaque data structure that can be used to carry additional information from the store and its content is implementation specific.
- [#3469](https://github.com/thanos-io/thanos/pull/3469) StoreAPI: Added `hints` field to `LabelNamesRequest` and `LabelValuesRequest`. Hints in an opaque data structure that can be used to carry additional information from the store and its content is implementation specific.

### Fixed

Expand Down
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 c73143d

Please sign in to comment.