Skip to content

Returning 422 (instead 500) when query hit max_chunks_per_query limit with block storage #3895

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
* [BUGFIX] Compactor: fixed "could not guess file size" log when uploading blocks deletion marks to the global location. #3807
* [BUGFIX] Prevent panic at start if the http_prefix setting doesn't have a valid value. #3796
* [BUGFIX] Memberlist: fixed panic caused by race condition in `armon/go-metrics` used by memberlist client. #3724
* [CHANGE] Returning 422 (instead 500) when query hit max_chunks_per_query limit with block storage. #3895

## 1.7.0

Expand Down
3 changes: 2 additions & 1 deletion pkg/querier/blocks_store_queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/cortexproject/cortex/pkg/util/math"
"github.com/cortexproject/cortex/pkg/util/services"
"github.com/cortexproject/cortex/pkg/util/spanlogger"
"github.com/cortexproject/cortex/pkg/util/validation"
)

const (
Expand Down Expand Up @@ -614,7 +615,7 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
if maxChunksLimit > 0 {
actual := numChunks.Add(int32(len(s.Chunks)))
if actual > int32(leftChunksLimit) {
return fmt.Errorf(errMaxChunksPerQueryLimit, convertMatchersToString(matchers), maxChunksLimit)
return validation.LimitError(fmt.Sprintf(errMaxChunksPerQueryLimit, convertMatchersToString(matchers), maxChunksLimit))
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions pkg/querier/blocks_store_queryable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/cortexproject/cortex/pkg/storegateway/storegatewaypb"
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/services"
"github.com/cortexproject/cortex/pkg/util/validation"
)

func TestBlocksStoreQuerier_Select(t *testing.T) {
Expand Down Expand Up @@ -67,18 +68,18 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
storeSetResponses []interface{}
limits BlocksStoreLimits
expectedSeries []seriesResult
expectedErr string
expectedErr error
expectedMetrics string
}{
"no block in the storage matching the query time range": {
finderResult: nil,
limits: &blocksStoreLimitsMock{},
expectedErr: "",
expectedErr: nil,
},
"error while finding blocks matching the query time range": {
finderErr: errors.New("unable to find blocks"),
limits: &blocksStoreLimitsMock{},
expectedErr: "unable to find blocks",
expectedErr: errors.New("unable to find blocks"),
},
"error while getting clients to query the store-gateway": {
finderResult: bucketindex.Blocks{
Expand All @@ -89,7 +90,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
errors.New("no client found"),
},
limits: &blocksStoreLimitsMock{},
expectedErr: "no client found",
expectedErr: errors.New("no client found"),
},
"a single store-gateway instance holds the required blocks (single returned series)": {
finderResult: bucketindex.Blocks{
Expand Down Expand Up @@ -290,7 +291,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
errors.New("no store-gateway remaining after exclude"),
},
limits: &blocksStoreLimitsMock{},
expectedErr: fmt.Sprintf("consistency check failed because some blocks were not queried: %s", block2.String()),
expectedErr: fmt.Errorf("consistency check failed because some blocks were not queried: %s", block2.String()),
},
"multiple store-gateway instances have some missing blocks (consistency check failed)": {
finderResult: bucketindex.Blocks{
Expand All @@ -315,7 +316,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
errors.New("no store-gateway remaining after exclude"),
},
limits: &blocksStoreLimitsMock{},
expectedErr: fmt.Sprintf("consistency check failed because some blocks were not queried: %s %s", block3.String(), block4.String()),
expectedErr: fmt.Errorf("consistency check failed because some blocks were not queried: %s %s", block3.String(), block4.String()),
},
"multiple store-gateway instances have some missing blocks but queried from a replica during subsequent attempts": {
finderResult: bucketindex.Blocks{
Expand Down Expand Up @@ -435,7 +436,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
},
},
limits: &blocksStoreLimitsMock{maxChunksPerQuery: 1},
expectedErr: fmt.Sprintf(errMaxChunksPerQueryLimit, fmt.Sprintf("{__name__=%q}", metricName), 1),
expectedErr: validation.LimitError(fmt.Sprintf(errMaxChunksPerQueryLimit, fmt.Sprintf("{__name__=%q}", metricName), 1)),
},
"max chunks per query limit hit while fetching chunks during subsequent attempts": {
finderResult: bucketindex.Blocks{
Expand Down Expand Up @@ -472,7 +473,7 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
},
},
limits: &blocksStoreLimitsMock{maxChunksPerQuery: 3},
expectedErr: fmt.Sprintf(errMaxChunksPerQueryLimit, fmt.Sprintf("{__name__=%q}", metricName), 3),
expectedErr: validation.LimitError(fmt.Sprintf(errMaxChunksPerQueryLimit, fmt.Sprintf("{__name__=%q}", metricName), 3)),
},
}

Expand Down Expand Up @@ -502,8 +503,9 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
}

set := q.Select(true, nil, matchers...)
if testData.expectedErr != "" {
assert.EqualError(t, set.Err(), testData.expectedErr)
if testData.expectedErr != nil {
assert.EqualError(t, set.Err(), testData.expectedErr.Error())
assert.IsType(t, set.Err(), testData.expectedErr)
assert.False(t, set.Next())
assert.Nil(t, set.Warnings())
return
Expand Down