Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build using local dependencies, re-enable CI #13

Merged
merged 7 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 38 additions & 56 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ name: Build and Test Anomaly detection
on:
push:
branches:
- main
- opendistro-*
- 7.10.2-no-workbench
- "*"
pull_request:
branches:
- main
- opendistro-*
- 7.10.2-no-workbench
- "*"

jobs:

Build-ad:
strategy:
matrix:
Expand All @@ -21,66 +18,51 @@ jobs:
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: Multi Nodes Integration Testing
run: |
./gradlew integTest -PnumNodes=3

- 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
# dependencies: OpenSearch
- name: Checkout OpenSearch
uses: actions/checkout@v2
with:
repository: 'opensearch-project/OpenSearch'
path: OpenSearch
- name: Build OpenSearch
working-directory: ./OpenSearch
run: ./gradlew publishToMavenLocal

## 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/opensearch/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/opensearch/bin/elasticsearch-plugin install --batch file:/tmp/opendistro-anomaly-detection-$plugin_version.zip" >> Dockerfile
# dependencies: common-utils
- name: Checkout common-utils
uses: actions/checkout@v2
with:
repository: 'dblock/common-utils'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: can we avoid using a personal repository name?
Ignore this comment if this is just WIP/temporary solution/testing purpose.

Copy link
Member Author

@dblock dblock Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not that minor. This is opensearch-project/common-utils#4 that would need to be merged and that's incompatible with the current S3 build setup - the whole build fails without S3 ENV regardless of whether you try to build to maven local or not.

Copy link
Collaborator

@ylwu-amzn ylwu-amzn Apr 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I mean it's good to remove this personal S3 maven repo url = 's3://search-vemsarat/', but seems we use another personal local path with name 'dblock/....

Currently it's not convenient to build/test locally. Will we publish all dependencies to public maven/integrate with jitpack soon?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The personal path is just pending PRs being merged if we decide to go this route.

We'll (I'll) evaluate jitpack to compare. It currently doesn't "just work", needs to successfully be able to check out and build these dependencies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, once we evaluate jitpack, we should make changes to common-utils and job-scheduler, build them locally here in the workflows instead of fork repositories.

ref: 'build-local'
path: common-utils
- name: Build common-utils
working-directory: ./common-utils
run: ./gradlew publishToMavenLocal

docker build -t odfe-ad:test .
echo "imagePresent=true" >> $GITHUB_ENV
else
echo "imagePresent=false" >> $GITHUB_ENV
fi
# dependencies: job-scheduler
- name: Checkout job-scheduler
uses: actions/checkout@v2
with:
repository: 'dblock/job-scheduler'
ref: 'build-local'
path: job-scheduler
- name: Build job-scheduler
working-directory: ./job-scheduler
run: ./gradlew publishToMavenLocal

- name: Run Docker Image
if: env.imagePresent == 'true'
run: |
cd ..
docker run -p 9200:9200 -d -p 9600:9600 -e "discovery.type=single-node" odfe-ad:test
sleep 90
# anomaly-detection
- name: Checkout AD
uses: actions/checkout@v1

- name: Run AD Test
if: env.imagePresent == 'true'
- name: Run test
run: |
security=`curl -XGET https://localhost:9200/_cat/plugins?v -u admin:admin --insecure |grep opendistro_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
./gradlew test

- name: Upload Coverage Report
uses: codecov/codecov-action@v1
with:
Expand Down
18 changes: 3 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ import org.opensearch.gradle.test.RestIntegTestTask
buildscript {
ext {
opensearch_group = "org.opensearch"
opensearch_version = '7.10.3'
opensearch_version = '1.0.0'
}

repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By removing this private S3 maven, can we use ./gradlew build to build AD plugin locally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Free at last!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw the S3 credentials being required could also be worked around by tagging ?: '' to them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing this s3 maven, I think we need build all of other dependencies and publish them to local maven repo in our laptop, just similar as the CI workflow to make the local ./gradlew build work, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, run ./gradlew publishToMavenLocal on each dependency once.

url = 's3://search-vemsarat/'
credentials(AwsCredentials) {
accessKey = System.env.AWS_ACCESS_KEY_ID ?: findProperty('aws_access_key_id')
secretKey = System.env.AWS_SECRET_ACCESS_KEY ?: findProperty('aws_secret_access_key')
}
}
jcenter()
}

Expand All @@ -59,15 +53,9 @@ plugins {
}

repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven {
url = 's3://search-vemsarat/'
credentials(AwsCredentials) {
accessKey = System.env.AWS_ACCESS_KEY_ID ?: findProperty('aws_access_key_id')
secretKey = System.env.AWS_SECRET_ACCESS_KEY ?: findProperty('aws_secret_access_key')
}
}
jcenter()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.junit.Assert;
import org.junit.Ignore;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
Expand Down Expand Up @@ -111,6 +112,7 @@ public void tearDown() throws Exception {
super.tearDownLog4jForJUnit();
}

@Ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious why these tests are not working?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, they are legit flaky, but I opened #15 to address.

public void testDeleteDocsBasedOnShardSizeWithCleanupNeededAsTrue() throws Exception {
long maxShardSize = 1000;
when(storeStats.getSizeInBytes()).thenReturn(maxShardSize + 1);
Expand All @@ -120,6 +122,7 @@ public void testDeleteDocsBasedOnShardSizeWithCleanupNeededAsTrue() throws Excep
}, exception -> { throw new RuntimeException(exception); }));
}

@Ignore
public void testDeleteDocsBasedOnShardSizeWithCleanupNeededAsFalse() throws Exception {
long maxShardSize = 1000;
when(storeStats.getSizeInBytes()).thenReturn(maxShardSize - 1);
Expand All @@ -132,6 +135,7 @@ public void testDeleteDocsBasedOnShardSizeWithCleanupNeededAsFalse() throws Exce
);
}

@Ignore
public void testDeleteDocsBasedOnShardSizeIndexNotExisted() throws Exception {
when(clusterService.state().getRoutingTable().hasIndex(anyString())).thenReturn(false);
Logger logger = (Logger) LogManager.getLogger(IndexCleanup.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.opensearch.Version;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.cluster.ClusterName;
Expand Down Expand Up @@ -97,6 +98,7 @@ public void setUp() throws Exception {
);
}

@Ignore
public void testNormal() throws IOException, JsonPathNotFoundException {
CronRequest request = new CronRequest();

Expand Down