diff --git a/.ci/opensearch/Dockerfile.opensearch b/.ci/opensearch/Dockerfile.opensearch index 787b1b864..c0ba778c6 100755 --- a/.ci/opensearch/Dockerfile.opensearch +++ b/.ci/opensearch/Dockerfile.opensearch @@ -3,5 +3,11 @@ FROM opensearchproject/opensearch:${OPENSEARCH_VERSION} ARG opensearch_path=/usr/share/opensearch ARG SECURE_INTEGRATION +ENV SECURE_INTEGRATION=$SECURE_INTEGRATION RUN if [ "$SECURE_INTEGRATION" != "true" ] ; then $opensearch_path/bin/opensearch-plugin remove opensearch-security; fi + +HEALTHCHECK --start-period=20s --interval=5s --retries=5 --timeout=1s \ + CMD if [ "$SECURE_INTEGRATION" != "true" ]; \ + then curl -f http://localhost:9200/_cat/health || exit 1; \ + else curl -fk https://localhost:9200/_cat/health -u admin:admin || exit 1; fi \ No newline at end of file diff --git a/.github/workflows/test-compatibility.yml b/.github/workflows/test-compatibility.yml index 795dc8302..6992a5a02 100644 --- a/.github/workflows/test-compatibility.yml +++ b/.github/workflows/test-compatibility.yml @@ -40,9 +40,12 @@ jobs: export OPENSEARCH_VERSION=${{ matrix.entry.opensearch_version }} export SECURE_INTEGRATION=${{ matrix.secured }} make cluster.clean cluster.build cluster.start - - name: Check Opensearch cluster health - run: | - make cluster.check SECURE_INTEGRATION=${{ matrix.secured }} NUM_CHECKS=30 CHECK_INTERVAL=1 + + - uses: zethuman/healthcheck@v0.0.1 + with: + name: opensearch_opensearch_1 + timeout: 300 + interval: 5 - name: Integration test without security if: ${{ matrix.secured == 'false'}} diff --git a/CHANGELOG.md b/CHANGELOG.md index 69c74688f..94447244c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Adds `advanced_index_actions` guide ([#288](https://github.com/opensearch-project/opensearch-go/pull/288)) - Adds testcases to check UpdateByQuery functionality ([#304](https://github.com/opensearch-project/opensearch-go/pull/304)) - Adds additional timeout after cluster start ([##303](https://github.com/opensearch-project/opensearch-go/pull/303)) +- Adds docker healthcheck to wait for test server to start ([#315](https://github.com/opensearch-project/opensearch-go/pull/315)) ### Changed diff --git a/Makefile b/Makefile index 68db1b3af..ade9b9667 100644 --- a/Makefile +++ b/Makefile @@ -205,37 +205,6 @@ cluster.clean: ## Remove unused Docker volumes and networks docker network prune --force docker system prune --volumes --force -cluster.check: - @printf "\033[2m→ Checking up cluster health...\033[0m\n" - SECURE_INTEGRATION=$(SECURE_INTEGRATION) \ - NUM_CHECKS=$(NUM_CHECKS) \ - CHECK_INTERVAL=$(CHECK_INTERVAL) \ - echo "SECURE_INTEGRATION: $$SECURE_INTEGRATION"; \ - for ((i=1; i<=NUM_CHECKS; i++)); do \ - if [[ $$SECURE_INTEGRATION == "true" ]]; \ - then response=$$(curl --insecure -sS "https://localhost:9200/_cluster/health" -u admin:admin); \ - else response=$$(curl -sS "http://localhost:9200/_cluster/health"); \ - fi; \ - if [[ $$response == *"green"* || $$response == *"yellow"* ]]; then \ - echo "Cluster is healthy."; \ - exit 0; \ - fi; \ - echo "Check #$$i: Cluster is not healthy. Status: $$response"; \ - if [[ $$i == $$((NUM_CHECKS / 5)) ]]; then \ - echo "Restarting OpenSearch Container..."; \ - docker-compose --project-directory .ci/opensearch restart; \ - fi; \ - sleep $$CHECK_INTERVAL; \ - done; \ - echo "Cluster is still not healthy after $$NUM_CHECKS checks."; \ - exit 1; - -cluster.kek: - if [[ "$$SECURE_INTEGRATION" == "false" ]] \ - then HEALTH_CHECK_URL="https://localhost:9200/_cluster/health" \ - else HEALTH_CHECK_URL="http://localhost:9200/_cluster/health" \ - fi; \ - linters: ./bin/golangci-lint run ./... --timeout=5m