From 9a88296b538b1c4e1383fa05db3c2534809477e4 Mon Sep 17 00:00:00 2001 From: Rodrigo Zhou Date: Tue, 16 Jul 2024 19:12:44 -0500 Subject: [PATCH] Fix ES docker container for GHA tests (#6284) --- .github/workflows/run-tests.yml | 119 +++++++++++------------------- develop/github/docker-compose.yml | 10 +++ tests/test_cluster.go | 24 ++++-- 3 files changed, 69 insertions(+), 84 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 69ea3b43d5..6c26bf088c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -59,25 +59,6 @@ jobs: - run: make build-tests - cache-docker-images: - name: Cache Docker images - strategy: - fail-fast: false - matrix: - runs-on: [ubuntu-20.04] - runs-on: ${{ matrix.runs-on }} - steps: - - uses: ScribeMD/docker-cache@0.3.7 - with: - key: docker-${{ runner.os }}-${{ hashFiles(env.DOCKER_COMPOSE_FILE) }} - - - uses: actions/checkout@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - ref: ${{ env.COMMIT }} - - - run: docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} pull - unit-test: name: Unit test needs: misc-checks @@ -107,17 +88,13 @@ jobs: integration-test: name: Integration test - needs: [misc-checks, cache-docker-images] + needs: misc-checks strategy: fail-fast: false matrix: runs-on: [ubuntu-20.04] runs-on: ${{ matrix.runs-on }} steps: - - uses: ScribeMD/docker-cache@0.3.7 - with: - key: docker-${{ runner.os }}-${{ hashFiles(env.DOCKER_COMPOSE_FILE) }} - - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -129,8 +106,14 @@ jobs: check-latest: true - name: Start containerized dependencies - run: | - docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} up -d cassandra mysql postgresql + uses: hoverkraft-tech/compose-action@v2.0.1 + with: + compose-file: ${{ env.DOCKER_COMPOSE_FILE }} + services: | + cassandra + mysql + postgresql + down-flags: -v - name: Run integration test timeout-minutes: 15 @@ -140,21 +123,16 @@ jobs: if: ${{ !cancelled() }} run: make upload-test-results - - name: Tear down docker compose - if: ${{ always() }} - run: | - docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} down -v - functional-test: name: Functional test - needs: [misc-checks, cache-docker-images] + needs: misc-checks strategy: fail-fast: false matrix: runs-on: [ubuntu-20.04] name: - cass_es - # - cass_es8 + - cass_es8 - sqlite - mysql8 - postgres12 @@ -165,10 +143,12 @@ jobs: persistence_type: nosql persistence_driver: cassandra containers: [cassandra, elasticsearch] - # - name: cass_es8 - # persistence_type: nosql - # persistence_driver: cassandra - # containers: [cassandra, elasticsearch8] + es_version: v7 + - name: cass_es8 + persistence_type: nosql + persistence_driver: cassandra + containers: [cassandra, elasticsearch8] + es_version: v8 - name: sqlite persistence_type: sql persistence_driver: sqlite @@ -192,10 +172,6 @@ jobs: PERSISTENCE_TYPE: ${{ matrix.persistence_type }} PERSISTENCE_DRIVER: ${{ matrix.persistence_driver }} steps: - - uses: ScribeMD/docker-cache@0.3.7 - with: - key: docker-${{ runner.os }}-${{ hashFiles(env.DOCKER_COMPOSE_FILE) }} - - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -208,8 +184,11 @@ jobs: - name: Start containerized dependencies if: ${{ toJson(matrix.containers) != '[]' }} - run: | - docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} up -d ${{ join(matrix.containers, ' ') }} + uses: hoverkraft-tech/compose-action@v2.0.1 + with: + compose-file: ${{ env.DOCKER_COMPOSE_FILE }} + services: "${{ join(matrix.containers, '\n') }}" + down-flags: -v - name: Run functional test timeout-minutes: 30 # make sure this is larger than the test timeout in the Makefile @@ -219,14 +198,9 @@ jobs: if: ${{ !cancelled() }} run: make upload-test-results - - name: Tear down docker compose - if: ${{ always() }} - run: | - docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} down -v - functional-test-xdc: name: Functional test xdc - needs: [misc-checks, cache-docker-images] + needs: misc-checks strategy: fail-fast: false matrix: @@ -259,10 +233,6 @@ jobs: PERSISTENCE_TYPE: ${{ matrix.persistence_type }} PERSISTENCE_DRIVER: ${{ matrix.persistence_driver }} steps: - - uses: ScribeMD/docker-cache@0.3.7 - with: - key: docker-${{ runner.os }}-${{ hashFiles(env.DOCKER_COMPOSE_FILE) }} - - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -275,8 +245,11 @@ jobs: - name: Start containerized dependencies if: ${{ toJson(matrix.containers) != '[]' }} - run: | - docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} up -d ${{ join(matrix.containers, ' ') }} + uses: hoverkraft-tech/compose-action@v2.0.1 + with: + compose-file: ${{ env.DOCKER_COMPOSE_FILE }} + services: "${{ join(matrix.containers, '\n') }}" + down-flags: -v - name: Run functional test xdc timeout-minutes: 15 @@ -286,21 +259,16 @@ jobs: if: ${{ !cancelled() }} run: make upload-test-results - - name: Tear down docker compose - if: ${{ always() }} - run: | - docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} down -v - functional-test-ndc: name: Functional test ndc - needs: [misc-checks, cache-docker-images] + needs: misc-checks strategy: fail-fast: false matrix: runs-on: [ubuntu-20.04] name: - cass_es - # - cass_es8 + - cass_es8 - mysql8 - postgres12 - postgres12_pgx @@ -309,10 +277,12 @@ jobs: persistence_type: nosql persistence_driver: elasticsearch containers: [cassandra, elasticsearch] - # - name: cass_es8 - # persistence_type: nosql - # persistence_driver: elasticsearch - # containers: [cassandra, elasticsearch8] + es_version: v7 + - name: cass_es8 + persistence_type: nosql + persistence_driver: elasticsearch + containers: [cassandra, elasticsearch8] + es_version: v8 - name: mysql8 persistence_type: sql persistence_driver: mysql8 @@ -329,11 +299,8 @@ jobs: env: PERSISTENCE_TYPE: ${{ matrix.persistence_type }} PERSISTENCE_DRIVER: ${{ matrix.persistence_driver }} + ES_VERSION: ${{ matrix.es_version }} steps: - - uses: ScribeMD/docker-cache@0.3.7 - with: - key: docker-${{ runner.os }}-${{ hashFiles(env.DOCKER_COMPOSE_FILE) }} - - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -346,18 +313,16 @@ jobs: - name: Start containerized dependencies if: ${{ toJson(matrix.containers) != '[]' }} - run: | - docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} up -d ${{ join(matrix.containers, ' ') }} + uses: hoverkraft-tech/compose-action@v2.0.1 + with: + compose-file: ${{ env.DOCKER_COMPOSE_FILE }} + services: "${{ join(matrix.containers, '\n') }}" + down-flags: -v - name: Run functional test ndc timeout-minutes: 15 run: make functional-test-ndc-coverage - - name: Tear down docker compose - if: ${{ always() }} - run: | - docker compose -f ${{ env.DOCKER_COMPOSE_FILE }} down -v - test-status: name: Test Status needs: diff --git a/develop/github/docker-compose.yml b/develop/github/docker-compose.yml index 31e74bc940..e0be54590d 100644 --- a/develop/github/docker-compose.yml +++ b/develop/github/docker-compose.yml @@ -32,12 +32,22 @@ services: ports: - "9200:9200" environment: + - cluster.routing.allocation.disk.threshold_enabled=true + - cluster.routing.allocation.disk.watermark.low=512mb + - cluster.routing.allocation.disk.watermark.high=256mb + - cluster.routing.allocation.disk.watermark.flood_stage=128mb - discovery.type=single-node + - ES_JAVA_OPTS=-Xms1g -Xmx1g elasticsearch8: image: elasticsearch:8.0.0 ports: - "9200:9200" environment: + - cluster.routing.allocation.disk.threshold_enabled=true + - cluster.routing.allocation.disk.watermark.low=512mb + - cluster.routing.allocation.disk.watermark.high=256mb + - cluster.routing.allocation.disk.watermark.flood_stage=128mb - discovery.type=single-node - xpack.security.enabled=false + - ES_JAVA_OPTS=-Xms1g -Xmx1g diff --git a/tests/test_cluster.go b/tests/test_cluster.go index 4f72fb2db6..10fb8e5c33 100644 --- a/tests/test_cluster.go +++ b/tests/test_cluster.go @@ -223,8 +223,10 @@ func NewClusterWithPersistenceTestBaseFactory(t *testing.T, options *TestCluster return nil, err } - // Disable standard to elasticsearch dual visibility - pConfig.VisibilityStore = "" + pConfig.VisibilityStore = "test-es-visibility" + pConfig.DataStores[pConfig.VisibilityStore] = config.DataStore{ + Elasticsearch: options.ESConfig, + } indexName = options.ESConfig.GetVisibilityIndex() esClient, err = esclient.NewClient(options.ESConfig, nil, logger) if err != nil { @@ -374,7 +376,17 @@ func setupIndex(esConfig *esclient.Config, logger log.Logger) error { logger.Info("Index template created.") logger.Info("Creating index.", tag.ESIndex(esConfig.GetVisibilityIndex())) - _, err = esClient.CreateIndex(ctx, esConfig.GetVisibilityIndex(), nil) + _, err = esClient.CreateIndex( + ctx, + esConfig.GetVisibilityIndex(), + map[string]any{ + "settings": map[string]any{ + "index": map[string]any{ + "number_of_replicas": 0, + }, + }, + }, + ) if err != nil { return err } @@ -397,14 +409,12 @@ func setupIndex(esConfig *esclient.Config, logger log.Logger) error { } func waitForYellowStatus(esClient esclient.IntegrationTestsClient, index string) error { - ctxWithTimeout, cancel := context.WithTimeout(context.Background(), 2*time.Minute) - defer cancel() - status, err := esClient.WaitForYellowStatus(ctxWithTimeout, index) + status, err := esClient.WaitForYellowStatus(context.Background(), index) if err != nil { return err } if status == "red" { - return fmt.Errorf("Cluster status for index %s is red", index) + return fmt.Errorf("Elasticsearch index status for %s is red", index) } return nil }