Fixed a nasty bug that was for debugging but was logging sudo pass to log file! Also fixed the script to work properly for logging random data generation and advanced mode

This commit is contained in:
hamilcarBarca17
2023-08-03 13:55:51 -06:00
parent 8b6738722b
commit bc00dca35e
4 changed files with 59 additions and 32 deletions
+49 -26
View File
@@ -40,7 +40,6 @@ verify-prerequisites() {
initialize-environment() {
check-sudo-pass "Installing dependencies requires sudo permissions."
if [[ "$?" == 0 ]]; then
log-info "Sudo pass: $PASSWORD"
declare title="Initialize Local Environment"
if (prompt-yes-no "$title"); then
@@ -82,9 +81,9 @@ deploy-and-run-benchmarkers() {
cd ansible
ansible-playbook -i inventories/local -e vpc_id="$VPC_ID" deploy_benchmarker.yml > "$ANSIBLE_LOG_FILE" 2>&1 &
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 no tags and logging output to file [$ANSIBLE_LOG_FILE]"
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"
@@ -120,13 +119,14 @@ destroy-all() {
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 /tmp/dynamodb-population.log &
./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 [$ANSIBLE_LOG_FILE]"
log-info "Running randomly-generate-high-velocity-data script and logging to [$log_file]"
show-tail-box "$title" $pid "$ANSIBLE_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"
@@ -138,9 +138,12 @@ randomly-populate-dynamodb() {
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" "$BOX_HEIGHT" "$BOX_WIDTH" 13 \
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 \
@@ -159,55 +162,75 @@ custom-selections() {
for choice in $choices; do
case "$choice" in
"PREREQUISITES")
tags+="prerequisites"
tags+="prerequisites,"
check-sudo-pass "Installing dependencies requires sudo permissions."
prompted_for_sudo_pass=true
;;
"INITIALIZE_ELK")
tags+="init_elk"
tags+="init_elk,"
;;
"START_ELK")
tags+="elk"
tags+="elk,"
;;
"DEPLOY_CDK")
tags+="cdk"
;;
"UPLOAD_BIN")
tags+="upload"
;;
"RUN_BENCHMARKERS")
tags+="run"
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"
tags+="stop_elk,"
;;
"DESTROY")
tags+="destroy"
tags+="destroy,"
;;
"DESTROY_KEY")
tags+="destroy_key_pair"
tags+="destroy_key_pair,"
;;
"RUN_DYNAMODB")
tags+="dynamodb"
tags+="dynamodb,"
;;
"RUN_DAX")
tags+="dax"
tags+="dax,"
;;
"RUN_CRUD")
tags+="crud"
tags+="crud,"
;;
"RUN_READ_ONLY")
tags+="read-only"
tags+="read-only,"
;;
esac
done
tags=$(echo "$tags" | sed 's/\(.*\),/\1/')
if (prompt-yes-no "$title"); then
if (prompt-yes-no "Advanced Mode: Deploy tasks with tags: [$tags]"); then
cd ansible
args=""
ansible-playbook -i inventories/local --tags "$tags" deploy_benchmarker.yml > "$ANSIBLE_LOG_FILE" 2>&1 &
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]"
+3 -3
View File
@@ -15,7 +15,7 @@ bold=$(tput bold)
log-error() {
if [[ -z $2 ]]; then
echo -e "${red}${bold}ERROR:${default}${red} $1${default}"
echo -e "ERROR: $1"
else
echo -e "${red}${bold}ERROR:${default}${red} $1${default}"
echo -e "${red}${bold}ERROR:${default}${red} $1${default}" >> "$BENCHMARK_LOG_FILE"
@@ -24,7 +24,7 @@ log-error() {
log-warn() {
if [[ -z $2 ]]; then
echo -e "${gold}${bold}WARN:${default}${gold} $1${default}"
echo -e "WARN: $1"
else
echo -e "${gold}${bold}WARN:${default}${gold} $1${default}"
echo -e "${gold}${bold}WARN:${default}${gold} $1${default}" >> "$BENCHMARK_LOG_FILE"
@@ -33,7 +33,7 @@ log-warn() {
log-info() {
if [[ -z $2 ]]; then
echo -e "${cyan}${bold}INFO:${default}${cyan} $1${default}"
echo -e "INFO: $1"
else
echo -e "${cyan}${bold}INFO:${default}${cyan} $1${default}"
echo -e "${cyan}${bold}INFO:${default}${cyan} $1${default}" >> "$BENCHMARK_LOG_FILE"
@@ -105,10 +105,8 @@ parse-arguments() {
show-properties() {
log-info "Using the following settings to randomly populate the DynamoDB benchmarking table:"
cat <<-EOF
${cyan}
ATTRIBUTES=$ATTRIBUTES
TABLE_NAME=$TABLE_NAME
${default}
EOF
}
@@ -178,3 +176,5 @@ while [[ $items_written -lt $ITEMS ]]; do
log-info "Sleeping for 2 seconds to avoid the partition throughput limits..."
sleep 2
done
echo -e "\n\n\nSuccessfully wrote $items_written randomly generated items to DynamoDB!"
+5 -1
View File
@@ -1,9 +1,13 @@
#!/bin/bash
TERMINAL_HEIGHT=$(tput lines)
BOX_HEIGHT=$(printf "%.0f" "$(echo "scale=2; $TERMINAL_HEIGHT * .5" | bc)")
CHECKBOX_HEIGHT=$(printf "%.0f" "$(echo "scale=2; $TERMINAL_HEIGHT * .5" | bc)")
TAIL_BOX_HEIGHT=$(printf "%.0f" "$(echo "scale=2; $TERMINAL_HEIGHT * .8" | bc)")
TERMINAL_WIDTH=$(tput cols)
BOX_WIDTH=$(printf "%.0f" "$(echo "scale=2; $TERMINAL_WIDTH * .75" | bc)")
CHECKBOX_WIDTH=$(printf "%.0f" "$(echo "scale=2; $TERMINAL_WIDTH * .5" | bc)")
TAIL_BOX_WIDTH=$(printf "%.0f" "$(echo "scale=2; $TERMINAL_WIDTH * .85" | bc)")
msg-box() {
whiptail --fb --msgbox "$1" "$BOX_HEIGHT" "$BOX_WIDTH"
@@ -20,7 +24,7 @@ show-tail-box() {
trap "kill $2 2> /dev/null" EXIT
while kill -0 "$2" 2> /dev/null; do
dialog --title "$1" --exit-label "Finished" --tailbox "$3" "$BOX_HEIGHT" "$BOX_WIDTH"
dialog --title "$1" --exit-label "Finished" --tailbox "$3" "$TAIL_BOX_HEIGHT" "$TAIL_BOX_WIDTH"
done
clear