From 333fea9f4bf017599093d83337c764a2b2074283 Mon Sep 17 00:00:00 2001 From: Ryan Allen Date: Wed, 24 Jun 2020 14:07:32 -0400 Subject: [PATCH] [dbnode] Fix limit integration tests (#2425) --- .../prometheus/test.sh | 36 +++++++++++++++++-- src/dbnode/storage/index_block_test.go | 4 +++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/scripts/docker-integration-tests/prometheus/test.sh b/scripts/docker-integration-tests/prometheus/test.sh index 37dc9c8de8..cec5381273 100755 --- a/scripts/docker-integration-tests/prometheus/test.sh +++ b/scripts/docker-integration-tests/prometheus/test.sh @@ -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 { diff --git a/src/dbnode/storage/index_block_test.go b/src/dbnode/storage/index_block_test.go index 466b7b1c6d..e487d2c48c 100644 --- a/src/dbnode/storage/index_block_test.go +++ b/src/dbnode/storage/index_block_test.go @@ -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" @@ -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) @@ -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) @@ -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)