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

store: Add Request Hints for Labels APIs #3469

Merged
merged 1 commit into from
Nov 19, 2020
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
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())
Copy link
Contributor

Choose a reason for hiding this comment

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

unmarshal label names request hints

Should be "label values request hints"

}

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