From ccd734826e47b13ed30e2afb1b76372cee67f121 Mon Sep 17 00:00:00 2001 From: Alok Kumar Singh Date: Sat, 16 Nov 2024 18:54:36 +0530 Subject: [PATCH 1/3] Fix cassandra docker-compose health check Signed-off-by: Alok Kumar Singh --- docker-compose/cassandra/v4/docker-compose.yaml | 3 ++- docker-compose/cassandra/v5/docker-compose.yaml | 3 ++- scripts/cassandra-integration-test.sh | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docker-compose/cassandra/v4/docker-compose.yaml b/docker-compose/cassandra/v4/docker-compose.yaml index 196a1b62225..b18539798bc 100644 --- a/docker-compose/cassandra/v4/docker-compose.yaml +++ b/docker-compose/cassandra/v4/docker-compose.yaml @@ -1,6 +1,7 @@ services: cassandra: image: cassandra:4.1 + container_name: "cassandra-4" ports: - "9042:9042" - "9160:9160" @@ -11,7 +12,7 @@ services: networks: - cassandra-net healthcheck: - test: ["CMD", "cqlsh", "-e", "describe keyspaces"] + test: ["CMD", "cqlsh", "-u", "cassandra", "-p", "cassandra", "-e", "describe keyspaces"] interval: 30s timeout: 10s retries: 5 diff --git a/docker-compose/cassandra/v5/docker-compose.yaml b/docker-compose/cassandra/v5/docker-compose.yaml index 282b77f60fb..f407b2d3550 100644 --- a/docker-compose/cassandra/v5/docker-compose.yaml +++ b/docker-compose/cassandra/v5/docker-compose.yaml @@ -1,6 +1,7 @@ services: cassandra: image: cassandra:5.0 + container_name: "cassandra-5" ports: - "9042:9042" - "9160:9160" @@ -11,7 +12,7 @@ services: networks: - cassandra-net healthcheck: - test: ["CMD", "cqlsh", "-e", "describe keyspaces"] + test: ["CMD", "cqlsh", "-u", "cassandra", "-p", "cassandra", "-e", "describe keyspaces"] interval: 30s timeout: 10s retries: 5 diff --git a/scripts/cassandra-integration-test.sh b/scripts/cassandra-integration-test.sh index 53a547ddb45..5d47d9ebe82 100755 --- a/scripts/cassandra-integration-test.sh +++ b/scripts/cassandra-integration-test.sh @@ -26,6 +26,19 @@ setup_cassandra() { docker compose -f "$compose_file" up -d } +healthcheck_cassandra() { + local cas_version=$1 + local container_name="cassandra-${cas_version}" + local status="unhealthy" + while [[ ${status} != "healthy" ]]; do + status=$(docker inspect -f '{{ .State.Health.Status }}' ${container_name}) + echo "healthcheck status=${status}" + # Since the healthcheck in cassandra is done at the interval of 30s + sleep 30; + done; + echo "cassandra is up" +} + dump_logs() { local compose_file=$1 echo "::group::🚧 🚧 🚧 Cassandra logs" @@ -71,6 +84,8 @@ run_integration_test() { setup_cassandra "${compose_file}" + healthcheck_cassandra "${major_version}" + # shellcheck disable=SC2064 trap "teardown_cassandra ${compose_file}" EXIT From 3dfd947222dbb28de91f0fcd9fcb0b79e9bda598 Mon Sep 17 00:00:00 2001 From: Alok Kumar Singh Date: Sat, 16 Nov 2024 19:18:24 +0530 Subject: [PATCH 2/3] shell lint fix Signed-off-by: Alok Kumar Singh --- scripts/cassandra-integration-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cassandra-integration-test.sh b/scripts/cassandra-integration-test.sh index 5d47d9ebe82..d77a2e9245b 100755 --- a/scripts/cassandra-integration-test.sh +++ b/scripts/cassandra-integration-test.sh @@ -31,7 +31,7 @@ healthcheck_cassandra() { local container_name="cassandra-${cas_version}" local status="unhealthy" while [[ ${status} != "healthy" ]]; do - status=$(docker inspect -f '{{ .State.Health.Status }}' ${container_name}) + status=$(docker inspect -f '{{ .State.Health.Status }}' "${container_name}") echo "healthcheck status=${status}" # Since the healthcheck in cassandra is done at the interval of 30s sleep 30; From c74757439f84532594e597706c05b52fd6eeb161 Mon Sep 17 00:00:00 2001 From: Alok Kumar Singh Date: Sun, 17 Nov 2024 10:53:26 +0530 Subject: [PATCH 3/3] Added timeout for healthcheck Signed-off-by: Alok Kumar Singh --- scripts/cassandra-integration-test.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/scripts/cassandra-integration-test.sh b/scripts/cassandra-integration-test.sh index d77a2e9245b..9f5e295bc3c 100755 --- a/scripts/cassandra-integration-test.sh +++ b/scripts/cassandra-integration-test.sh @@ -8,6 +8,8 @@ set -euxf -o pipefail export CASSANDRA_USERNAME="cassandra" export CASSANDRA_PASSWORD="cassandra" success="false" +timeout=600 +end_time=$((SECONDS + timeout)) usage() { echo $"Usage: $0 " @@ -29,14 +31,21 @@ setup_cassandra() { healthcheck_cassandra() { local cas_version=$1 local container_name="cassandra-${cas_version}" - local status="unhealthy" - while [[ ${status} != "healthy" ]]; do + # Since the healthcheck in cassandra is done at the interval of 30s + local wait_seconds=30 + + while [ $SECONDS -lt $end_time ]; do status=$(docker inspect -f '{{ .State.Health.Status }}' "${container_name}") - echo "healthcheck status=${status}" - # Since the healthcheck in cassandra is done at the interval of 30s - sleep 30; - done; - echo "cassandra is up" + if [[ ${status} == "healthy" ]]; then + echo "✅ $container_name is healthy" + return 0 + fi + echo "Waiting for $container_name to be healthy. Current status: $status" + sleep $wait_seconds + done + + echo "❌ ERROR: $container_name did not become healthy in time" + exit 1 } dump_logs() { @@ -84,11 +93,11 @@ run_integration_test() { setup_cassandra "${compose_file}" - healthcheck_cassandra "${major_version}" - # shellcheck disable=SC2064 trap "teardown_cassandra ${compose_file}" EXIT + healthcheck_cassandra "${major_version}" + apply_schema "$schema_version" "$primaryKeyspace" apply_schema "$schema_version" "$archiveKeyspace"