Skip to content

Commit

Permalink
[dbnode] Fix limit integration tests (#2425)
Browse files Browse the repository at this point in the history
  • Loading branch information
rallen090 authored Jun 24, 2020
1 parent 35021ce commit 333fea9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
36 changes: 33 additions & 3 deletions scripts/docker-integration-tests/prometheus/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,41 @@ function test_query_limits_applied {
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 retry_with_backoff \
'[[ $(curl -s 0.0.0.0:7201/api/v1/query?query=\\{__name__!=\"\"\\} | jq -r ".data.result | length") -lt 101 ]]'

# Test the default series limit applied when directly querying
# coordinator (limit set by header)
echo "Test query limit with coordinator limit header"
# Test the series limit applied when directly querying
# coordinator (series limit set by header)
echo "Test query series limit with coordinator limit header"
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 retry_with_backoff \
'[[ $(curl -s -H "M3-Limit-Max-Series: 10" 0.0.0.0:7201/api/v1/query?query=\\{__name__!=\"\"\\} | jq -r ".data.result | length") -eq 10 ]]'

echo "Test query series limit with require-exhaustive headers false"
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 retry_with_backoff \
'[[ $(curl -s -H "M3-Limit-Max-Series: 2" -H "M3-Limit-Require-Exhaustive: false" 0.0.0.0:7201/api/v1/query?query=database_write_tagged_success | jq -r ".data.result | length") -eq 2 ]]'

echo "Test query series limit with require-exhaustive headers true (below limit therefore no error)"
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 retry_with_backoff \
'[[ $(curl -s -H "M3-Limit-Max-Series: 4" -H "M3-Limit-Require-Exhaustive: true" 0.0.0.0:7201/api/v1/query?query=database_write_tagged_success | jq -r ".data.result | length") -eq 3 ]]'

echo "Test query series limit with require-exhaustive headers true (above limit therefore error)"
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 retry_with_backoff \
'[[ -n $(curl -s -H "M3-Limit-Max-Series: 3" -H "M3-Limit-Require-Exhaustive: true" 0.0.0.0:7201/api/v1/query?query=database_write_tagged_success | jq ."error" | grep "query exceeded limit") ]]'

# Test the default docs limit applied when directly querying
# coordinator (docs limit set by header)
echo "Test query docs limit with coordinator limit header"
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 retry_with_backoff \
'[[ $(curl -s -H "M3-Limit-Max-Docs: 1" 0.0.0.0:7201/api/v1/query?query=\\{__name__!=\"\"\\} | jq -r ".data.result | length") -lt 101 ]]'

echo "Test query docs limit with require-exhaustive headers false"
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 retry_with_backoff \
'[[ $(curl -s -H "M3-Limit-Max-Docs: 1" -H "M3-Limit-Require-Exhaustive: false" 0.0.0.0:7201/api/v1/query?query=database_write_tagged_success | jq -r ".data.result | length") -eq 3 ]]'

echo "Test query docs limit with require-exhaustive headers true (below limit therefore no error)"
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 retry_with_backoff \
'[[ $(curl -s -H "M3-Limit-Max-Docs: 4" -H "M3-Limit-Require-Exhaustive: true" 0.0.0.0:7201/api/v1/query?query=database_write_tagged_success | jq -r ".data.result | length") -eq 3 ]]'

echo "Test query docs limit with require-exhaustive headers true (above limit therefore error)"
ATTEMPTS=50 TIMEOUT=2 MAX_TIMEOUT=4 retry_with_backoff \
'[[ -n $(curl -s -H "M3-Limit-Max-Docs: 1" -H "M3-Limit-Require-Exhaustive: true" 0.0.0.0:7201/api/v1/query?query=database_write_tagged_success | jq ."error" | grep "query exceeded limit") ]]'
}

function prometheus_query_native {
Expand Down
4 changes: 4 additions & 0 deletions src/dbnode/storage/index_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/m3db/m3/src/m3ninx/index/segment"
idxpersist "github.com/m3db/m3/src/m3ninx/persist"
"github.com/m3db/m3/src/x/context"
xerrors "github.com/m3db/m3/src/x/errors"
"github.com/m3db/m3/src/x/ident"
xtest "github.com/m3db/m3/src/x/test"
xtime "github.com/m3db/m3/src/x/time"
Expand Down Expand Up @@ -643,6 +644,7 @@ func TestNamespaceIndexBlockQuery(t *testing.T) {
result, err = idx.Query(ctx, q, qOpts)
if test.requireExhaustive {
require.Error(t, err)
require.False(t, xerrors.IsRetryableError(err))
} else {
require.NoError(t, err)
require.False(t, result.Exhaustive)
Expand Down Expand Up @@ -1041,6 +1043,7 @@ func TestNamespaceIndexBlockAggregateQuery(t *testing.T) {
result, err = idx.AggregateQuery(ctx, q, aggOpts)
if test.requireExhaustive {
require.Error(t, err)
require.False(t, xerrors.IsRetryableError(err))
} else {
require.NoError(t, err)
require.False(t, result.Exhaustive)
Expand Down Expand Up @@ -1278,6 +1281,7 @@ func TestNamespaceIndexBlockAggregateQueryAggPath(t *testing.T) {
result, err = idx.AggregateQuery(ctx, q, aggOpts)
if test.requireExhaustive {
require.Error(t, err)
require.False(t, xerrors.IsRetryableError(err))
} else {
require.NoError(t, err)
require.False(t, result.Exhaustive)
Expand Down

0 comments on commit 333fea9

Please sign in to comment.