Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run v2 e2e integration tests for Kafka #5782

Merged
merged 8 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/ci-e2e-kafka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ permissions: # added using https://github.com/step-security/secure-workflows
jobs:
kafka:
runs-on: ubuntu-latest
strategy:
matrix:
jaeger-version: [v1, v2] # Adjust if there are specific versions of Jaeger
name: Kafka Integration Tests ${{ matrix.jaeger-version }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
Expand All @@ -30,9 +34,9 @@ jobs:
with:
go-version: 1.22.x

- name: Run kafka integration tests
- name: Run Kafka integration tests
id: test-execution
run: bash scripts/kafka-integration-test.sh -k
run: bash scripts/kafka-integration-test.sh -k ${{ matrix.jaeger-version }}

- name: Output Kafka logs on failure
run: docker compose -f ${{ steps.test-execution.outputs.docker_compose_file }} logs
Expand All @@ -42,4 +46,4 @@ jobs:
uses: ./.github/actions/upload-codecov
with:
files: cover.out
flags: kafka
flags: kafka-${{ matrix.jaeger-version }}
114 changes: 82 additions & 32 deletions scripts/kafka-integration-test.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,44 +1,94 @@
#!/bin/bash

set -e
set -euxf -o pipefail

export STORAGE=kafka
compose_file="docker-compose/kafka-integration-test/docker-compose.yml"
usage() {
echo $"Usage: $0 -k <test_version>"
joeyyy09 marked this conversation as resolved.
Show resolved Hide resolved
exit 1
}

check_args() {
if [ $# -ne 2 ]; then
echo "ERROR: need exactly two arguments, -k and <test_version>"
usage
fi
}

setup_kafka() {
local compose_file=$1
echo "Starting Kafka using Docker Compose..."
docker compose -f "${compose_file}" up -d kafka
echo "docker_compose_file=${compose_file}" >> "${GITHUB_OUTPUT:-/dev/null}"
}

# Check if the -k parameter is provided and start Kafka if it was
if [ "$1" == "-k" ]; then
echo "Starting Kafka using Docker Compose..."
docker compose -f "${compose_file}" up -d kafka
echo "docker_compose_file=${compose_file}" >> "${GITHUB_OUTPUT:-/dev/null}"
fi
teardown_kafka() {
local compose_file=$1
echo "Stopping Kafka..."
docker compose -f "${compose_file}" down
}

# Check if Kafka is ready by attempting to list topics
is_kafka_ready() {
docker compose -f "${compose_file}" \
exec kafka /opt/bitnami/kafka/bin/kafka-topics.sh \
--list \
--bootstrap-server localhost:9092 \
>/dev/null 2>&1
}

# Set the timeout in seconds
timeout=180
# Set the interval between checks in seconds
interval=5
# Calculate the end time
end_time=$((SECONDS + timeout))

while [ $SECONDS -lt $end_time ]; do
if is_kafka_ready; then
break
local compose_file=$1
docker compose -f "${compose_file}" \
exec kafka /opt/bitnami/kafka/bin/kafka-topics.sh \
--list \
--bootstrap-server localhost:9092 \
>/dev/null 2>&1
}

wait_for_kafka() {
local compose_file=$1
local timeout=180
local interval=5
local end_time=$((SECONDS + timeout))

while [ $SECONDS -lt $end_time ]; do
if is_kafka_ready "$compose_file"; then
echo "Kafka is ready."
return
fi
echo "Kafka broker not ready, waiting ${interval} seconds"
sleep $interval
done
done

echo "Timed out waiting for Kafka to start"
exit 1
}

run_integration_test() {
local version=$1

if ! is_kafka_ready; then
echo "Timed out waiting for Kafka to start"
if [ "${version}" = "v1" ]; then
STORAGE=kafka make storage-integration-test
exit_status=$?
elif [ "${version}" = "v2" ]; then
STORAGE=kafka make jaeger-v2-storage-integration-test
exit_status=$?
joeyyy09 marked this conversation as resolved.
Show resolved Hide resolved
else
echo "Unknown test version ${version}. Valid options are v1 or v2"
exit 1
fi
fi

if [ $exit_status -ne 0 ]; then
echo "Integration tests failed."
exit $exit_status
fi
}

main() {
check_args "$@"

local compose_file="docker-compose/kafka-integration-test/docker-compose.yml"

echo "Executing Kafka integration test for version $2"

if [ "$1" == "-k" ]; then
setup_kafka "${compose_file}"
joeyyy09 marked this conversation as resolved.
Show resolved Hide resolved
wait_for_kafka "${compose_file}"
trap "teardown_kafka ${compose_file}" EXIT
joeyyy09 marked this conversation as resolved.
Show resolved Hide resolved
fi

run_integration_test "$2"
}

make storage-integration-test
main "$@"
Loading