-
Notifications
You must be signed in to change notification settings - Fork 2.2k
store: Implement metadata API limit in stores #7652
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1008,6 +1008,7 @@ type blockSeriesClient struct { | |
|
||
mint int64 | ||
maxt int64 | ||
seriesLimit int | ||
indexr *bucketIndexReader | ||
chunkr *bucketChunkReader | ||
loadAggregates []storepb.Aggr | ||
|
@@ -1083,6 +1084,7 @@ func newBlockSeriesClient( | |
|
||
mint: req.MinTime, | ||
maxt: req.MaxTime, | ||
seriesLimit: int(req.Limit), | ||
indexr: b.indexReader(logger), | ||
chunkr: chunkr, | ||
seriesLimiter: seriesLimiter, | ||
|
@@ -1162,14 +1164,20 @@ func (b *blockSeriesClient) ExpandPostings( | |
b.expandedPostings = make([]storage.SeriesRef, 0, len(b.lazyPostings.postings)/2) | ||
b.lazyExpandedPostingsCount.Inc() | ||
} else { | ||
// If seriesLimit is set, it can be applied here to limit the amount of series. | ||
// Note: This can only be done when postings are not expanded lazily. | ||
if b.seriesLimit > 0 && len(b.lazyPostings.postings) > b.seriesLimit { | ||
b.lazyPostings.postings = b.lazyPostings.postings[:b.seriesLimit] | ||
} | ||
|
||
// Apply series limiter eargerly if lazy postings not enabled. | ||
if err := seriesLimiter.Reserve(uint64(len(ps.postings))); err != nil { | ||
if err := seriesLimiter.Reserve(uint64(len(b.lazyPostings.postings))); err != nil { | ||
return httpgrpc.Errorf(int(codes.ResourceExhausted), "exceeded series limit: %s", err) | ||
} | ||
} | ||
|
||
if b.batchSize > len(ps.postings) { | ||
b.batchSize = len(ps.postings) | ||
if b.batchSize > len(b.lazyPostings.postings) { | ||
b.batchSize = len(b.lazyPostings.postings) | ||
} | ||
|
||
b.entries = make([]seriesEntry, 0, b.batchSize) | ||
|
@@ -1291,6 +1299,11 @@ OUTER: | |
} | ||
|
||
seriesMatched++ | ||
if b.seriesLimit > 0 && seriesMatched > b.seriesLimit { | ||
// Exit early if seriesLimit is set. | ||
b.hasMorePostings = false | ||
break | ||
} | ||
s := seriesEntry{lset: completeLabelset} | ||
if b.skipChunks { | ||
b.entries = append(b.entries, s) | ||
|
@@ -1694,7 +1707,12 @@ func (s *BucketStore) Series(req *storepb.SeriesRequest, seriesSrv storepb.Store | |
tracing.DoInSpan(ctx, "bucket_store_merge_all", func(ctx context.Context) { | ||
begin := time.Now() | ||
set := NewResponseDeduplicator(NewProxyResponseLoserTree(respSets...)) | ||
i := 0 | ||
for set.Next() { | ||
i++ | ||
if req.Limit > 0 && i > int(req.Limit) { | ||
break | ||
} | ||
at := set.At() | ||
warn := at.GetWarning() | ||
if warn != "" { | ||
|
@@ -1945,8 +1963,13 @@ func (s *BucketStore) LabelNames(ctx context.Context, req *storepb.LabelNamesReq | |
return nil, status.Error(codes.Unknown, errors.Wrap(err, "marshal label names response hints").Error()) | ||
} | ||
|
||
names := strutil.MergeSlices(sets...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we think it is worth it to pass limit into
For example, if the limit is < len(a) / 2, we can skip merging the second half of slice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this is not a blocker, we can do it in further prs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Ben. I can look into it. Since this PR has gotten too big, I prefer to do in a follow up PR. :) |
||
if req.Limit > 0 && len(names) > int(req.Limit) { | ||
names = names[:req.Limit] | ||
} | ||
|
||
return &storepb.LabelNamesResponse{ | ||
Names: strutil.MergeSlices(sets...), | ||
Names: names, | ||
Hints: anyHints, | ||
}, nil | ||
} | ||
|
@@ -2160,8 +2183,13 @@ func (s *BucketStore) LabelValues(ctx context.Context, req *storepb.LabelValuesR | |
return nil, status.Error(codes.Unknown, errors.Wrap(err, "marshal label values response hints").Error()) | ||
} | ||
|
||
vals := strutil.MergeSlices(sets...) | ||
if req.Limit > 0 && len(vals) > int(req.Limit) { | ||
vals = vals[:req.Limit] | ||
} | ||
|
||
return &storepb.LabelValuesResponse{ | ||
Values: strutil.MergeSlices(sets...), | ||
Values: vals, | ||
Hints: anyHints, | ||
}, nil | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.