forked from cloudendpoints/esp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linux-test-vm-echo
executable file
·151 lines (129 loc) · 5.18 KB
/
linux-test-vm-echo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
#
# Copyright (C) Extensible Service Proxy Authors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
################################################################################
#
# This script deploys the echo API into a GAEv2 VM with ESP
# and use AB to test performance against it.
if [[ "$(uname)" != 'Linux' ]]; then
echo 'Run on Linux only.'
exit 1
fi
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
. "${ROOT}/script/all-utilities" \
|| { echo 'Cannot load Bash utilities' ; exit 1 ; }
function cleanup() {
retry -n 2 "${ROOT}/script/linux-gae-instance" -v "${GAE_VERSION}" -p "${PROJECT_ID}" delete
}
IMAGE_NAME="gcr.io/endpointsv2/endpoints-runtime-flex:debian-git-$(git log -1 --pretty=format:%H)"
PROJECT_ID='esp-load-test'
API_KEY=''
TEST_ENV=''
BUCKET=''
while getopts a:i:p:t:b: arg; do
case ${arg} in
a) API_KEY="${OPTARG}";;
i) IMAGE_NAME="${OPTARG}";;
p) PROJECT_ID="${OPTARG}";;
t) TEST_ENV="$(realpath "${OPTARG}")";;
b) BUCKET="${OPTARG}";;
*) echo "Invalid option: -${OPTARG}";;
esac
done
if [[ -z "${API_KEY}" ]]; then
echo 'Getting default API Key set.'
set_api_keys
API_KEY="${ESP_LOAD_TEST_API_KEY}"
[[ -n "${API_KEY}" ]] \
|| error_exit 'API key is not set properly'
fi
TIME_VERSION="$(date +"%Y%m%d%H%M%S")"
APP_VERSION="${IMAGE_NAME}-${TIME_VERSION}"
GAE_VERSION="$(extract_key_from_test_env_file 'run_id' "${TEST_ENV}")" \
|| error_exit "Could not extract run_id from ${TEST_ENV}."
echo "API_KEY: ${API_KEY}"
echo "PROJECT_ID: ${PROJECT_ID}"
echo "IMAGE_NAME: ${IMAGE_NAME}"
echo "APP_VERSION: ${APP_VERSION}"
echo "GAE_VERSION: ${GAE_VERSION}"
APP_DIR="${ROOT}/test/echo"
echo 'Replaces environment.'
sed -i "s|\${VERSION}|${APP_VERSION}|g" "${APP_DIR}/echo.js"
sed -i "s|\${MY_PROJECT_ID}|${PROJECT_ID}|g" "${APP_DIR}/app_esp.yaml"
sed -i "s|\${IMAGE_NAME}|${IMAGE_NAME}|g" "${APP_DIR}/app_esp.yaml"
trap cleanup EXIT
"${ROOT}/script/linux-gae-instance" -a "${ROOT}/test/echo/app_esp.yaml" \
-v "${GAE_VERSION}" -p "${PROJECT_ID}" create \
|| error_exit "Failed to deploy ${GAE_VERSION} to ${PROJECT_ID}."
HOST="https://${GAE_VERSION}-dot-${PROJECT_ID}.appspot.com"
function check_deployed_version() {
echo "Verify \"${APP_VERSION}\" version is deployed on host: ${HOST}".
local deployed_version="$(curl ${HOST}/version)"
echo "Expected version: ${APP_VERSION}"
echo "Deployed version: ${deployed_version}"
if [[ "${deployed_version}" =~ .*${APP_VERSION}.* ]]; then
return 0
else
echo "Version from ${HOST}: ${deployed_version} doesn't contain ${APP_VERSION}"
return 1
fi
}
# appengine deploy may take a while to come up
retry -n 30 -s 60 -t 60 check_deployed_version \
|| error_exit "Timeout: could not match the version from ${HOST} with ${APP_VERSION}"
echo 'Verify that endpoints is enabled'
EXPECTED_RESPONSE=".*Method doesn't allow unregistered callers.*STATUS_CODE:401"
[[ "$(curl -w "STATUS_CODE:%{http_code}" "${HOST}/echo")" =~ ${EXPECTED_RESPONSE} ]] \
|| error_exit "ERROR: Endpoints is disabled on ${HOST}"
SERVICE_NAME="echo-dot-${PROJECT_ID}.appspot.com"
JWT_TOKEN="$("${ROOT}/client/custom/gen-auth-token.sh" \
-s "$(get_test_client_key ${ROOT}/test/echo/esp-echo-client-secret-jwk.json)" \
-a "${SERVICE_NAME}")"
POST_FILE="${ROOT}/test/echo/package.json"
echo "Start perf testing"
pushd "${ROOT}/test/client" > /dev/null
cat "${TEST_ENV}"
./esp_client.py \
--test_env="${TEST_ENV}" \
--host=${HOST} \
--api_key=${API_KEY} \
--auth_token=${JWT_TOKEN} \
--post_file=${POST_FILE}
RESULT=${?}
if [[ -n "${BUCKET}" ]] ; then
LOG_DIRECTORY="${HOME}/nginx-logs"
TEST_ID="$(extract_key_from_test_env_file 'test' "${TEST_ENV}")"
JSON_FILE="${LOG_DIRECTORY}/${TEST_ID}.json"
create_status_file \
-f "${JSON_FILE}" \
-s ${RESULT} \
-t "${TEST_ID}" \
-r "${GAE_VERSION}" \
|| error_exit "Could not create ${JSON_FILE}."
echo "Uploading logs."
gsutil -h 'Content-Type:text/plain' -m cp -r "${LOG_DIRECTORY}" "${BUCKET}/${GAE_VERSION}"
fi
exit ${RESULT}