Skip to content

Commit e02797a

Browse files
alanprotpstibranypracucci
authored
Returning 422 (instead 500) when query hit max_chunks_per_query limit with block storage (#3895)
* Returning 422 (instead 500) when query hit max_chunks_per_query limit Signed-off-by: Alan Protasio <[email protected]> * Update CHANGELOG.md Co-authored-by: Peter Štibraný <[email protected]> Signed-off-by: Alan Protasio <[email protected]> * Update CHANGELOG.md Signed-off-by: Marco Pracucci <[email protected]> Co-authored-by: Peter Štibraný <[email protected]> Co-authored-by: Marco Pracucci <[email protected]>
1 parent 003eb33 commit e02797a

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
* [BUGFIX] Compactor: fixed "could not guess file size" log when uploading blocks deletion marks to the global location. #3807
9393
* [BUGFIX] Prevent panic at start if the http_prefix setting doesn't have a valid value. #3796
9494
* [BUGFIX] Memberlist: fixed panic caused by race condition in `armon/go-metrics` used by memberlist client. #3724
95+
* [BUGFIX] Querier: returning 422 (instead of 500) when query hits `max_chunks_per_query` limit with block storage. #3895
9596

9697
## 1.7.0
9798

pkg/querier/blocks_store_queryable.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"github.com/cortexproject/cortex/pkg/util/math"
4242
"github.com/cortexproject/cortex/pkg/util/services"
4343
"github.com/cortexproject/cortex/pkg/util/spanlogger"
44+
"github.com/cortexproject/cortex/pkg/util/validation"
4445
)
4546

4647
const (
@@ -614,7 +615,7 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
614615
if maxChunksLimit > 0 {
615616
actual := numChunks.Add(int32(len(s.Chunks)))
616617
if actual > int32(leftChunksLimit) {
617-
return fmt.Errorf(errMaxChunksPerQueryLimit, convertMatchersToString(matchers), maxChunksLimit)
618+
return validation.LimitError(fmt.Sprintf(errMaxChunksPerQueryLimit, convertMatchersToString(matchers), maxChunksLimit))
618619
}
619620
}
620621
}

pkg/querier/blocks_store_queryable_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/cortexproject/cortex/pkg/storegateway/storegatewaypb"
3333
"github.com/cortexproject/cortex/pkg/util"
3434
"github.com/cortexproject/cortex/pkg/util/services"
35+
"github.com/cortexproject/cortex/pkg/util/validation"
3536
)
3637

3738
func TestBlocksStoreQuerier_Select(t *testing.T) {
@@ -67,18 +68,18 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
6768
storeSetResponses []interface{}
6869
limits BlocksStoreLimits
6970
expectedSeries []seriesResult
70-
expectedErr string
71+
expectedErr error
7172
expectedMetrics string
7273
}{
7374
"no block in the storage matching the query time range": {
7475
finderResult: nil,
7576
limits: &blocksStoreLimitsMock{},
76-
expectedErr: "",
77+
expectedErr: nil,
7778
},
7879
"error while finding blocks matching the query time range": {
7980
finderErr: errors.New("unable to find blocks"),
8081
limits: &blocksStoreLimitsMock{},
81-
expectedErr: "unable to find blocks",
82+
expectedErr: errors.New("unable to find blocks"),
8283
},
8384
"error while getting clients to query the store-gateway": {
8485
finderResult: bucketindex.Blocks{
@@ -89,7 +90,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
8990
errors.New("no client found"),
9091
},
9192
limits: &blocksStoreLimitsMock{},
92-
expectedErr: "no client found",
93+
expectedErr: errors.New("no client found"),
9394
},
9495
"a single store-gateway instance holds the required blocks (single returned series)": {
9596
finderResult: bucketindex.Blocks{
@@ -290,7 +291,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
290291
errors.New("no store-gateway remaining after exclude"),
291292
},
292293
limits: &blocksStoreLimitsMock{},
293-
expectedErr: fmt.Sprintf("consistency check failed because some blocks were not queried: %s", block2.String()),
294+
expectedErr: fmt.Errorf("consistency check failed because some blocks were not queried: %s", block2.String()),
294295
},
295296
"multiple store-gateway instances have some missing blocks (consistency check failed)": {
296297
finderResult: bucketindex.Blocks{
@@ -315,7 +316,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
315316
errors.New("no store-gateway remaining after exclude"),
316317
},
317318
limits: &blocksStoreLimitsMock{},
318-
expectedErr: fmt.Sprintf("consistency check failed because some blocks were not queried: %s %s", block3.String(), block4.String()),
319+
expectedErr: fmt.Errorf("consistency check failed because some blocks were not queried: %s %s", block3.String(), block4.String()),
319320
},
320321
"multiple store-gateway instances have some missing blocks but queried from a replica during subsequent attempts": {
321322
finderResult: bucketindex.Blocks{
@@ -435,7 +436,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
435436
},
436437
},
437438
limits: &blocksStoreLimitsMock{maxChunksPerQuery: 1},
438-
expectedErr: fmt.Sprintf(errMaxChunksPerQueryLimit, fmt.Sprintf("{__name__=%q}", metricName), 1),
439+
expectedErr: validation.LimitError(fmt.Sprintf(errMaxChunksPerQueryLimit, fmt.Sprintf("{__name__=%q}", metricName), 1)),
439440
},
440441
"max chunks per query limit hit while fetching chunks during subsequent attempts": {
441442
finderResult: bucketindex.Blocks{
@@ -472,7 +473,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
472473
},
473474
},
474475
limits: &blocksStoreLimitsMock{maxChunksPerQuery: 3},
475-
expectedErr: fmt.Sprintf(errMaxChunksPerQueryLimit, fmt.Sprintf("{__name__=%q}", metricName), 3),
476+
expectedErr: validation.LimitError(fmt.Sprintf(errMaxChunksPerQueryLimit, fmt.Sprintf("{__name__=%q}", metricName), 3)),
476477
},
477478
}
478479

@@ -502,8 +503,9 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
502503
}
503504

504505
set := q.Select(true, nil, matchers...)
505-
if testData.expectedErr != "" {
506-
assert.EqualError(t, set.Err(), testData.expectedErr)
506+
if testData.expectedErr != nil {
507+
assert.EqualError(t, set.Err(), testData.expectedErr.Error())
508+
assert.IsType(t, set.Err(), testData.expectedErr)
507509
assert.False(t, set.Next())
508510
assert.Nil(t, set.Warnings())
509511
return

0 commit comments

Comments
 (0)