From b530acfafd75a5b10c72ed98e3fb88029c78a30f Mon Sep 17 00:00:00 2001 From: Kaituo Li Date: Thu, 21 May 2020 14:00:07 -0700 Subject: [PATCH 1/2] Added CI/CD workflows This PR adds CI/CD workflows. CI workflow builds a zip file, installs that on the official odfe docker image, and runs rest test case. CI workflow is triggered via branch pushing. CD workflow builds zip, rpm, deb files and uploads those files to s3. CD workflow is triggered via tag creation. This PR also increases model initialization waiting time as needed on an rest test case as that time can be can be longer on a remote cluster. Testing done: 1. run the scripts on CI/CD workflow on Mac and tested it works. 2. make sure local gradle build time does not increase. --- .github/workflows/CD.yml | 42 +++++++++++++ .github/workflows/CI.yml | 63 +++++++++++++++++++ .../ad/e2e/DetectionResultEvalutationIT.java | 17 ++++- 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/CD.yml create mode 100644 .github/workflows/CI.yml diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml new file mode 100644 index 00000000..aeef4dd2 --- /dev/null +++ b/.github/workflows/CD.yml @@ -0,0 +1,42 @@ +name: Build and Release AD +on: + push: + tags: + - v* + +jobs: + Build-AD: + strategy: + matrix: + java: [14] + + name: Build and Release AD Plugin + runs-on: ubuntu-latest + + steps: + - name: Checkout AD + uses: actions/checkout@v1 + + - name: Configure AWS + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Setup Java ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + - name: Run build + run: | + ./gradlew buildPackages --console=plain -Dbuild.snapshot=false + artifact=`ls build/distributions/*.zip` + rpm_artifact=`ls build/distributions/*.rpm` + deb_artifact=`ls build/distributions/*.deb` + + aws s3 cp $artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/elasticsearch-plugins/opendistro-anomaly-detection/ + aws s3 cp $rpm_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/rpms/opendistro-anomaly-detection/ + aws s3 cp $deb_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/debs/opendistro-anomaly-detection/ + aws cloudfront create-invalidation --distribution-id E1VG5HMIWI4SA2 --paths "/downloads/*" diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..ff3205db --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,63 @@ +name: Build and Test Anomaly detection +on: + push: + branches: + - master + - opendistro-* + +jobs: + Build-ad: + strategy: + matrix: + java: [14] + + name: Build and Test Anomaly detection Plugin + runs-on: ubuntu-latest + + steps: + - name: Checkout AD + uses: actions/checkout@v1 + + - name: Setup Java ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + - name: Run build + run: | + ./gradlew build + ls -ltr build/distributions/ + + - name: Pull and Run Docker + run: | + plugin=`ls build/distributions/*.zip` + version=`echo $plugin|awk -F- '{print $4}'| cut -d. -f 1-3` + plugin_version=`echo $plugin|awk -F- '{print $4}'| cut -d. -f 1-4` + echo $version + cd .. + + if docker pull opendistroforelasticsearch/opendistroforelasticsearch:$version + then + echo "FROM opendistroforelasticsearch/opendistroforelasticsearch:$version" >> Dockerfile + + ## The ESRestTest Client uses http by default. + ## Need to disable the security plugin to call the rest api over http. + echo "RUN if [ -d /usr/share/elasticsearch/plugins/opendistro_security ]; then /usr/share/elasticsearch/bin/elasticsearch-plugin remove opendistro_security; fi" >> Dockerfile + echo "RUN if [ -d /usr/share/elasticsearch/plugins/opendistro-anomaly-detection ]; then /usr/share/elasticsearch/bin/elasticsearch-plugin remove opendistro-anomaly-detection; fi" >> Dockerfile + echo "ADD anomaly-detection/build/distributions/opendistro-anomaly-detection-$plugin_version.zip /tmp/" >> Dockerfile + echo "RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch file:/tmp/opendistro-anomaly-detection-$plugin_version.zip" >> Dockerfile + + docker build -t odfe-ad:test . + fi + + - name: Run Docker Image + run: | + cd .. + docker run -p 9200:9200 -d -p 9600:9600 -e "discovery.type=single-node" odfe-ad:test + sleep 90 + curl -XGET http://localhost:9200/_cat/plugins + + - name: Run AD Test + run: | + ./gradlew ':integTestRunner' --tests "com.amazon.opendistroforelasticsearch.ad.rest.*IT" -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" + ./gradlew :integTestRunner --tests "com.amazon.opendistroforelasticsearch.ad.e2e.*IT" -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java index 076f4d83..a619e348 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java @@ -172,7 +172,22 @@ private void startDetector( } catch (Exception e) {} } Thread.sleep(5_000); - getDetectionResult(detectorId, begin, end, client); + // It takes more time to wait for model initialization on a remote cluster + long startTime = System.currentTimeMillis(); + while (true) { + try { + getDetectionResult(detectorId, begin, end, client); + break; + } catch (Exception e) { + long duration = System.currentTimeMillis() - startTime; + // we wait at most 60 secs + if (duration < 60_000) { + Thread.sleep(2_000); + } else { + break; + } + } + } } private String createDetector(String datasetName, int intervalMinutes, RestClient client) throws Exception { From 02b38770c3b9b078b1d03758c6e5d555e1e363d2 Mon Sep 17 00:00:00 2001 From: Kaituo Li Date: Fri, 22 May 2020 19:39:28 -0700 Subject: [PATCH 2/2] Merge multiple test commands into one and refactor test case --- .github/workflows/CI.yml | 3 +-- .../ad/e2e/DetectionResultEvalutationIT.java | 16 +++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ff3205db..28db6aba 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -59,5 +59,4 @@ jobs: - name: Run AD Test run: | - ./gradlew ':integTestRunner' --tests "com.amazon.opendistroforelasticsearch.ad.rest.*IT" -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" - ./gradlew :integTestRunner --tests "com.amazon.opendistroforelasticsearch.ad.e2e.*IT" -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" + ./gradlew :integTestRunner --tests "com.amazon.opendistroforelasticsearch.ad.rest.*IT" --tests "com.amazon.opendistroforelasticsearch.ad.e2e.*IT" -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java index a619e348..5c2ad6aa 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/ad/e2e/DetectionResultEvalutationIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -171,23 +171,21 @@ private void startDetector( getDetectionResult(detectorId, begin, end, client); } catch (Exception e) {} } - Thread.sleep(5_000); - // It takes more time to wait for model initialization on a remote cluster + // It takes time to wait for model initialization long startTime = System.currentTimeMillis(); - while (true) { + do { try { + Thread.sleep(5_000); getDetectionResult(detectorId, begin, end, client); break; } catch (Exception e) { long duration = System.currentTimeMillis() - startTime; // we wait at most 60 secs - if (duration < 60_000) { - Thread.sleep(2_000); - } else { - break; + if (duration > 60_000) { + throw new RuntimeException(e); } } - } + } while (true); } private String createDetector(String datasetName, int intervalMinutes, RestClient client) throws Exception {