github.com/m3db/m3@v1.5.0/scripts/docker-integration-tests/query_fanout/test.sh (about) 1 #!/usr/bin/env bash 2 3 set -xe 4 5 TEST_PATH="$M3_PATH"/scripts/docker-integration-tests 6 FANOUT_PATH=$TEST_PATH/query_fanout 7 source $TEST_PATH/common.sh 8 source $FANOUT_PATH/warning.sh 9 source $FANOUT_PATH/restrict.sh 10 11 REVISION=$(git rev-parse HEAD) 12 COMPOSE_FILE="$M3_PATH"/scripts/docker-integration-tests/query_fanout/docker-compose.yml 13 export REVISION 14 15 echo "Run m3dbnode and m3coordinator containers" 16 docker-compose -f ${COMPOSE_FILE} up -d dbnode-cluster-a 17 docker-compose -f ${COMPOSE_FILE} up -d coordinator-cluster-a 18 19 docker-compose -f ${COMPOSE_FILE} up -d dbnode-cluster-b 20 docker-compose -f ${COMPOSE_FILE} up -d coordinator-cluster-b 21 22 docker-compose -f ${COMPOSE_FILE} up -d dbnode-cluster-c 23 docker-compose -f ${COMPOSE_FILE} up -d coordinator-cluster-c 24 25 # think of this as a defer func() in golang 26 function defer { 27 docker-compose -f ${COMPOSE_FILE} down || echo "unable to shutdown containers" # CI fails to stop all containers sometimes 28 } 29 trap defer EXIT 30 31 AGG_RESOLUTION=5s DBNODE_HOST=dbnode-cluster-a DBDNODE_PORT=9000 DBNODE_HEALTH_PORT=9002 COORDINATOR_PORT=7201 \ 32 setup_single_m3db_node 33 34 AGG_RESOLUTION=5s DBNODE_HOST=dbnode-cluster-b DBDNODE_PORT=19000 DBNODE_HEALTH_PORT=19002 COORDINATOR_PORT=17201 \ 35 setup_single_m3db_node 36 37 AGG_RESOLUTION=5s DBNODE_HOST=dbnode-cluster-c DBDNODE_PORT=29000 DBNODE_HEALTH_PORT=29002 COORDINATOR_PORT=27201 \ 38 setup_single_m3db_node 39 40 echo "Write data to cluster a" 41 curl -vvvsS -X POST 0.0.0.0:9003/writetagged -d '{ 42 "namespace": "unagg", 43 "id": "{__name__=\"test_metric\",cluster=\"cluster-a\",endpoint=\"/request\"}", 44 "tags": [ 45 { 46 "name": "__name__", 47 "value": "test_metric" 48 }, 49 { 50 "name": "cluster", 51 "value": "cluster-a" 52 }, 53 { 54 "name": "endpoint", 55 "value": "/request" 56 } 57 ], 58 "datapoint": { 59 "timestamp":'"$(date +"%s")"', 60 "value": 42.123456789 61 } 62 }' 63 64 echo "Write data to cluster b" 65 curl -vvvsS -X POST 0.0.0.0:19003/writetagged -d '{ 66 "namespace": "unagg", 67 "id": "{__name__=\"test_metric\",cluster=\"cluster-b\",endpoint=\"/request\"}", 68 "tags": [ 69 { 70 "name": "__name__", 71 "value": "test_metric" 72 }, 73 { 74 "name": "cluster", 75 "value": "cluster-b" 76 }, 77 { 78 "name": "endpoint", 79 "value": "/request" 80 } 81 ], 82 "datapoint": { 83 "timestamp":'"$(date +"%s")"', 84 "value": 42.123456789 85 } 86 }' 87 88 echo "Write data to cluster c" 89 curl -vvvsS -X POST 0.0.0.0:29003/writetagged -d '{ 90 "namespace": "unagg", 91 "id": "{__name__=\"test_metric\",cluster=\"cluster-c\",endpoint=\"/request\"}", 92 "tags": [ 93 { 94 "name": "__name__", 95 "value": "test_metric" 96 }, 97 { 98 "name": "cluster", 99 "value": "cluster-c" 100 }, 101 { 102 "name": "endpoint", 103 "value": "/request" 104 } 105 ], 106 "datapoint": { 107 "timestamp":'"$(date +"%s")"', 108 "value": 42.123456789 109 } 110 }' 111 112 function read { 113 RESPONSE=$(curl "http://0.0.0.0:7201/api/v1/query?query=test_metric") 114 ACTUAL=$(echo $RESPONSE | jq .data.result[].metric.cluster | sort) 115 test "$(echo $ACTUAL)" = '"cluster-a" "cluster-b" "cluster-c"' 116 } 117 118 ATTEMPTS=5 TIMEOUT=1 retry_with_backoff read 119 120 function read_sum { 121 RESPONSE=$(curl "http://0.0.0.0:7201/api/v1/query?query=sum(test_metric)") 122 ACTUAL=$(echo $RESPONSE | jq .data.result[].value[1]) 123 test $ACTUAL = '"126.370370367"' 124 } 125 126 ATTEMPTS=5 TIMEOUT=1 retry_with_backoff read_sum 127 128 echo "Write local tagged data to cluster a" 129 curl -vvvsS -X POST 0.0.0.0:19003/writetagged -d '{ 130 "namespace": "unagg", 131 "id": "{__name__=\"test_metric\",cluster=\"cluster-b\",endpoint=\"/request\",local-only=\"local\"}", 132 "tags": [ 133 { 134 "name": "__name__", 135 "value": "test_metric" 136 }, 137 { 138 "name": "cluster", 139 "value": "cluster-b" 140 }, 141 { 142 "name": "endpoint", 143 "value": "/request" 144 }, 145 { 146 "name": "local-only", 147 "value": "local" 148 } 149 ], 150 "datapoint": { 151 "timestamp":'"$(date +"%s")"', 152 "value": 42.123456789 153 } 154 }' 155 156 echo "Write remote tagged data to cluster b" 157 curl -vvvsS -X POST 0.0.0.0:19003/writetagged -d '{ 158 "namespace": "unagg", 159 "id": "{__name__=\"test_metric\",cluster=\"cluster-b\",endpoint=\"/request\",remote-only=\"remote\"}", 160 "tags": [ 161 { 162 "name": "__name__", 163 "value": "test_metric" 164 }, 165 { 166 "name": "cluster", 167 "value": "cluster-b" 168 }, 169 { 170 "name": "endpoint", 171 "value": "/request" 172 }, 173 { 174 "name": "remote-only", 175 "value": "remote" 176 } 177 ], 178 "datapoint": { 179 "timestamp":'"$(date +"%s")"', 180 "value": 42.123456789 181 } 182 }' 183 184 echo "Write remote tagged data to cluster c" 185 curl -vvvsS -X POST 0.0.0.0:29003/writetagged -d '{ 186 "namespace": "unagg", 187 "id": "{__name__=\"test_metric\",cluster=\"cluster-c\",endpoint=\"/request\",third-cluster=\"third\"}", 188 "tags": [ 189 { 190 "name": "__name__", 191 "value": "test_metric" 192 }, 193 { 194 "name": "cluster", 195 "value": "cluster-c" 196 }, 197 { 198 "name": "endpoint", 199 "value": "/request" 200 }, 201 { 202 "name": "third-cluster", 203 "value": "third" 204 } 205 ], 206 "datapoint": { 207 "timestamp":'"$(date +"%s")"', 208 "value": 42.123456789 209 } 210 }' 211 212 function complete_tags { 213 RESPONSE=$(curl "http://0.0.0.0:7201/api/v1/labels") 214 ACTUAL=$(echo $RESPONSE | jq .data[]) 215 test "$(echo $ACTUAL)" = '"__name__" "cluster" "endpoint" "local-only" "remote-only" "third-cluster"' 216 } 217 218 ATTEMPTS=5 TIMEOUT=1 retry_with_backoff complete_tags 219 220 echo "running fanout warning tests" 221 test_fanout_warnings 222 223 echo "running restrict tests" 224 test_restrictions