Skip to content

Commit

Permalink
allow empty matcher at store gateway to fetch all postings
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <benye@amazon.com>
  • Loading branch information
yeya24 committed Apr 5, 2024
1 parent 3048d99 commit b3fc96d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/store/bucket.go
Expand Up @@ -112,6 +112,7 @@ const (
var (
errBlockSyncConcurrencyNotValid = errors.New("the block sync concurrency must be equal or greater than 1.")
hashPool = sync.Pool{New: func() interface{} { return xxhash.New() }}
allPostingMatcher = labels.MustNewMatcher(labels.MatchEqual, "", "")
)

type bucketStoreMetrics struct {
Expand Down Expand Up @@ -1478,6 +1479,11 @@ func (s *BucketStore) Series(req *storepb.SeriesRequest, seriesSrv storepb.Store
if !ok {
continue
}
// If no matcher left after removing external label matchers,
// fallback to use all posting matcher.
if len(blockMatchers) == 0 {
blockMatchers = []*labels.Matcher{allPostingMatcher}
}
// Sort matchers to make sure we generate the same cache key
// when fetching expanded postings.
sortedBlockMatchers := newSortedMatchers(blockMatchers)
Expand Down
46 changes: 46 additions & 0 deletions pkg/store/bucket_e2e_test.go
Expand Up @@ -464,6 +464,23 @@ func testBucketStore_e2e(t *testing.T, ctx context.Context, s *storeSuite) {
{{Name: "a", Value: "1"}, {Name: "c", Value: "2"}, {Name: "ext2", Value: "value2"}},
},
},
// External label only. Should fetch all series matching external label.
{
req: &storepb.SeriesRequest{
Matchers: []storepb.LabelMatcher{
{Type: storepb.LabelMatcher_EQ, Name: "ext1", Value: "value1"},
},
MinTime: mint,
MaxTime: maxt,
},
expectedChunkLen: 3,
expected: [][]labelpb.ZLabel{
{{Name: "a", Value: "1"}, {Name: "b", Value: "1"}, {Name: "ext1", Value: "value1"}},
{{Name: "a", Value: "1"}, {Name: "b", Value: "2"}, {Name: "ext1", Value: "value1"}},
{{Name: "a", Value: "2"}, {Name: "b", Value: "1"}, {Name: "ext1", Value: "value1"}},
{{Name: "a", Value: "2"}, {Name: "b", Value: "2"}, {Name: "ext1", Value: "value1"}},
},
},
} {
if ok := t.Run(fmt.Sprint(i), func(t *testing.T) {
srv := newStoreSeriesServer(ctx)
Expand Down Expand Up @@ -766,6 +783,20 @@ func TestBucketStore_LabelNames_e2e(t *testing.T) {
},
expected: nil,
},
"ext1=value1 matcher": {
req: &storepb.LabelNamesRequest{
Start: timestamp.FromTime(minTime),
End: timestamp.FromTime(maxTime),
Matchers: []storepb.LabelMatcher{
{
Type: storepb.LabelMatcher_EQ,
Name: "ext1",
Value: "value1",
},
},
},
expected: []string{"a", "b", "ext1"},
},
} {
t.Run(name, func(t *testing.T) {
vals, err := s.store.LabelNames(ctx, tc.req)
Expand Down Expand Up @@ -924,6 +955,21 @@ func TestBucketStore_LabelValues_e2e(t *testing.T) {
},
expected: nil, // ext1 is replaced with ext2 for series with c
},
"label a, ext1=value1": {
req: &storepb.LabelValuesRequest{
Label: "a",
Start: timestamp.FromTime(minTime),
End: timestamp.FromTime(maxTime),
Matchers: []storepb.LabelMatcher{
{
Type: storepb.LabelMatcher_EQ,
Name: "ext1",
Value: "value1",
},
},
},
expected: []string{"1", "2"},
},
} {
t.Run(name, func(t *testing.T) {
vals, err := s.store.LabelValues(ctx, tc.req)
Expand Down

0 comments on commit b3fc96d

Please sign in to comment.