From 8e430e3b0696b3ae24a21eac953e870d935f5226 Mon Sep 17 00:00:00 2001 From: Amit Galitzky Date: Mon, 5 Dec 2022 16:16:16 -0800 Subject: [PATCH] Adding windows and mac CI to 1.3 (#745) Signed-off-by: Amit Galitzky --- .github/workflows/CI.yml | 93 ------------------- .../workflows/test_build_multi_platform.yml | 71 ++++++++++++++ .github/workflows/test_bwc.yml | 45 +++++++++ .github/workflows/test_security.yml | 78 ++++++++++++++++ build.gradle | 12 +-- .../ad/e2e/DetectionResultEvalutationIT.java | 12 +-- 6 files changed, 202 insertions(+), 109 deletions(-) delete mode 100644 .github/workflows/CI.yml create mode 100644 .github/workflows/test_build_multi_platform.yml create mode 100644 .github/workflows/test_bwc.yml create mode 100644 .github/workflows/test_security.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml deleted file mode 100644 index 4f2092d21..000000000 --- a/.github/workflows/CI.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: Build and Test Anomaly detection -on: - push: - branches: - - "*" - pull_request: - branches: - - "*" - -jobs: - Build-ad: - strategy: - matrix: - java: [8, 11, 14] - fail-fast: false - - name: Build and Test Anomaly detection Plugin - runs-on: ubuntu-latest - - steps: - - name: Setup Java ${{ matrix.java }} - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.java }} - - # anomaly-detection - - name: Checkout AD - uses: actions/checkout@v2 - - - name: Assemble anomaly-detection - run: | - ./gradlew assemble -Dopensearch.version=1.3.7-SNAPSHOT - echo "Creating ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/1.3.7.0-SNAPSHOT ..." - mkdir -p ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/1.3.7.0-SNAPSHOT - echo "Copying ./build/distributions/*.zip to ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/1.3.7.0-SNAPSHOT ..." - ls ./build/distributions/ - cp ./build/distributions/*.zip ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/1.3.7.0-SNAPSHOT - echo "Copied ./build/distributions/*.zip to ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/1.3.7.0-SNAPSHOT ..." - ls ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/1.3.7.0-SNAPSHOT - - name: Build and Run Tests - run: | - ./gradlew build -Dopensearch.version=1.3.7-SNAPSHOT - - name: Publish to Maven Local - run: | - ./gradlew publishToMavenLocal -Dopensearch.version=1.3.7-SNAPSHOT - - name: Multi Nodes Integration Testing - run: | - ./gradlew integTest -PnumNodes=3 - - name: Pull and Run Docker - run: | - plugin=`ls build/distributions/*.zip` - version=1.3.7 - plugin_version=1.3.7.0-SNAPSHOT - echo Using OpenSearch $version with AD $plugin_version - cd .. - if docker pull opensearchstaging/opensearch:$version - then - echo "FROM opensearchstaging/opensearch:$version" >> Dockerfile - echo "RUN if [ -d /usr/share/opensearch/plugins/opensearch-anomaly-detection ]; then /usr/share/opensearch/bin/opensearch-plugin remove opensearch-anomaly-detection; fi" >> Dockerfile - echo "ADD anomaly-detection/build/distributions/opensearch-anomaly-detection-$plugin_version.zip /tmp/" >> Dockerfile - echo "RUN /usr/share/opensearch/bin/opensearch-plugin install --batch file:/tmp/opensearch-anomaly-detection-$plugin_version.zip" >> Dockerfile - docker build -t opensearch-ad:test . - echo "imagePresent=true" >> $GITHUB_ENV - else - echo "imagePresent=false" >> $GITHUB_ENV - fi - - name: Run Docker Image - if: env.imagePresent == 'true' - run: | - cd .. - docker run -p 9200:9200 -d -p 9600:9600 -e "discovery.type=single-node" opensearch-ad:test - sleep 90 - - name: Run AD Test - if: env.imagePresent == 'true' - run: | - security=`curl -XGET https://localhost:9200/_cat/plugins?v -u admin:admin --insecure |grep opensearch-security|wc -l` - if [ $security -gt 0 ] - then - echo "Security plugin is available" - ./gradlew integTest -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" -Dhttps=true -Duser=admin -Dpassword=admin - else - echo "Security plugin is NOT available" - ./gradlew integTest -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" - fi - - name: Run AD Backwards Compatibility Tests - run: | - echo "Running backwards compatibility tests ..." - ./gradlew bwcTestSuite -Dtests.security.manager=false - - name: Upload Coverage Report - uses: codecov/codecov-action@v1 - with: - file: ./build/reports/jacoco/test/jacocoTestReport.xml - flags: plugin diff --git a/.github/workflows/test_build_multi_platform.yml b/.github/workflows/test_build_multi_platform.yml new file mode 100644 index 000000000..b965366b7 --- /dev/null +++ b/.github/workflows/test_build_multi_platform.yml @@ -0,0 +1,71 @@ +name: Build and Test Anomaly detection +on: + push: + branches: + - "*" + pull_request: + branches: + - "*" + +jobs: + Build-ad-windows: + strategy: + matrix: + java: [8, 11, 14] + name: Build and Test Anomaly Detection Plugin on Windows + runs-on: windows-latest + steps: + - name: Setup Java ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: Checkout Anomaly Detection + uses: actions/checkout@v2 + + - name: Build and Run Tests + run: | + ./gradlew build + - name: Publish to Maven Local + run: | + ./gradlew publishToMavenLocal + - name: Upload Coverage Report + uses: codecov/codecov-action@v1 + with: + file: ./build/reports/jacoco/test/jacocoTestReport.xml + flags: plugin + Build-ad: + strategy: + matrix: + java: [8, 11, 14] + os: [ubuntu-latest, macos-latest] + fail-fast: false + + name: Build and Test Anomaly detection Plugin on multiple platforms + runs-on: ${{ matrix.os }} + + steps: + - name: Setup Java ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + - name: Checkout AD + uses: actions/checkout@v2 + + - name: Assemble anomaly-detection + run: | + ./gradlew assemble + - name: Build and Run Tests + run: | + ./gradlew build -Dtest.logs=true + - name: Publish to Maven Local + run: | + ./gradlew publishToMavenLocal + - name: Multi Nodes Integration Testing + run: | + ./gradlew integTest -PnumNodes=3 + - name: Upload Coverage Report + uses: codecov/codecov-action@v1 + with: + file: ./build/reports/jacoco/test/jacocoTestReport.xml + flags: plugin diff --git a/.github/workflows/test_bwc.yml b/.github/workflows/test_bwc.yml new file mode 100644 index 000000000..98bd0177f --- /dev/null +++ b/.github/workflows/test_bwc.yml @@ -0,0 +1,45 @@ +name: Test Anomaly detection BWC +on: + push: + branches: + - "*" + pull_request: + branches: + - "*" + +jobs: + Build-ad: + strategy: + matrix: + java: [8, 11, 14] + fail-fast: false + + name: Test Anomaly detection BWC + runs-on: ubuntu-latest + + steps: + - name: Setup Java ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + # anomaly-detection + - name: Checkout AD + uses: actions/checkout@v2 + + - name: Assemble anomaly-detection + run: | + plugin_version=`./gradlew properties -q | grep "opensearch_build:" | awk '{print $2}'` + echo plugin_version $plugin_version + ./gradlew assemble + echo "Creating ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/$plugin_version ..." + mkdir -p ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/$plugin_version + echo "Copying ./build/distributions/*.zip to ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/$plugin_version ..." + ls ./build/distributions/ + cp ./build/distributions/*.zip ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/$plugin_version + echo "Copied ./build/distributions/*.zip to ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/$plugin_version ..." + ls ./src/test/resources/org/opensearch/ad/bwc/anomaly-detection/$plugin_version + - name: Run AD Backwards Compatibility Tests + run: | + echo "Running backwards compatibility tests ..." + ./gradlew bwcTestSuite -Dtests.security.manager=false \ No newline at end of file diff --git a/.github/workflows/test_security.yml b/.github/workflows/test_security.yml new file mode 100644 index 000000000..e519c3568 --- /dev/null +++ b/.github/workflows/test_security.yml @@ -0,0 +1,78 @@ +name: Security test workflow for Anomaly Detection +on: + push: + branches: + - "*" + pull_request: + branches: + - "*" + +jobs: + Build-ad: + strategy: + matrix: + java: [8, 11, 14] + fail-fast: false + + name: Security test workflow for Anomaly Detection + runs-on: ubuntu-latest + + steps: + - name: Setup Java ${{ matrix.java }} + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + # anomaly-detection + - name: Checkout AD + uses: actions/checkout@v2 + + - name: Build Anomaly Detection + run: | + ./gradlew assemble + # example of variables: + # plugin = opensearch-anomaly-detection-1.3.7.0-SNAPSHOT.zip + # version = 1.3.7, plugin_version = 1.3.7.0, qualifier = SNAPSHOT + - name: Pull and Run Docker + run: | + plugin=`basename $(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` + qualifier=`echo $plugin|awk -F- '{print $5}'| cut -d. -f 1-1` + if $qualifier!=SNAPSHOT + then + docker_version=$version-$qualifier + else + docker_version=$version + fi + echo plugin version plugin_version qualifier docker_version + echo "($plugin) ($version) ($plugin_version) ($qualifier) ($docker_version)" + cd .. + if docker pull opensearchstaging/opensearch:$docker_version + then + echo "FROM opensearchstaging/opensearch:$docker_version" >> Dockerfile + echo "RUN if [ -d /usr/share/opensearch/plugins/opensearch-anomaly-detection ]; then /usr/share/opensearch/bin/opensearch-plugin remove opensearch-anomaly-detection; fi" >> Dockerfile + echo "ADD anomaly-detection/build/distributions/$plugin /tmp/" >> Dockerfile + echo "RUN /usr/share/opensearch/bin/opensearch-plugin install --batch file:/tmp/$plugin" >> Dockerfile + docker build -t opensearch-ad:test . + echo "imagePresent=true" >> $GITHUB_ENV + else + echo "imagePresent=false" >> $GITHUB_ENV + fi + - name: Run Docker Image + if: env.imagePresent == 'true' + run: | + cd .. + docker run -p 9200:9200 -d -p 9600:9600 -e "discovery.type=single-node" opensearch-ad:test + sleep 90 + - name: Run AD Test + if: env.imagePresent == 'true' + run: | + security=`curl -XGET https://localhost:9200/_cat/plugins?v -u admin:admin --insecure |grep opensearch-security|wc -l` + if [ $security -gt 0 ] + then + echo "Security plugin is available" + ./gradlew integTest -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" -Dhttps=true -Duser=admin -Dpassword=admin + else + echo "Security plugin is NOT available, skipping integration tests" + fi \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3ff58af40..c5de31486 100644 --- a/build.gradle +++ b/build.gradle @@ -121,7 +121,6 @@ configurations.all { if (it.state != Configuration.State.UNRESOLVED) return resolutionStrategy { force "joda-time:joda-time:${versions.joda}" - force "com.fasterxml.jackson.core:jackson-core:2.13.4" force "commons-logging:commons-logging:${versions.commonslogging}" force "org.apache.httpcomponents:httpcore:${versions.httpcore}" force "commons-codec:commons-codec:${versions.commonscodec}" @@ -659,9 +658,8 @@ dependencies { implementation 'software.amazon.randomcutforest:randomcutforest-serialization:2.0.1' compile files('lib/randomcutforest-parkservices-2.0.1.jar') compile files('lib/randomcutforest-core-2.0.1.jar') - implementation "com.fasterxml.jackson.core:jackson-core:2.13.4" - implementation "com.fasterxml.jackson.core:jackson-databind:2.13.4.2" - implementation "com.fasterxml.jackson.core:jackson-annotations:2.13.4" + implementation "com.fasterxml.jackson.core:jackson-databind:2.14.1" + implementation "com.fasterxml.jackson.core:jackson-annotations:2.14.1" // used for serializing/deserializing rcf models. compile group: 'io.protostuff', name: 'protostuff-core', version: '1.8.0' @@ -789,12 +787,6 @@ task updateVersion { ext.newVersion = System.getProperty('newVersion') println "Setting version to ${newVersion}." // String tokenization to support -SNAPSHOT - ant.replaceregexp(match: opensearch_version.tokenize('-')[0], replace: newVersion.tokenize('-')[0], flags:'g', byline:true) { - fileset(dir: projectDir) { - // Include the required files that needs to be updated with new Version - include(name: ".github/workflows/CI.yml") - } - } ant.replaceregexp(file:'build.gradle', match: '"opensearch.version", "\\d.*"', replace: '"opensearch.version", "' + newVersion.tokenize('-')[0] + '-SNAPSHOT"', flags:'g', byline:true) } } diff --git a/src/test/java/org/opensearch/ad/e2e/DetectionResultEvalutationIT.java b/src/test/java/org/opensearch/ad/e2e/DetectionResultEvalutationIT.java index 638c2162f..96a231e62 100644 --- a/src/test/java/org/opensearch/ad/e2e/DetectionResultEvalutationIT.java +++ b/src/test/java/org/opensearch/ad/e2e/DetectionResultEvalutationIT.java @@ -141,12 +141,14 @@ public void testValidationIntervalRecommendation() throws Exception { public void testValidationWindowDelayRecommendation() throws Exception { RestClient client = client(); - long recDetectorIntervalMillis = 180000; + long recDetectorIntervalMillisForDataSet = 180000; // this would be equivalent to the window delay in this data test - long recDetectorIntervalMinutes = recDetectorIntervalMillis / 60000; - List data = createData(2000, recDetectorIntervalMillis); + List data = createData(2000, recDetectorIntervalMillisForDataSet); indexTrainData("validation", data, 2000, client); long detectorInterval = 4; + long expectedWindowDelayMillis = Instant.now().toEpochMilli() - data.get(0).get("timestamp").getAsLong(); + // we always round up for window delay recommendation to reduce chance of missed data. + long expectedWindowDelayMinutes = (long) Math.ceil(expectedWindowDelayMillis / 60000.0); String requestBody = String .format( Locale.ROOT, @@ -171,10 +173,8 @@ public void testValidationWindowDelayRecommendation() throws Exception { @SuppressWarnings("unchecked") Map> messageMap = (Map>) XContentMapValues .extractValue("model", responseMap); - // adding plus one since window delay always rounds up another minute assertEquals( - String - .format(Locale.ROOT, CommonErrorMessages.WINDOW_DELAY_REC, +recDetectorIntervalMinutes + 1, recDetectorIntervalMinutes + 1), + String.format(Locale.ROOT, CommonErrorMessages.WINDOW_DELAY_REC, expectedWindowDelayMinutes, expectedWindowDelayMinutes), messageMap.get("window_delay").get("message") ); }