Skip to content

Commit

Permalink
Use docker compose for elasticsearch/opensearch integration tests (#5490
Browse files Browse the repository at this point in the history
)

## Which problem is this PR solving?

Part of #5485

## Description of the changes
* updated `script/es-integration-test.sh` to use docker compose files
* updated `.github/workflows/ci-elasticsearch.yml` now it only passes
the major version for elasticsearch
* updated `.github/workflows/ci-opensearch.yml` now it only passes major
version for opensearch
* added docker compose files at `docker-compose/elasticsearch` and
`docker-compose/opensearch`
* removed` setup_es` and `setup_opensearch` function and a generalized
`setup_db()` function

## How was this change tested?
- CI

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: Your Name <you@example.com>
Signed-off-by: mehul gautam  <mehulsharma4786@gmail.com>
Co-authored-by: Your Name <you@example.com>
  • Loading branch information
hellspawn679 and Your Name committed May 28, 2024
1 parent a7a7308 commit 5900360
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 72 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/ci-elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ jobs:
matrix:
version:
- major: 7.x
image: 7.14.0
distribution: elasticsearch
jaeger: v1
- major: 8.x
image: 8.8.2
distribution: elasticsearch
jaeger: v1
- major: 8.x
image: 8.8.2
distribution: elasticsearch
jaeger: v2
name: ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}
Expand All @@ -57,10 +54,10 @@ jobs:
run: make install-ci

- uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0

- name: Run ${{ matrix.version.distribution }} integration tests
id: test-execution
run: bash scripts/es-integration-test.sh ${{ matrix.version.distribution }} ${{ matrix.version.image }} ${{ matrix.version.jaeger }}
run: bash scripts/es-integration-test.sh ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}


- name: Output ${{ matrix.version.distribution }} logs
run: docker logs ${{ steps.test-execution.outputs.cid }}
Expand All @@ -71,3 +68,4 @@ jobs:
with:
files: cover.out,cover-index-cleaner.out,cover-index-rollover.out
flags: ${{ matrix.version.distribution }}-${{ matrix.version.major }}-${{ matrix.version.jaeger }}

6 changes: 2 additions & 4 deletions .github/workflows/ci-opensearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ jobs:
matrix:
version:
- major: 1.x
image: 1.3.7
distribution: opensearch
jaeger: v1
- major: 2.x
image: 2.3.0
distribution: opensearch
jaeger: v1
- major: 2.x
image: 2.3.0
distribution: opensearch
jaeger: v2
name: ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}
Expand Down Expand Up @@ -60,7 +57,8 @@ jobs:

- name: Run ${{ matrix.version.distribution }} integration tests
id: test-execution
run: bash scripts/es-integration-test.sh ${{ matrix.version.distribution }} ${{ matrix.version.image }} ${{ matrix.version.jaeger }}
run: bash scripts/es-integration-test.sh ${{ matrix.version.distribution }} ${{ matrix.version.major }} ${{ matrix.version.jaeger }}


- name: Output ${{ matrix.version.distribution }} logs
run: docker logs ${{ steps.test-execution.outputs.cid }}
Expand Down
14 changes: 14 additions & 0 deletions docker-compose/elasticsearch/v7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.8'

services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0
environment:
- discovery.type=single-node
- http.host=0.0.0.0
- transport.host=127.0.0.1
- xpack.security.enabled=false # Disable security features
- xpack.security.http.ssl.enabled=false # Disable HTTPS
- xpack.monitoring.enabled=false # Disable monitoring features
ports:
- "9200:9200"
16 changes: 16 additions & 0 deletions docker-compose/elasticsearch/v8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'

services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.8.2
environment:
- discovery.type=single-node
- http.host=0.0.0.0
- transport.host=127.0.0.1
- xpack.security.enabled=false # Disable security features
- xpack.security.http.ssl.enabled=false # Disable HTTPS
- action.destructive_requires_name=false
- xpack.monitoring.collection.enabled=false # Disable monitoring features
ports:
- "9200:9200"

12 changes: 12 additions & 0 deletions docker-compose/opensearch/v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.8'

services:
opensearch:
image: opensearchproject/opensearch:1.3.9
environment:
- discovery.type=single-node
- plugins.security.disabled=true
- http.host=0.0.0.0
- transport.host=127.0.0.1
ports:
- "9200:9200"
13 changes: 13 additions & 0 deletions docker-compose/opensearch/v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'

services:
opensearch:
image: opensearchproject/opensearch:2.5.0
environment:
- discovery.type=single-node
- plugins.security.disabled=true
- http.host=0.0.0.0
- transport.host=127.0.0.1
ports:
- "9200:9200"

