@@ -384,8 +384,8 @@ function checkParams() {
384
384
checkPath PG_CONFIG
385
385
if [ " $? " -ne " 0" ]; then
386
386
# >&2 echo "WARNING: Value given as pg_config: '$PG_CONFIG' not found as file will use as content"
387
- echo " $PG_CONFIG " > $TMP_PATH /pg_congif_tmp .sql
388
- WORKLOAD_CUSTOM_SQL=" $TMP_PATH /pg_congif_tmp .sql"
387
+ echo " $PG_CONFIG " > $TMP_PATH /pg_config_tmp .sql
388
+ WORKLOAD_CUSTOM_SQL=" $TMP_PATH /pg_config_tmp .sql"
389
389
fi
390
390
fi
391
391
@@ -529,18 +529,65 @@ function waitEC2Ready() {
529
529
done
530
530
}
531
531
532
+ # Params:
533
+ # 1) machine name
534
+ # 2) AWS EC2 instance type
535
+ # 3) price
536
+ # 4) duration (minutes)
537
+ # 5) key pair name
538
+ # 6) key path
532
539
function createDockerMachine() {
533
540
echo " Attempt to create a docker machine..."
534
541
docker-machine create --driver=amazonec2 \
535
542
--amazonec2-request-spot-instance \
536
- --amazonec2-keypair-name=" $AWS_KEY_PAIR " \
537
- --amazonec2-ssh-keypath=" $AWS_KEY_PATH " \
538
- --amazonec2-block-duration-minutes=60 \
539
- --amazonec2-instance-type=$AWS_EC2_TYPE \
540
- --amazonec2-spot-price=$EC2_PRICE \
541
- $DOCKER_MACHINE &
543
+ --amazonec2-keypair-name=" $5 " \
544
+ --amazonec2-ssh-keypath=" $6 " \
545
+ --amazonec2-block-duration-minutes=$4 \
546
+ --amazonec2-instance-type=$2 \
547
+ --amazonec2-spot-price=$3 \
548
+ $1 2> >( grep -v " failed waiting for successful resource state " >&2 ) &
542
549
}
543
550
551
+ function destroyDockerMachine() {
552
+ # If spot request wasn't fulfilled, there is no associated instance,
553
+ # so "docker-machine rm" will show an error, which is safe to ignore.
554
+ # We better filter it out to avoid any confusions.
555
+ # What is used here is called "process substitution",
556
+ # see https://www.gnu.org/software/bash/manual/bash.html#Process-Substitution
557
+ # The same trick is used in createDockerMachine to filter out errors
558
+ # when we have "price-too-low" attempts, such errors come in few minutes
559
+ # after an attempt and are generally unexpected by user.
560
+ cmdout=$( docker-machine rm --force $1 2> >( grep -v " unknown instance" >&2 ) )
561
+ echo " Termination requested for machine '$1 ', current status: $cmdout "
562
+ }
563
+
564
+ function cleanupAndExit {
565
+ echo " Remove temp files..." # if exists
566
+ rm -f " $TMP_PATH /after_db_init_code_tmp.sql"
567
+ rm -f " $TMP_PATH /workload_custom_sql_tmp.sql"
568
+ rm -f " $TMP_PATH /target_ddl_do_tmp.sql"
569
+ rm -f " $TMP_PATH /target_ddl_undo_tmp.sql"
570
+ rm -f " $TMP_PATH /target_config_tmp.conf"
571
+ rm -f " $TMP_PATH /pg_config_tmp.conf"
572
+ if [ " $RUN_ON " = " localhost" ]; then
573
+ rm -rf " $TMP_PATH /nancy_${containerHash} "
574
+ echo " Remove docker container"
575
+ docker container rm -f $containerHash
576
+ elif [ " $RUN_ON " = " aws" ]; then
577
+ destroyDockerMachine $DOCKER_MACHINE
578
+ if [ ! -z ${VOLUME_ID+x} ]; then
579
+ echo " Wait and delete volume $VOLUME_ID "
580
+ sleep 60 # wait to machine removed
581
+ delvolout=$( aws ec2 delete-volume --volume-id $VOLUME_ID )
582
+ echo " Volume $VOLUME_ID deleted"
583
+ fi
584
+ else
585
+ >&2 echo " ASSERT: must not reach this point"
586
+ exit 1
587
+ fi
588
+ }
589
+ trap cleanupAndExit EXIT
590
+
544
591
if [[ " $RUN_ON " = " localhost" ]]; then
545
592
if [ -z ${CONTAINER_ID+x} ]; then
546
593
containerHash=$( docker run --name=" pg_nancy_${CURRENT_TS} " \
@@ -569,11 +616,22 @@ elif [[ "$RUN_ON" = "aws" ]]; then
569
616
echo " Increased price: $price "
570
617
EC2_PRICE=$price
571
618
572
- createDockerMachine;
619
+ createDockerMachine $DOCKER_MACHINE $AWS_EC2_TYPE $EC2_PRICE \
620
+ 60 $AWS_KEY_PAIR $AWS_KEY_PATH ;
573
621
status=$( waitEC2Ready " docker-machine create" " $DOCKER_MACHINE " 1)
574
622
if [ " $status " == " price-too-low" ]
575
623
then
576
- echo " Price $price is too low for $AWS_EC2_TYPE instance. Try detect actual."
624
+ echo " Price $price is too low for $AWS_EC2_TYPE instance. Getting the up-to-date value from the error message..."
625
+
626
+ # destroyDockerMachine $DOCKER_MACHINE
627
+ # "docker-machine rm" doesn't work for "price-too-low" spot requests,
628
+ # so we need to clean up them via aws cli interface directly
629
+ aws ec2 describe-spot-instance-requests \
630
+ --filters ' Name=status-code,Values=price-too-low' \
631
+ | grep SpotInstanceRequestId | awk ' {gsub(/[,"]/, "", $2); print $2}' \
632
+ | xargs --no-run-if-empty aws ec2 cancel-spot-instance-requests \
633
+ --spot-instance-request-ids
634
+
577
635
corrrectPriceForLastFailedRequest=$( \
578
636
aws ec2 describe-spot-instance-requests \
579
637
--filters=" Name=launch.instance-type,Values=$AWS_EC2_TYPE " \
@@ -588,7 +646,8 @@ elif [[ "$RUN_ON" = "aws" ]]; then
588
646
DOCKER_MACHINE=" ${DOCKER_MACHINE// _/ -} "
589
647
# try start docker machine name with new price
590
648
echo " Attempt to create a new docker machine: $DOCKER_MACHINE with price: $EC2_PRICE ."
591
- createDockerMachine;
649
+ createDockerMachine $DOCKER_MACHINE $AWS_EC2_TYPE $EC2_PRICE \
650
+ 60 $AWS_KEY_PAIR $AWS_KEY_PATH ;
592
651
waitEC2Ready " docker-machine create" " $DOCKER_MACHINE " 0;
593
652
else
594
653
>&2 echo " ERROR: Cannot determine actual price for the instance $AWS_EC2_TYPE ."
@@ -657,35 +716,6 @@ else
657
716
exit 1
658
717
fi
659
718
660
- function cleanup {
661
- echo " Remove temp files..." # if exists
662
- rm -f " $TMP_PATH /after_db_init_code_tmp.sql"
663
- rm -f " $TMP_PATH /workload_custom_sql_tmp.sql"
664
- rm -f " $TMP_PATH /target_ddl_do_tmp.sql"
665
- rm -f " $TMP_PATH /target_ddl_undo_tmp.sql"
666
- rm -f " $TMP_PATH /target_config_tmp.conf"
667
- rm -f " $TMP_PATH /pg_config_tmp.conf"
668
- if [ " $RUN_ON " = " localhost" ]; then
669
- rm -rf " $TMP_PATH /nancy_${containerHash} "
670
- echo " Remove docker container"
671
- docker container rm -f $containerHash
672
- elif [ " $RUN_ON " = " aws" ]; then
673
- cmdout=$( docker-machine rm --force $DOCKER_MACHINE )
674
- echo " Finished working with machine $DOCKER_MACHINE , termination requested, current status: $cmdout "
675
- if [ ! -z ${VOLUME_ID+x} ]; then
676
- echo " Wait and delete volume $VOLUME_ID "
677
- sleep 60 # wait to machine removed
678
- delvolout=$( aws ec2 delete-volume --volume-id $VOLUME_ID )
679
- echo " Volume $VOLUME_ID deleted"
680
- fi
681
- else
682
- >&2 echo " ASSERT: must not reach this point"
683
- exit 1
684
- fi
685
- }
686
- trap cleanup EXIT
687
-
688
-
689
719
alias docker_exec=' docker $dockerConfig exec -i ${containerHash} '
690
720
691
721
MACHINE_HOME=" /machine_home/nancy_${containerHash} "
@@ -825,9 +855,10 @@ echo -e "Report: $ARTIFACTS_DESTINATION/$ARTIFACTS_FILENAME.json"
825
855
echo -e " Query log: $ARTIFACTS_DESTINATION /$ARTIFACTS_FILENAME .log.gz"
826
856
echo -e " -------------------------------------------"
827
857
echo -e " Summary:"
828
- echo -e " Queries number:\t\t" $( cat $ARTIFACTS_DESTINATION /$ARTIFACTS_FILENAME .json | jq ' .overall_stat.queries_number' )
829
858
echo -e " Queries duration:\t\t" $( cat $ARTIFACTS_DESTINATION /$ARTIFACTS_FILENAME .json | jq ' .overall_stat.queries_duration' ) " ms"
830
- echo -e " Errors number:\t\t" $( cat $ARTIFACTS_DESTINATION /$ARTIFACTS_FILENAME .json | jq ' .overall_stat.errors_number' )
859
+ echo -e " Queries count:\t\t" $( cat $ARTIFACTS_DESTINATION /$ARTIFACTS_FILENAME .json | jq ' .overall_stat.queries_number' )
860
+ echo -e " Normalized queries count:\t" $( cat $ARTIFACTS_DESTINATION /$ARTIFACTS_FILENAME .json | jq ' .normalyzed_info| length' )
861
+ echo -e " Errors count:\t\t\t" $( cat $ARTIFACTS_DESTINATION /$ARTIFACTS_FILENAME .json | jq ' .overall_stat.errors_number' )
831
862
echo -e " -------------------------------------------"
832
863
833
864
sleep $DEBUG_TIMEOUT
0 commit comments