Skip to content

Commit

Permalink
Added a docker-compose for hotrod e2e test (#5740)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- #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 <mehulsharma4786@gamil.com>
Co-authored-by: mehul gautam <mehulsharma4786@gamil.com>
  • Loading branch information
hellspawn679 and mehul gautam authored Jul 17, 2024
1 parent c68136e commit edfee78
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-docker-hotrod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions examples/hotrod/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
69 changes: 60 additions & 9 deletions scripts/hotrod-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit edfee78

Please sign in to comment.