Skip to content

Commit 65a5bde

Browse files
committed
Address a review comment
Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
1 parent 3a087de commit 65a5bde

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

docs/configuration/config-file-reference.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,8 +2681,9 @@ The `limits_config` configures default and per-tenant limits imposed by Cortex s
26812681
[max_fetched_chunk_bytes_per_query: <int> | default = 0]
26822682
26832683
# The maximum combined size of all data that a query can fetch from each
2684-
# ingester and storage. This limit is enforced in the querier and ruler only
2685-
# when running Cortex with blocks storage. 0 to disable.
2684+
# ingester and storage. This limit is only applied for `query`, `query_range`
2685+
# and `series` APIs. This limit is enforced in the querier and ruler only when
2686+
# running Cortex with blocks storage. 0 to disable.
26862687
# CLI flag: -querier.max-fetched-data-bytes-per-query
26872688
[max_fetched_data_bytes_per_query: <int> | default = 0]
26882689

pkg/distributor/distributor.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,11 @@ func (d *Distributor) MetricsForLabelMatchers(ctx context.Context, from, through
10271027
if err != nil {
10281028
return nil, err
10291029
}
1030+
if err := queryLimiter.AddDataBytes(resp.Size()); err != nil {
1031+
return nil, err
1032+
}
10301033
ms := ingester_client.FromMetricsForLabelMatchersResponse(resp)
10311034
for _, m := range ms {
1032-
if err := queryLimiter.AddDataBytes(resp.Size()); err != nil {
1033-
return nil, err
1034-
}
10351035
if err := queryLimiter.AddSeries(cortexpb.FromMetricsToLabelAdapters(m)); err != nil {
10361036
return nil, err
10371037
}
@@ -1058,6 +1058,9 @@ func (d *Distributor) MetricsForLabelMatchersStream(ctx context.Context, from, t
10581058
defer stream.CloseSend() //nolint:errcheck
10591059
for {
10601060
resp, err := stream.Recv()
1061+
if err := queryLimiter.AddDataBytes(resp.Size()); err != nil {
1062+
return nil, err
1063+
}
10611064

10621065
if err == io.EOF {
10631066
break
@@ -1068,9 +1071,6 @@ func (d *Distributor) MetricsForLabelMatchersStream(ctx context.Context, from, t
10681071
for _, metric := range resp.Metric {
10691072
m := cortexpb.FromLabelAdaptersToMetricWithCopy(metric.Labels)
10701073

1071-
if err := queryLimiter.AddDataBytes(resp.Size()); err != nil {
1072-
return nil, err
1073-
}
10741074
if err := queryLimiter.AddSeries(metric.Labels); err != nil {
10751075
return nil, err
10761076
}

pkg/querier/blocks_store_queryable.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,7 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
691691

692692
numSeries := len(mySeries)
693693
chunkBytes := countChunkBytes(mySeries...)
694-
labelBytes := countDataBytes(mySeries...)
695-
dataBytes := labelBytes + chunkBytes
694+
dataBytes := countDataBytes(mySeries...)
696695

697696
reqStats.AddFetchedSeries(uint64(numSeries))
698697
reqStats.AddFetchedChunkBytes(uint64(chunkBytes))
@@ -1008,7 +1007,7 @@ func countChunkBytes(series ...*storepb.Series) (count int) {
10081007
return count
10091008
}
10101009

1011-
// countChunkBytes returns the size of the chunks making up the provided series in bytes
1010+
// countDataBytes returns the combined size of the all series
10121011
func countDataBytes(series ...*storepb.Series) (count int) {
10131012
for _, s := range series {
10141013
count += s.Size()

pkg/util/limiter/query_limiter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (ql *QueryLimiter) AddChunkBytes(chunkSizeInBytes int) error {
102102
return nil
103103
}
104104

105-
// AddDataBytes adds the input label size in bytes and returns an error if the limit is reached.
105+
// AddDataBytes adds the queried data bytes and returns an error if the limit is reached.
106106
func (ql *QueryLimiter) AddDataBytes(dataSizeInBytes int) error {
107107
if ql.maxDataBytesPerQuery == 0 {
108108
return nil

pkg/util/validation/limits.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (l *Limits) RegisterFlags(f *flag.FlagSet) {
152152
f.IntVar(&l.MaxChunksPerQuery, "querier.max-fetched-chunks-per-query", 2000000, "Maximum number of chunks that can be fetched in a single query from ingesters and long-term storage. This limit is enforced in the querier, ruler and store-gateway. 0 to disable.")
153153
f.IntVar(&l.MaxFetchedSeriesPerQuery, "querier.max-fetched-series-per-query", 0, "The maximum number of unique series for which a query can fetch samples from each ingesters and blocks storage. This limit is enforced in the querier only when running Cortex with blocks storage. 0 to disable")
154154
f.IntVar(&l.MaxFetchedChunkBytesPerQuery, "querier.max-fetched-chunk-bytes-per-query", 0, "Deprecated (user max-fetched-data-bytes-per-query instead): The maximum size of all chunks in bytes that a query can fetch from each ingester and storage. This limit is enforced in the querier and ruler only when running Cortex with blocks storage. 0 to disable.")
155-
f.IntVar(&l.MaxFetchedDataBytesPerQuery, "querier.max-fetched-data-bytes-per-query", 0, "The maximum combined size of all data that a query can fetch from each ingester and storage. This limit is enforced in the querier and ruler only when running Cortex with blocks storage. 0 to disable.")
155+
f.IntVar(&l.MaxFetchedDataBytesPerQuery, "querier.max-fetched-data-bytes-per-query", 0, "The maximum combined size of all data that a query can fetch from each ingester and storage. This limit is only applied for `query`, `query_range` and `series` APIs. This limit is enforced in the querier and ruler only when running Cortex with blocks storage. 0 to disable.")
156156
f.Var(&l.MaxQueryLength, "store.max-query-length", "Limit the query time range (end - start time). This limit is enforced in the query-frontend (on the received query) and in the querier (on the query possibly split by the query-frontend). 0 to disable.")
157157
f.Var(&l.MaxQueryLookback, "querier.max-query-lookback", "Limit how long back data (series and metadata) can be queried, up until <lookback> duration ago. This limit is enforced in the query-frontend, querier and ruler. If the requested time range is outside the allowed range, the request will not fail but will be manipulated to only query data within the allowed time range. 0 to disable.")
158158
f.IntVar(&l.MaxQueryParallelism, "querier.max-query-parallelism", 14, "Maximum number of split queries will be scheduled in parallel by the frontend.")

0 commit comments

Comments
 (0)