Skip to content

Commit 4f31df8

Browse files
treid314pracucci
authored andcommitted
Apply suggestions from code review
Co-authored-by: Marco Pracucci <[email protected]> Signed-off-by: Tyler Reid <[email protected]>
1 parent 01e59ea commit 4f31df8

File tree

5 files changed

+12
-17
lines changed

5 files changed

+12
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
* `cortex_alertmanager_state_persist_failed_total`
1919
* [ENHANCEMENT] Blocks storage: support ingesting exemplars. Enabled by setting new CLI flag `-blocks-storage.tsdb.max-exemplars=<n>` or config option `blocks_storage.tsdb.max_exemplars` to positive value. #4124
2020
* [ENHANCEMENT] Distributor: Added distributors ring status section in the admin page. #4151
21-
* [ENHANCEMENT] Ingester/Block Storage: Added ingester and block storage support for `max_series_per_query` / `-ingester.max-series-per-query`
22-
If cortex is running in chunk mode the series limit is only supported for fetched series from the ingester. If cortex is in blocks mode this
23-
this limit is for fetched series from block storage and ingester. #4179
21+
* [ENHANCEMENT] Querier: Added `-ingester.max-series-per-query` support for blocks storage. When Cortex is running with blocks storage, the limit is enforced in the querier and applies both to data received from ingesters and store-gateway (long-term storage). #4179
2422
* [BUGFIX] Purger: fix `Invalid null value in condition for column range` caused by `nil` value in range for WriteBatch query. #4128
2523
* [BUGFIX] Ingester: fixed infrequent panic caused by a race condition between TSDB mmap-ed head chunks truncation and queries. #4176
2624

docs/configuration/arguments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ Valid per-tenant limits are (with their corresponding flags for default values):
484484

485485
- `max_series_per_query` / `-ingester.max-series-per-query`
486486

487-
When running Cortex chunks storage: limit enforced when fetching metrics from ingesters only.
488-
When running Cortex blocks storage: limit enforced when fetching metrics both from ingesters and store-gateways.
487+
When running Cortex chunks storage: limit enforced in the ingesters only and it's a per-instance limit.
488+
When running Cortex blocks storage: limit enforced in the queriers both on samples fetched from ingesters and store-gateways (long-term storage).
489489

490490
- `max_samples_per_query` / `-ingester.max-samples-per-query`
491491

pkg/distributor/distributor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ func TestDistributor_QueryStream_ShouldReturnErrorIfMaxSeriesPerQueryLimitIsReac
963963
})
964964
defer stopAll(ds, r)
965965

966-
// Push a number of series below the max series limit. Each series has 1 sample,
966+
// Push a number of series below the max series limit. Each series has 1 sample.
967967
initialSeries := maxSeriesLimit
968968
writeReq := makeWriteRequest(0, initialSeries, 0)
969969
writeRes, err := ds[0].Push(ctx, writeReq)

pkg/util/limiter/query_limiter.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
errMaxSeriesHit = "The query hit the max number of series limit while fetching chunks %s (limit: %d)"
3030
)
3131

32-
// NewQueryLimiter makes a new per-query rate limiter. Each per-query limiter
32+
// NewQueryLimiter makes a new per-query limiter. Each per-query limiter
3333
// is configured using the `maxSeriesPerQuery` and `maxChunkBytesPerQuery` limits.
3434
func NewQueryLimiter(maxSeriesPerQuery int) *QueryLimiter {
3535
return &QueryLimiter{
@@ -50,8 +50,8 @@ func AddQueryLimiterToContext(ctx context.Context, limiter *QueryLimiter) contex
5050
return context.WithValue(ctx, qlCtxKey, limiter)
5151
}
5252

53-
// QueryLimiterFromContextWithFallback returns a Query Limiter from the current context.
54-
// IF there is Per Query Limiter on the context we will return a new no-op limiter
53+
// QueryLimiterFromContextWithFallback returns a QueryLimiter from the current context.
54+
// If there is not a QueryLimiter on the context it will return a new no-op limiter.
5555
func QueryLimiterFromContextWithFallback(ctx context.Context) *QueryLimiter {
5656
ql, ok := ctx.Value(qlCtxKey).(*QueryLimiter)
5757
if !ok {
@@ -61,9 +61,7 @@ func QueryLimiterFromContextWithFallback(ctx context.Context) *QueryLimiter {
6161
return ql
6262
}
6363

64-
// AddSeries Add labels for series to the count of unique series. If the
65-
// added series label causes us to go over the limit of maxSeriesPerQuery we will
66-
// return a validation error
64+
// AddSeries adds the input series and returns an error if the limit is reached.
6765
func (ql *QueryLimiter) AddSeries(labelAdapter []cortexpb.LabelAdapter, matchers []*labels.Matcher) error {
6866
// If the max series is unlimited just return without managing map
6967
if ql.maxSeriesPerQuery == 0 {

pkg/util/limiter/query_limiter_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/cortexproject/cortex/pkg/cortexpb"
1212
)
1313

14-
func TestPerQueryLimiter_AddFingerPrint(t *testing.T) {
14+
func TestQueryLimiter_AddSeries_ShouldReturnNoErrorOnLimitNotExceeded(t *testing.T) {
1515
const (
1616
metricName = "test_metric"
1717
)
@@ -35,10 +35,9 @@ func TestPerQueryLimiter_AddFingerPrint(t *testing.T) {
3535
err := limiter.AddSeries(cortexpb.FromLabelsToLabelAdapters(series2), matchers)
3636
assert.Equal(t, 2, limiter.UniqueSeries())
3737
assert.Nil(t, err)
38-
3938
}
4039

41-
func TestPerQueryLimiter_AddFingerPrintExceedLimit(t *testing.T) {
40+
func TestQueryLimiter_AddSeriers_ShouldReturnErrorOnLimitExceeded(t *testing.T) {
4241
const (
4342
metricName = "test_metric"
4443
)
@@ -59,12 +58,12 @@ func TestPerQueryLimiter_AddFingerPrintExceedLimit(t *testing.T) {
5958
limiter = NewQueryLimiter(1)
6059
)
6160
err := limiter.AddSeries(cortexpb.FromLabelsToLabelAdapters(series1), matchers)
62-
assert.Equal(t, nil, err)
61+
require.NoError(t, err)
6362
err = limiter.AddSeries(cortexpb.FromLabelsToLabelAdapters(series2), matchers)
6463
require.Error(t, err)
6564
}
6665

67-
func BenchmarkPerQueryLimiter_AddFingerPrint(b *testing.B) {
66+
func BenchmarkQueryLimiter_AddSeries(b *testing.B) {
6867
const (
6968
metricName = "test_metric"
7069
)

0 commit comments

Comments
 (0)