92 changes: 29 additions & 63 deletions scripts/es-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,115 +18,81 @@ check_arg() {
fi
}

setup_es() {
local tag=$1
local image=docker.elastic.co/elasticsearch/elasticsearch
local params=(
--detach
--publish 9200:9200
--env "http.host=0.0.0.0"
--env "transport.host=127.0.0.1"
--env "xpack.security.enabled=false"
)
local major_version=${tag%%.*}
if (( major_version < 8 )); then
params+=(--env "xpack.monitoring.enabled=false")
else
params+=(--env "xpack.monitoring.collection.enabled=false")
fi
if (( major_version > 7 )); then
params+=(
--env "action.destructive_requires_name=false"
)
fi

local cid
cid=$(docker run "${params[@]}" "${image}:${tag}")
echo "cid=${cid}" >> "$GITHUB_OUTPUT"
echo "${cid}"
}

setup_opensearch() {
local image=opensearchproject/opensearch
local tag=$1
local params=(
--detach
--publish 9200:9200
--env "http.host=0.0.0.0"
--env "transport.host=127.0.0.1"
--env "plugins.security.disabled=true"
)
local cid
cid=$(docker run "${params[@]}" "${image}:${tag}")
setup_db() {
local distro=$1
local compose_file=$2
docker compose -f "${compose_file}" up -d
local cid
cid=$(docker compose -f "${compose_file}" ps -q "${distro}")
echo "cid=${cid}" >> "$GITHUB_OUTPUT"
echo "${cid}"
}

wait_for_storage() {
local distro=$1
local url=$2
local cid=$3
local compose_file=$3
local params=(
--silent
--output
/dev/null
--write-out
"%{http_code}"
)
local counter=0
local max_counter=60
while [[ "$(curl "${params[@]}" "${url}")" != "200" && ${counter} -le ${max_counter} ]]; do
docker inspect "${cid}" | jq '.[].State'
echo "waiting for ${url} to be up..."
local max_attempts=60
local attempt=0
echo "Waiting for ${distro} to be available at ${url}..."
until [[ "$(curl "${params[@]}" "${url}")" == "200" ]] || (( attempt >= max_attempts )); do
attempt=$(( attempt + 1 ))
echo "Attempt: ${attempt} ${distro} is not yet available at ${url}..."
sleep 10
counter=$((counter+1))
done
# after the loop, do final verification and set status as global var

if [[ "$(curl "${params[@]}" "${url}")" != "200" ]]; then
echo "ERROR: ${distro} is not ready"
docker logs "${cid}"
docker kill "${cid}"
echo "ERROR: ${distro} is not ready at ${url} after $(( attempt * 10 )) seconds"
echo "::group::${distro} logs"
docker compose -f "${compose_file}" logs
echo "::endgroup::"
docker compose -f "${compose_file}" down
db_is_up=0
else
echo "SUCCESS: ${distro} is ready"
echo "SUCCESS: ${distro} is available at ${url}"
db_is_up=1
fi
}

bring_up_storage() {
local distro=$1
local version=$2
local cid
local major_version=${version%%.*}
local compose_file="docker-compose/${distro}/v${major_version}.yml"

echo "starting ${distro} ${version}"
for retry in 1 2 3
do
echo "attempt $retry"
if [ "${distro}" = "elasticsearch" ]; then
cid=$(setup_es "${version}")
elif [ "${distro}" == "opensearch" ]; then
cid=$(setup_opensearch "${version}")
if [ "${distro}" = "elasticsearch" ] || [ "${distro}" = "opensearch" ]; then
setup_db "${distro}" "${compose_file}"
else
echo "Unknown distribution $distro. Valid options are opensearch or elasticsearch"
usage
fi
wait_for_storage "${distro}" "http://localhost:9200" "${cid}"
wait_for_storage "${distro}" "http://localhost:9200" "${compose_file}"
if [ ${db_is_up} = "1" ]; then
break
fi
done
if [ ${db_is_up} = "1" ]; then
# shellcheck disable=SC2064
trap "teardown_storage ${cid}" EXIT
trap "teardown_storage ${compose_file}" EXIT
else
echo "ERROR: unable to start ${distro}"
exit 1
fi
}

teardown_storage() {
local cid=$1
docker kill "${cid}"
local compose_file=$1
docker compose -f "${compose_file}" down
}

main() {
Expand All @@ -146,4 +112,4 @@ main() {
fi
}

main "$@"
main "$@"

0 comments on commit 5900360

Please sign in to comment.