From e01e670f9a6cf9350524116de166b8423ad1acb6 Mon Sep 17 00:00:00 2001 From: mehul gautam Date: Thu, 18 Jul 2024 02:54:23 +0530 Subject: [PATCH] Added a docker-compose for hotrod e2e test (#5740) ## Which problem is this PR solving? - https://github.com/jaegertracing/jaeger/issues/5735 ## Description of the changes - added docker-compose file to test hotrod so that is can connect to jaeger ## How was this change tested? - ## Checklist - [ ] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [ ] I have signed all commits - [ ] I have added unit tests for the new functionality - [ ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: mehul gautam Co-authored-by: mehul gautam --- .github/workflows/ci-docker-hotrod.yml | 2 +- examples/hotrod/docker-compose.yml | 6 +-- scripts/hotrod-integration-test.sh | 69 ++++++++++++++++++++++---- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci-docker-hotrod.yml b/.github/workflows/ci-docker-hotrod.yml index 16f39344404..1bba419d9a9 100644 --- a/.github/workflows/ci-docker-hotrod.yml +++ b/.github/workflows/ci-docker-hotrod.yml @@ -51,5 +51,5 @@ jobs: QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} - name: Print logs from hotrod - run: docker logs example-hotrod + run: docker compose -f ./examples/hotrod/docker-compose.yml logs if: failure() diff --git a/examples/hotrod/docker-compose.yml b/examples/hotrod/docker-compose.yml index 250f78f82b8..048de7de59e 100644 --- a/examples/hotrod/docker-compose.yml +++ b/examples/hotrod/docker-compose.yml @@ -1,11 +1,10 @@ version: '3.7' - # To run a specific version of Jaeger, use environment variable, e.g.: # JAEGER_VERSION=1.52 docker compose up services: jaeger: - image: jaegertracing/all-in-one:${JAEGER_VERSION:-latest} + image: ${REGISTRY:-}jaegertracing/all-in-one:${JAEGER_VERSION:-latest} ports: - "16686:16686" - "4317:4317" @@ -14,8 +13,9 @@ services: - LOG_LEVEL=debug networks: - jaeger-example + hotrod: - image: jaegertracing/example-hotrod:${JAEGER_VERSION:-latest} + image: ${REGISTRY:-}jaegertracing/example-hotrod:${JAEGER_VERSION:-latest} # To run the latest trunk build, find the tag at Docker Hub and use the line below # https://hub.docker.com/r/jaegertracing/example-hotrod-snapshot/tags #image: jaegertracing/example-hotrod-snapshot:0ab8f2fcb12ff0d10830c1ee3bb52b745522db6c diff --git a/scripts/hotrod-integration-test.sh b/scripts/hotrod-integration-test.sh index 40149bef8ff..8fc080e9378 100755 --- a/scripts/hotrod-integration-test.sh +++ b/scripts/hotrod-integration-test.sh @@ -2,32 +2,83 @@ set -euxf -o pipefail +docker_compose_file="./examples/hotrod/docker-compose.yml" +platforms="linux/amd64,linux/s390x,linux/ppc64le,linux/arm64" + +teardown() { + echo "Tearing down..." + docker compose -f "$docker_compose_file" down +} +trap teardown EXIT + make build-examples GOOS=linux GOARCH=amd64 make build-examples GOOS=linux GOARCH=s390x make build-examples GOOS=linux GOARCH=ppc64le make build-examples GOOS=linux GOARCH=arm64 -REPO=jaegertracing/example-hotrod -platforms="linux/amd64,linux/s390x,linux/ppc64le,linux/arm64" make prepare-docker-buildx +make create-baseimg -# build image locally (-l) for integration test +# Loop through each platform (separated by commas) +for platform in $(echo "$platforms" | tr ',' ' '); do + # Extract the architecture from the platform string + arch=${platform##*/} # Remove everything before the last slash + make "build-all-in-one" GOOS=linux GOARCH="${arch}" +done + +# Build image locally (-l) for integration test bash scripts/build-upload-a-docker-image.sh -l -c example-hotrod -d examples/hotrod -p "${platforms}" +bash scripts/build-upload-a-docker-image.sh -l -b -c all-in-one -d cmd/all-in-one -p "${platforms}" -t release -# pass --name example-hotrod so that we can do `docker logs example-hotrod` later -export CID -CID=$(docker run -d --name example-hotrod -p 8080:8080 "localhost:5000/${REPO}:${GITHUB_SHA}") +JAEGER_VERSION=$GITHUB_SHA REGISTRY="localhost:5000/" docker compose -f "$docker_compose_file" up -d i=0 -while [[ "$(curl -s -o /dev/null -w '%{http_code}' localhost:8080)" != "200" && ${i} -lt 30 ]]; do +while [[ "$(curl -s -o /dev/null -w '%{http_code}' localhost:8080)" != "200" && $i -lt 30 ]]; do sleep 1 i=$((i+1)) done + body=$(curl localhost:8080) if [[ $body != *"Rides On Demand"* ]]; then echo "String \"Rides On Demand\" is not present on the index page" exit 1 fi -docker rm -f "$CID" -bash scripts/build-upload-a-docker-image.sh -c example-hotrod -d examples/hotrod -p "${platforms}" +response=$(curl -i -X POST "http://localhost:8080/dispatch?customer=123") +TRACE_ID=$(echo "$response" | grep -Fi "Traceresponse:" | awk '{print $2}' | cut -d '-' -f 2) + +if [ -n "$TRACE_ID" ]; then + echo "TRACE_ID is not empty: $TRACE_ID" +else + echo "TRACE_ID is empty" + exit 1 +fi + +JAEGER_QUERY_URL="http://localhost:16686" +EXPECTED_SPANS=35 +MAX_RETRIES=30 +SLEEP_INTERVAL=10 + +# Function to poll Jaeger for the trace +poll_jaeger() { + local trace_id=$1 + local url="${JAEGER_QUERY_URL}/api/traces/${trace_id}" + + curl -s "${url}" | jq '.data[0].spans | length' || echo "0" +} + +# Polling loop +for ((i=1; i<=MAX_RETRIES; i++)); do + span_count=$(poll_jaeger "${TRACE_ID}") + + if [[ "$span_count" -ge "$EXPECTED_SPANS" ]]; then + echo "Trace found with $span_count spans." + exit 0 + fi + + echo "Retry $i/$MAX_RETRIES: Trace not found or insufficient spans ($span_count/$EXPECTED_SPANS). Retrying in $SLEEP_INTERVAL seconds..." + sleep $SLEEP_INTERVAL +done + +echo "Failed to find the trace with the expected number of spans within the timeout period." +exit 1