Skip to content

Commit a0c05ff

Browse files
committed
move scaletest.sh to top level of scaletest dir
1 parent 5f7c961 commit a0c05ff

File tree

2 files changed

+182
-109
lines changed

2 files changed

+182
-109
lines changed

scaletest/scaletest.sh

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#!/usr/bin/env bash
2+
3+
[[ -n ${VERBOSE:-} ]] && set -x
4+
set -euo pipefail
5+
6+
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
7+
# shellcheck source=scripts/lib.sh
8+
source "${PROJECT_ROOT}/scripts/lib.sh"
9+
10+
DRY_RUN="${DRY_RUN:-0}"
11+
SCALETEST_NAME="${SCALETEST_NAME:-}"
12+
SCALETEST_NUM_WORKSPACES="${SCALETEST_NUM_WORKSPACES:-}"
13+
SCALETEST_SCENARIO="${SCALETEST_SCENARIO:-}"
14+
SCALETEST_PROJECT="${SCALETEST_PROJECT:-}"
15+
SCALETEST_PROMETHEUS_REMOTE_WRITE_USER="${SCALETEST_PROMETHEUS_REMOTE_WRITE_USER:-}"
16+
SCALETEST_PROMETHEUS_REMOTE_WRITE_PASSWORD="${SCALETEST_PROMETHEUS_REMOTE_WRITE_PASSWORD:-}"
17+
SCALETEST_SKIP_CLEANUP="${SCALETEST_SKIP_CLEANUP:-}"
18+
19+
script_name=$(basename "$0")
20+
args="$(getopt -o "" -l dry-run,help,name:,num-workspaces:,project:,scenario:,skip-cleanup -- "$@")"
21+
eval set -- "$args"
22+
while true; do
23+
case "$1" in
24+
--dry-run)
25+
DRY_RUN=1
26+
shift
27+
;;
28+
--help)
29+
echo "Usage: $script_name --name <name> --project <project> [--num-workspaces <num-workspaces>] [--scenario <scenario>] [--dry-run]"
30+
exit 1
31+
;;
32+
--name)
33+
SCALETEST_NAME="$2"
34+
shift 2
35+
;;
36+
--num-workspaces)
37+
SCALETEST_NUM_WORKSPACES="$2"
38+
shift 2
39+
;;
40+
--project)
41+
SCALETEST_PROJECT="$2"
42+
shift 2
43+
;;
44+
--scenario)
45+
SCALETEST_SCENARIO="$2"
46+
shift 2
47+
;;
48+
--skip-cleanup)
49+
SCALETEST_SKIP_CLEANUP=1
50+
shift
51+
;;
52+
--)
53+
shift
54+
break
55+
;;
56+
*)
57+
error "Unrecognized option: $1"
58+
;;
59+
esac
60+
done
61+
62+
dependencies gcloud kubectl terraform
63+
64+
if [[ -z "${SCALETEST_NAME}" ]]; then
65+
echo "Must specify --name"
66+
exit 1
67+
fi
68+
69+
if [[ -z "${SCALETEST_PROJECT}" ]]; then
70+
echo "Must specify --project"
71+
exit 1
72+
fi
73+
74+
if [[ -z "${SCALETEST_NUM_WORKSPACES}" ]]; then
75+
echo "Must specify --num-workspaces"
76+
exit 1
77+
fi
78+
79+
if [[ -z "${SCALETEST_SCENARIO}" ]]; then
80+
echo "Must specify --scenario"
81+
exit 1
82+
fi
83+
84+
if [[ -z "${SCALETEST_PROMETHEUS_REMOTE_WRITE_USER}" ]] || [[ -z "${SCALETEST_PROMETHEUS_REMOTE_WRITE_PASSWORD}" ]]; then
85+
echo "SCALETEST_PROMETHEUS_REMOTE_WRITE_USER or SCALETEST_PROMETHEUS_REMOTE_WRITE_PASSWORD not specified."
86+
echo "No prometheus metrics will be collected!"
87+
read -p "Continue (y/N)? " choice
88+
case "$choice" in
89+
y|Y|yes|YES ) ;;
90+
* ) exit 1;;
91+
esac
92+
fi
93+
94+
SCALETEST_SCENARIO_VARS="${PROJECT_ROOT}/scaletest/terraform/scenario-${SCALETEST_SCENARIO}.tfvars"
95+
if [[ ! -f "${SCALETEST_SCENARIO_VARS}" ]]; then
96+
echo "Scenario ${SCALETEST_SCENARIO_VARS} not found."
97+
echo "Please create it or choose another scenario:"
98+
find "${PROJECT_ROOT}/scaletest/terraform" -type f -name 'scenario-*.tfvars'
99+
exit 1
100+
fi
101+
102+
if [[ "${SCALETEST_SKIP_CLEANUP}" == "true" ]]; then
103+
log "WARNING: you told me to not clean up after myself, so this is now your job!"
104+
fi
105+
106+
CONFIG_DIR="${PROJECT_ROOT}/scaletest/.coderv2"
107+
SCALETEST_SCENARIO_VARS="${PROJECT_ROOT}/scaletest/terraform/scenario-${SCALETEST_SCENARIO}.tfvars"
108+
SCALETEST_SECRETS="${PROJECT_ROOT}/scaletest/terraform/secrets.tfvars"
109+
SCALETEST_SECRETS_TEMPLATE="${PROJECT_ROOT}/scaletest/terraform/secrets.tfvars.tpl"
110+
111+
log "Writing scaletest secrets to file."
112+
SCALETEST_NAME="${SCALETEST_NAME}" \
113+
SCALETEST_PROJECT="${SCALETEST_PROJECT}" \
114+
SCALETEST_PROMETHEUS_REMOTE_WRITE_USER="${SCALETEST_PROMETHEUS_REMOTE_WRITE_USER}" \
115+
SCALETEST_PROMETHEUS_REMOTE_WRITE_PASSWORD="${SCALETEST_PROMETHEUS_REMOTE_WRITE_PASSWORD}" \
116+
envsubst <"${SCALETEST_SECRETS_TEMPLATE}" >"${SCALETEST_SECRETS}"
117+
118+
pushd "${PROJECT_ROOT}/scaletest/terraform"
119+
120+
echo "Initializing terraform."
121+
maybedryrun "$DRY_RUN" terraform init
122+
123+
echo "Setting up infrastructure."
124+
maybedryrun "$DRY_RUN" terraform apply --var-file="${SCALETEST_SCENARIO_VARS}" --var-file="${SCALETEST_SECRETS}" --auto-approve
125+
126+
if [[ "${DRY_RUN}" != 1 ]]; then
127+
SCALETEST_CODER_URL=$(<"${CONFIG_DIR}/url")
128+
else
129+
SCALETEST_CODER_URL="http://coder.dryrun.local:3000"
130+
fi
131+
KUBECONFIG="${PWD}/.coderv2/${SCALETEST_NAME}-cluster.kubeconfig"
132+
echo "Waiting for Coder deployment at ${SCALETEST_CODER_URL} to become ready"
133+
maybedryrun "$DRY_RUN" kubectl --kubeconfig="${KUBECONFIG}" -n "coder-${SCALETEST_NAME}" rollout status deployment/coder
134+
135+
echo "Initializing Coder deployment."
136+
DRY_RUN="$DRY_RUN" "${PROJECT_ROOT}/scaletest/lib/coder_init.sh" "${SCALETEST_CODER_URL}"
137+
138+
echo "Creating ${SCALETEST_NUM_WORKSPACES} workspaces."
139+
DRY_RUN="$DRY_RUN" "${PROJECT_ROOT}/scaletest/lib/coder_shim.sh" scaletest create-workspaces \
140+
--count "${SCALETEST_NUM_WORKSPACES}" \
141+
--template=kubernetes \
142+
--concurrency 10 \
143+
--no-cleanup
144+
145+
echo "Sleeping 10 minutes to establish a baseline measurement."
146+
maybedryrun "$DRY_RUN" sleep 600
147+
148+
echo "Sending traffic to workspaces"
149+
maybedryrun "$DRY_RUN" "${PROJECT_ROOT}/scaletest/lib/coder_workspacetraffic.sh" "${SCALETEST_NAME}"
150+
maybedryrun "$DRY_RUN" kubectl --kubeconfig="${KUBECONFIG}" -n "coder-${SCALETEST_NAME}" wait pods coder-scaletest-workspace-traffic --for condition=Ready
151+
maybedryrun "$DRY_RUN" kubectl --kubeconfig="${KUBECONFIG}" -n "coder-${SCALETEST_NAME}" logs -f pod/coder-scaletest-workspace-traffic
152+
153+
echo "Starting pprof"
154+
maybedryrun "$DRY_RUN" kubectl -n "coder-${SCALETEST_NAME}" port-forward deployment/coder 6061:6060 &
155+
pfpid=$!
156+
maybedryrun "$DRY_RUN" trap 'kill $pfpid' EXIT
157+
158+
echo "Waiting for pprof endpoint to become available"
159+
pprof_attempt_counter=0
160+
while ! maybedryrun "$DRY_RUN" timeout 1 bash -c "echo > /dev/tcp/localhost/6061"; do
161+
if [[ $pprof_attempt_counter -eq 10 ]]; then
162+
echo
163+
echo "pprof failed to become ready in time!"
164+
exit 1
165+
fi
166+
maybedryrun "$DRY_RUN" sleep 3
167+
done
168+
169+
echo "Taking pprof snapshots"
170+
maybedryrun "$DRY_RUN" curl --silent --fail --output "${SCALETEST_NAME}-heap.pprof.gz" http://localhost:6061/debug/pprof/heap
171+
maybedryrun "$DRY_RUN" curl --silent --fail --output "${SCALETEST_NAME}-goroutine.pprof.gz" http://localhost:6061/debug/pprof/goroutine
172+
maybedryrun "$DRY_RUN" kill $pfpid
173+
174+
if [[ "${SCALETEST_SKIP_CLEANUP}" == "true" ]]; then
175+
echo "Leaving resources up for you to inspect."
176+
echo "Please don't forget to clean up afterwards:"
177+
echo "cd terraform && terraform destroy --var-file=${SCALETEST_SCENARIO_VARS} --var-file=${SCALETEST_SECRETS} --auto-approve"
178+
exit 0
179+
fi
180+
181+
echo "Cleaning up"
182+
maybedryrun "$DRY_RUN" terraform destroy --var-file="${SCALETEST_SCENARIO_VARS}" --var-file="${SCALETEST_SECRETS}" --auto-approve

scripts/scaletest.sh

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)