diff --git a/benchmarker.sh b/benchmarker.sh index 2ddd83a..8130031 100755 --- a/benchmarker.sh +++ b/benchmarker.sh @@ -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]" diff --git a/scripts/logger.sh b/scripts/logger.sh index d60b902..5a84134 100755 --- a/scripts/logger.sh +++ b/scripts/logger.sh @@ -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" diff --git a/scripts/randomly-generate-high-velocity-data.sh b/scripts/randomly-generate-high-velocity-data.sh index b7ce0f7..22249f4 100755 --- a/scripts/randomly-generate-high-velocity-data.sh +++ b/scripts/randomly-generate-high-velocity-data.sh @@ -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!" diff --git a/scripts/ui_utils.sh b/scripts/ui_utils.sh index 03b9123..54b0ad0 100755 --- a/scripts/ui_utils.sh +++ b/scripts/ui_utils.sh @@ -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