github.com/m3db/m3@v1.5.0/scripts/docker-integration-tests/prometheus/metadata-limits.sh (about) 1 #!/usr/bin/env bash 2 3 set -ex 4 M3_PATH=${M3_PATH:-$GOPATH/src/github.com/m3db/m3} 5 source "$M3_PATH"/scripts/docker-integration-tests/common.sh 6 7 COMPOSE_FILE="$M3_PATH"/scripts/docker-integration-tests/query_fanout/docker-compose.yml 8 HEADER_FILE=headers.out 9 10 function write_agg_metrics { 11 NUM=$1 12 echo "Writing $NUM metrics to [0.0.0.0:9003]" 13 set +x 14 for (( i=0; i<$NUM; i++ )) 15 do 16 curl -s -X POST 0.0.0.0:9003/writetagged -d '{ 17 "namespace": "unagg", 18 "id": "{__name__=\"'$METRIC_NAME'\",'$METRIC_NAME'=\"'$i'\"}", 19 "tags": [ 20 { 21 "name": "__name__", 22 "value": "'$METRIC_NAME'" 23 }, 24 { 25 "name": "'$METRIC_NAME'", 26 "value": "'$i'" 27 } 28 ], 29 "datapoint": { 30 "timestamp":'"$NOW"', 31 "value": '$i' 32 } 33 }' &> /dev/null 34 done 35 36 set -x 37 } 38 39 function test_correct_label_values { 40 RESULT=$(curl "http://0.0.0.0:7201/api/v1/label/${METRIC_NAME}/values" ) 41 COUNT=$(echo $RESULT | jq .data[] | wc -l) 42 test $COUNT = 60 43 } 44 45 function test_failing_label_values { 46 RESULT=$(curl -D $HEADER_FILE "http://0.0.0.0:7201/api/v1/label/${METRIC_NAME}/values" ) 47 STATUS=$(echo $RESULT | jq .status) 48 test $STATUS = '"error"' 49 } 50 51 function test_query_succeeds { 52 RESULT=$(curl "http://0.0.0.0:7201/api/v1/query?query=sum($METRIC_NAME)&start=$NOW") 53 STATUS=$(echo $RESULT | jq .status) 54 test $STATUS = '"success"' 55 } 56 57 function test_global_aggregate_limits { 58 export NOW=$(date +"%s") 59 export METRIC_NAME="aggregate_limits_$NOW" 60 61 write_agg_metrics 60 62 curl -vvvsSf -X POST 0.0.0.0:7201/api/v1/kvstore -d '{ 63 "key": "m3db.query.limits", 64 "value":{ 65 "maxRecentlyQueriedMetadataRead": { 66 "limit":150, 67 "lookbackSeconds":5, 68 "forceExceeded":false 69 } 70 }, 71 "commit":true 72 }' 73 74 # Make sure any existing limit has expired before continuing. 75 ATTEMPTS=5 retry_with_backoff test_correct_label_values 76 ATTEMPTS=5 retry_with_backoff test_correct_label_values 77 ATTEMPTS=5 TIMEOUT=1 retry_with_backoff test_failing_label_values 78 # Make sure that a query is unaffected by the the metadata limits. 79 ATTEMPTS=2 retry_with_backoff test_query_succeeds 80 # Make sure the limit expires within 10 seconds and the query succeeds again. 81 ATTEMPTS=10 retry_with_backoff test_correct_label_values 82 curl -vvvsSf -X POST 0.0.0.0:7201/api/v1/kvstore -d '{ 83 "key": "m3db.query.limits", 84 "value":{}, 85 "commit":true 86 }' 87 }