From 22b0cde806c2b71760e1b5adb65d869a48e3d389 Mon Sep 17 00:00:00 2001 From: GWphua Date: Thu, 5 Dec 2024 11:38:41 +0800 Subject: [PATCH 1/5] Add retry mechanism for ZK mirror in Integration Test --- integration-tests/docker/base-setup.sh | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/integration-tests/docker/base-setup.sh b/integration-tests/docker/base-setup.sh index 2a258664fb7b..7fc054e3ab04 100755 --- a/integration-tests/docker/base-setup.sh +++ b/integration-tests/docker/base-setup.sh @@ -31,10 +31,34 @@ apt-get install -y default-mysql-server # Supervisor apt-get install -y supervisor -# Zookeeper +# Retry function to make setup process more robust +retry() { + local retries="$1" + shift + local count=0 + local success=false + + while [ $count -lt "$retries" ]; do + echo "Attempting command... (Attempt $((count + 1)) of $retries)" + + if "$@"; then + success=true + break + else + count=$((count + 1)) + sleep 2 # Optional: wait before retrying + fi + done + if [ "$success" = false ]; then + echo "Command failed after $retries attempts." + exit 1 + fi +} + +# Zookeeper install_zk() { - wget -q -O /tmp/$ZK_TAR.tar.gz "$APACHE_ARCHIVE_MIRROR_HOST/dist/zookeeper/zookeeper-$ZK_VERSION/$ZK_TAR.tar.gz" + retry 3 wget -q -O /tmp/$ZK_TAR.tar.gz "$APACHE_ARCHIVE_MIRROR_HOST/dist/zookeeper/zookeeper-$ZK_VERSION/$ZK_TAR.tar.gz" tar -xzf /tmp/$ZK_TAR.tar.gz -C /usr/local cp /usr/local/$ZK_TAR/conf/zoo_sample.cfg /usr/local/$ZK_TAR/conf/zoo.cfg rm /tmp/$ZK_TAR.tar.gz From fa932541e8430049f237f9377b6abc91dca51a54 Mon Sep 17 00:00:00 2001 From: GWphua Date: Thu, 5 Dec 2024 14:12:59 +0800 Subject: [PATCH 2/5] Add docker-retry --- integration-tests/docker/Dockerfile | 12 +++++++++++- integration-tests/docker/base-setup.sh | 27 +------------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/integration-tests/docker/Dockerfile b/integration-tests/docker/Dockerfile index df8c6f2598be..9506c078cd58 100644 --- a/integration-tests/docker/Dockerfile +++ b/integration-tests/docker/Dockerfile @@ -25,7 +25,17 @@ ARG KAFKA_VERSION # This is passed in by maven at build time to align with the client version we depend on in the pom file ARG ZK_VERSION ARG APACHE_ARCHIVE_MIRROR_HOST=https://archive.apache.org -RUN APACHE_ARCHIVE_MIRROR_HOST=${APACHE_ARCHIVE_MIRROR_HOST} /root/base-setup.sh && rm -f /root/base-setup.sh +ARG SETUP_RETRIES=3 +# Retry mechanism for running the setup script up to limit of 3 times. +RUN set -e; \ + for i in {1..$SETUP_RETRIES}; do \ + echo "Attempt $i to run the setup script..."; \ + APACHE_ARCHIVE_MIRROR_HOST=${APACHE_ARCHIVE_MIRROR_HOST} /root/base-setup.sh && break || { \ + echo "Attempt $i failed. Retrying..."; \ + sleep 2; \ + }; \ + done; \ + rm -f /root/base-setup.sh FROM druidbase ARG MYSQL_VERSION diff --git a/integration-tests/docker/base-setup.sh b/integration-tests/docker/base-setup.sh index 7fc054e3ab04..bd47f8bc1780 100755 --- a/integration-tests/docker/base-setup.sh +++ b/integration-tests/docker/base-setup.sh @@ -31,34 +31,9 @@ apt-get install -y default-mysql-server # Supervisor apt-get install -y supervisor -# Retry function to make setup process more robust -retry() { - local retries="$1" - shift - local count=0 - local success=false - - while [ $count -lt "$retries" ]; do - echo "Attempting command... (Attempt $((count + 1)) of $retries)" - - if "$@"; then - success=true - break - else - count=$((count + 1)) - sleep 2 # Optional: wait before retrying - fi - done - - if [ "$success" = false ]; then - echo "Command failed after $retries attempts." - exit 1 - fi -} - # Zookeeper install_zk() { - retry 3 wget -q -O /tmp/$ZK_TAR.tar.gz "$APACHE_ARCHIVE_MIRROR_HOST/dist/zookeeper/zookeeper-$ZK_VERSION/$ZK_TAR.tar.gz" + wget -q -O /tmp/$ZK_TAR.tar.gz "$APACHE_ARCHIVE_MIRROR_HOST/dist/zookeeper/zookeeper-$ZK_VERSION/$ZK_TAR.tar.gz" tar -xzf /tmp/$ZK_TAR.tar.gz -C /usr/local cp /usr/local/$ZK_TAR/conf/zoo_sample.cfg /usr/local/$ZK_TAR/conf/zoo.cfg rm /tmp/$ZK_TAR.tar.gz From 7a8d3a9ed16131d9200870ec1edd9cae481891f9 Mon Sep 17 00:00:00 2001 From: GWphua Date: Thu, 5 Dec 2024 17:04:17 +0800 Subject: [PATCH 3/5] Update retry logic --- integration-tests/docker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/docker/Dockerfile b/integration-tests/docker/Dockerfile index 9506c078cd58..bbf4d2935878 100644 --- a/integration-tests/docker/Dockerfile +++ b/integration-tests/docker/Dockerfile @@ -28,10 +28,10 @@ ARG APACHE_ARCHIVE_MIRROR_HOST=https://archive.apache.org ARG SETUP_RETRIES=3 # Retry mechanism for running the setup script up to limit of 3 times. RUN set -e; \ - for i in {1..$SETUP_RETRIES}; do \ + for i in $(seq 1 $SETUP_RETRIES); do \ echo "Attempt $i to run the setup script..."; \ APACHE_ARCHIVE_MIRROR_HOST=${APACHE_ARCHIVE_MIRROR_HOST} /root/base-setup.sh && break || { \ - echo "Attempt $i failed. Retrying..."; \ + echo "Set up script attempt $i/$SETUP_RETRIES failed. Retrying..."; \ sleep 2; \ }; \ done; \ From 95a196c7f8a731832ea6c4bdf4b522519c08e487 Mon Sep 17 00:00:00 2001 From: GWphua Date: Fri, 6 Dec 2024 10:45:11 +0800 Subject: [PATCH 4/5] Change on only Dockerfile --- integration-tests/docker/base-setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/integration-tests/docker/base-setup.sh b/integration-tests/docker/base-setup.sh index bd47f8bc1780..2a258664fb7b 100755 --- a/integration-tests/docker/base-setup.sh +++ b/integration-tests/docker/base-setup.sh @@ -32,6 +32,7 @@ apt-get install -y default-mysql-server apt-get install -y supervisor # Zookeeper + install_zk() { wget -q -O /tmp/$ZK_TAR.tar.gz "$APACHE_ARCHIVE_MIRROR_HOST/dist/zookeeper/zookeeper-$ZK_VERSION/$ZK_TAR.tar.gz" tar -xzf /tmp/$ZK_TAR.tar.gz -C /usr/local From 0bcb7c9346bcb47c9a87dd2b2080a903ffbad674 Mon Sep 17 00:00:00 2001 From: GWphua Date: Fri, 6 Dec 2024 11:12:13 +0800 Subject: [PATCH 5/5] Remove retrying log --- integration-tests/docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/docker/Dockerfile b/integration-tests/docker/Dockerfile index bbf4d2935878..89fd45c97784 100644 --- a/integration-tests/docker/Dockerfile +++ b/integration-tests/docker/Dockerfile @@ -31,7 +31,7 @@ RUN set -e; \ for i in $(seq 1 $SETUP_RETRIES); do \ echo "Attempt $i to run the setup script..."; \ APACHE_ARCHIVE_MIRROR_HOST=${APACHE_ARCHIVE_MIRROR_HOST} /root/base-setup.sh && break || { \ - echo "Set up script attempt $i/$SETUP_RETRIES failed. Retrying..."; \ + echo "Set up script attempt $i/$SETUP_RETRIES failed."; \ sleep 2; \ }; \ done; \