-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmarker.sh
executable file
·300 lines (246 loc) · 8.4 KB
/
benchmarker.sh
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/bin/bash
export PATH="$HOME"/.local/bin:$PATH
source scripts/logger.sh /tmp/benchmarker-tui.log
source scripts/ui_utils.sh
ANSIBLE_LOG_FILE=/tmp/ansible-playbook-output.log
rm "$ANSIBLE_LOG_FILE" > /dev/null 2>&1 &
verify-prerequisites() {
log-info "Verifying prerequisites"
declare prerequisites=(whiptail jq dialog)
if ! (aws sts get-caller-identity > /dev/null 2>&1); then
log-error "Must be logged into AWS CLI to use this script. Log into the target AWS account and run this script again" true
exit 1
fi
for application in "${prerequisites[@]}"; do
if ! (command -v "$application" > /dev/null 2>&1); then
log-warn "$application is required to run this script. Installing $application..."
sudo apt install "$application"
fi
done
if ! (command -v ansible > /dev/null 2>&1); then
log-warn "Ansible is required to run this script. Installing Ansible..." true
sudo apt install python3-pip
pip3 install --user ansible jmespath
fi
if ! (ansible-galaxy collection list | grep -i "community.general\|amazon.aws" > /dev/null 2>&1); then
log-warn "Installing Ansible galaxy requirements..." true
cd ansible
ansible-galaxy install -r requirements.yml
cd -
fi
}
initialize-environment() {
check-sudo-pass "Installing dependencies requires sudo permissions."
if [[ "$?" == 0 ]]; then
declare title="Initialize Local Environment"
if (prompt-yes-no "$title"); then
cd ansible
ansible-playbook -i inventories/local -e "ansible_become_password=$PASSWORD" --tags init deploy_benchmarker.yml > "$ANSIBLE_LOG_FILE" 2>&1 &
pid=$!
log-info "Running ansible-playbook 'deploy_benchmarker.yml' with the 'init' tag and logging output to file [$ANSIBLE_LOG_FILE]"
show-tail-box "$title" $pid "$ANSIBLE_LOG_FILE"
msg-box "Successfully initialized the local environment!"
log-info "Successfully initialized the local environment"
cd -
fi
fi
main-menu
}
prompt-for-vpc-id() {
readarray -t vpc_arr < <(aws ec2 describe-vpcs | jq -r '.Vpcs[] | "\(.VpcId) \((.Tags[]? | select(.Key | contains("Name")) | .Value) // "")"' | awk '{print($1, $2 == "" ? "-" : $2);}')
declare prompt=""
for item in "${vpc_arr[@]}"; do
prompt+="$item OFF "
done
VPC_ID=$(whiptail --fb --title "Select VPC" --radiolist "Select which VPC to use to deploy resources into" "$BOX_HEIGHT" "$BOX_WIDTH" "${#vpc_arr[@]}" $prompt 3>&2 2>&1 1>&3)
}
deploy-and-run-benchmarkers() {
declare title="Deploy and Run Benchmarkers"
if (prompt-yes-no "$title"); then
if [[ -z $VPC_ID ]]; then
prompt-for-vpc-id
fi
cd ansible
ansible-playbook -i inventories/local -e vpc_id="$VPC_ID" --tags deploy deploy_benchmarker.yml > "$ANSIBLE_LOG_FILE" 2>&1 &
pid=$!
log-info "Running ansible-playbook 'deploy_benchmarker.yml' with tags [deploy] and logging output to file [$ANSIBLE_LOG_FILE]"
show-tail-box "$title" $pid "$ANSIBLE_LOG_FILE"
msg-box "Successfully deployed and ran benchmarkers!"
log-info "Successfully deployed and ran benchmarkers"
cd -
fi
main-menu
}
destroy-all() {
declare title="Destroy Everything (Clean Slate)"
if (prompt-yes-no "$title"); then
cd ansible
ansible-playbook -i inventories/local --tags 'destroy,destroy_key_pair' deploy_benchmarker.yml > "$ANSIBLE_LOG_FILE" 2>&1 &
pid=$!
log-info "Running ansible-playbook 'deploy_benchmarker.yml' with [destroy,destroy_key_pair] tags and logging output to file [$ANSIBLE_LOG_FILE]"
show-tail-box "$title" $pid "$ANSIBLE_LOG_FILE"
msg-box "Successfully destroyed everything!"
log-info "Successfully destroyed everything"
cd -
fi
main-menu
}
randomly-populate-dynamodb() {
declare title="Populate DynamoDB with Random Data"
declare log_file=/tmp/dynamodb-data-population.log
if (prompt-yes-no "$title"); then
./scripts/randomly-generate-high-velocity-data.sh -i 5000 > "$log_file" 2>&1 &
pid=$!
log-info "Running randomly-generate-high-velocity-data script and logging to [$log_file]"
show-tail-box "$title" $pid "$log_file"
msg-box "Successfully populated DynamoDB with random data!"
log-info "Successfully populated DynamoDB with random data"
fi
main-menu
}
custom-selections() {
declare title="Customize What to Run (Advanced Mode)"
declare choices
declare prompted_for_sudo_pass=false
declare prompted_for_vpc_id=false
declare requires_vpc_id=false
declare tags=""
choices=$(whiptail --separate-output --checklist --fb "$title" "$CHECKBOX_HEIGHT" "$CHECKBOX_WIDTH" 13 \
"PREREQUISITES" "Install Prerequisites for Local Machine" OFF \
"INITIALIZE_ELK" "Initialize Local Elastic Stack" OFF \
"START_ELK" "Start Local Elastic Stack" OFF \
"DEPLOY_CDK" "Deploy CDK" OFF \
"UPLOAD_BIN" "Upload Benchmarker binaries" OFF \
"RUN_BENCHMARKERS" "Run Benchmarkers" OFF \
"STOP_ELK" "Stop Local Elastic Stack" OFF \
"DESTROY" "Destroy Everything except the SSH key" OFF \
"DESTROY_KEY" "Destroy the SSK Key" OFF \
"RUN_DYNAMODB" "Run the DynamoDB Benchmarkers" OFF \
"RUN_DAX" "Run the DAX Benchmarkers" OFF \
"RUN_CRUD" "Run the CRUD benchmarks for both the DynamoDB and DAX benchmarkers" OFF \
"RUN_READ_ONLY" "Run the READ-ONLY benchmarks for both the DynamoDB and DAX benchmarkers" OFF 3>&2 2>&1 1>&3)
if [[ -n $choices ]]; then
for choice in $choices; do
case "$choice" in
"PREREQUISITES")
tags+="prerequisites,"
check-sudo-pass "Installing dependencies requires sudo permissions."
prompted_for_sudo_pass=true
;;
"INITIALIZE_ELK")
tags+="init_elk,"
;;
"START_ELK")
tags+="elk,"
;;
"DEPLOY_CDK")
tags+="cdk,"
requires_vpc_id=true
if [[ -z $VPC_ID ]]; then
prompt-for-vpc-id
prompted_for_vpc_id=true
fi
;;
"UPLOAD_BIN")
tags+="upload,"
;;
"RUN_BENCHMARKERS")
tags+="run,"
requires_vpc_id=true
if [[ -z $VPC_ID ]]; then
prompt-for-vpc-id
prompted_for_vpc_id=true
fi
;;
"STOP_ELK")
tags+="stop_elk,"
;;
"DESTROY")
tags+="destroy,"
;;
"DESTROY_KEY")
tags+="destroy_key_pair,"
;;
"RUN_DYNAMODB")
tags+="dynamodb,"
;;
"RUN_DAX")
tags+="dax,"
;;
"RUN_CRUD")
tags+="crud,"
;;
"RUN_READ_ONLY")
tags+="read-only,"
;;
esac
done
tags=$(echo "$tags" | sed 's/\(.*\),/\1/')
if (prompt-yes-no "Advanced Mode: Deploy tasks with tags: [$tags]"); then
cd ansible
args=""
if [[ $prompted_for_sudo_pass == true ]]; then
args+=" -e ansible_become_password='$PASSWORD'"
fi
if [[ $requires_vpc_id == true && $prompted_for_vpc_id == true ]]; then
args+=" -e vpc_id=$VPC_ID"
fi
ansible-playbook -i inventories/local $args --tags "$tags" deploy_benchmarker.yml > "$ANSIBLE_LOG_FILE" 2>&1 &
pid=$!
log-info "Running ansible-playbook 'deploy_benchmarker.yml' with [$tags] tags and logging output to file [$ANSIBLE_LOG_FILE]"
show-tail-box "$title" $pid "$ANSIBLE_LOG_FILE"
msg-box "Successfully ran custom tasks!"
log-info "Successfully ran custom tasks"
cd -
fi
fi
main-menu
}
main-menu() {
declare choice
choice=$(whiptail --fb --title "DynamoDB + DAX Benchmarker" --menu "Select an action" "$BOX_HEIGHT" "$BOX_WIDTH" 7 \
"I" "(I)nitialize local environment" \
"B" "Open Dash(b)oards" \
"D" "(D)eploy and Run benchmarkers" \
"W" "(W)ipe away everything (Clean Slate)" \
"R" "(R)andomly populate DynamoDB" \
"C" "(C)ustom (Advanced)" \
"X" "E(x)it" 3>&2 2>&1 1>&3)
case $choice in
"I")
initialize-environment
;;
"B")
msg-box "$(cat <<-EOF
This will open two new tabs in Firefox to display the DynamoDB and DAX dashboards.
The default credentials are:
Username: elastic
Password: changeme
EOF
)"
firefox --new-tab --url 'http://localhost:5601/app/dashboards#/view/51721040-24be-11ee-ac2e-ff8a2f0e28da?_g=(filters:!(),refreshInterval:(pause:!t,value:60000),time:(from:now-15m,to:now))' > /dev/null 2>&1 &
firefox --new-tab --url 'http://localhost:5601/app/dashboards#/view/0fe18820-2736-11ee-a70f-4976799912d8?_g=(filters:!(),refreshInterval:(pause:!t,value:60000),time:(from:now-15m,to:now))' > /dev/null 2>&1 &
;;
"D")
deploy-and-run-benchmarkers
;;
"W")
destroy-all
;;
"R")
randomly-populate-dynamodb
;;
"C")
msg-box "This is for advanced users only! Be sure you know what you're doing, as running some things at the same time can cause problems (like destroy and deploy)!"
custom-selections
;;
"X")
clear
exit 0
;;
esac
}
verify-prerequisites
while :; do
main-menu
done