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

[Backport to main] Backport multiple commits from 2.x to main branch #1273

Merged
merged 59 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
49c140e
remote inference: add connector executor (#1052)
ylwu-amzn Jul 9, 2023
dfc1399
refactor predictable: add method to check if model is ready (#1057)
ylwu-amzn Jul 9, 2023
49cc07e
add unit test for connector class in commons (#1058)
ylwu-amzn Jul 10, 2023
85e94ac
Add basic connector access control classes (#1055)
zane-neo Jul 10, 2023
1c936ea
remote inference: add unit test for model and register model input (#…
ylwu-amzn Jul 10, 2023
9465496
connector transport actions and disable native memory CB
Zhangxunmt Jul 9, 2023
ce8eded
remote inference: add unit test for StringUtils and remote inference …
ylwu-amzn Jul 10, 2023
508872e
Add missing codes from pen test fix (#1060)
zane-neo Jul 10, 2023
ea823b7
change to compileOnly to avoid jarhell (#1062)
ylwu-amzn Jul 10, 2023
0de3fba
restful connector actions and UT
Zhangxunmt Jul 10, 2023
38226aa
create model group automatically with first model version (#1063)
rbhavna Jul 10, 2023
33a095d
Fix breaking changes from opensearch core
zane-neo Sep 1, 2023
ab7ad70
remote inference: add unit test for create connector request/response…
ylwu-amzn Jul 11, 2023
14c5f1b
more UT for rest and trasport actions
Zhangxunmt Jul 10, 2023
12d7f99
fix cannot specify model access control parameters error (#1068)
ylwu-amzn Jul 11, 2023
8327f80
Change connector access control creation allow empty list
zane-neo Jul 11, 2023
34b07c5
fix memory circuit breaker
Zhangxunmt Jul 11, 2023
b51b23d
PenTest fixes: error codes and update model group fix (#1074)
rbhavna Jul 11, 2023
0e48a5f
Fix rare private ip address bypass SSRF issue (#1070)
zane-neo Jul 11, 2023
020dce4
leftover in the 404 Not Found return error
Zhangxunmt Jul 12, 2023
bfc6694
modify error message when model group not unique is provided (#1078)
rbhavna Jul 12, 2023
dacd510
Add more UT for remote inference classes (#1077)
b4sjoo Jul 12, 2023
8cc6016
init master key automatically (#1075)
ylwu-amzn Jul 12, 2023
a4942a3
stash context before accessing ml config index; increase master key s…
ylwu-amzn Jul 12, 2023
1aa966e
fix init master key bug (#1094)
ylwu-amzn Jul 12, 2023
afba6c9
IT Security Tests for model access control (#1095)
rbhavna Jul 12, 2023
0215308
Add test keys to CI related workflows (#1099)
peterzhuamazon Jul 12, 2023
269db07
Tweak workflow event so ci can retrieve credentails correctly (#1102)
peterzhuamazon Jul 12, 2023
25867c6
2.9 release notes (#1098)
rbhavna Jul 12, 2023
e09ffc9
delete connector successfully if model index is missing
Zhangxunmt Jul 12, 2023
fa0e1be
Add integration tests for the remote inference feature (#1073)
ryanbogan Jul 13, 2023
cb77030
Update ml CI workflow checkout ref to be PR commit (#1114)
peterzhuamazon Jul 13, 2023
69dfb5b
Temporarily ignore OpenAI Tests
ryanbogan Jul 13, 2023
6610e45
Add shell bash settings for windows github actions to export credentials
peterzhuamazon Jul 13, 2023
ea8356b
Increase sleep time on remote inference integration tests
ryanbogan Jul 13, 2023
faed209
fix encoding US-ASCII error (#1126)
rbhavna Jul 13, 2023
04f7434
fix remote inference it: update job interval (#1129)
ylwu-amzn Jul 14, 2023
173d12b
Add null key check for integration tests (#1113)
ryanbogan Jul 17, 2023
43e451c
Reenable OpenAI remote inference tests (#1127)
ryanbogan Jul 17, 2023
c11ee74
more PRs to 2.9 release notes (#1143)
rbhavna Jul 18, 2023
4f52142
updating developer guide for CCI contributors (#1049)
dhrubo-os Jul 24, 2023
679f2bd
adding blueprint examples for remote inference (#1155)
dhrubo-os Jul 25, 2023
9a731d7
add remote inference tutorial (#1158)
ylwu-amzn Jul 26, 2023
fd7f499
remote inference: escape parameter if not valid json (#1176)
ylwu-amzn Aug 1, 2023
29b7ca3
Add model auto redeploy tutorial (#1175)
zane-neo Aug 2, 2023
e6784bb
fixing docs (#1193)
dhrubo-os Aug 9, 2023
cb3183d
add more stats: connector count, connector/config index status; fix m…
ylwu-amzn Aug 16, 2023
4de469d
fix parameter parsing bug for create connector input (#1210)
ylwu-amzn Aug 17, 2023
b40371d
updating cohere blueprint doc (#1213)
dhrubo-os Aug 17, 2023
312d30c
fix:admin with no backend role on AOS unable to create restricted mod…
ylwu-amzn Aug 18, 2023
229c16d
fill null parameters in connector body template (#1192) (#1219)
ylwu-amzn Aug 18, 2023
d87f593
fixing metrics (#1194) (#1220)
ylwu-amzn Aug 18, 2023
a31edbb
Fix breaking changes from opensearch core
zane-neo Sep 1, 2023
9fa955e
add eligible node role settings (#1197) (#1221)
ylwu-amzn Aug 18, 2023
385d7a4
fixing some error message handeling (#1222)
ylwu-amzn Aug 18, 2023
3765972
add feature flags for remote inference (#1223)
ylwu-amzn Aug 18, 2023
e828635
Bump checkstyle version for CVE fix (#1216)
b4sjoo Aug 18, 2023
8b66f96
renaming metrics (#1224)
dhrubo-os Aug 22, 2023
d1e5235
Fix breaking change from opensearch core
zane-neo Sep 1, 2023
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
62 changes: 54 additions & 8 deletions .github/workflows/CI-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
name: Build and Test ml-commons
# This workflow is triggered on pull requests and push to any branches
on:
pull_request:
branches:
- "*"
push:
branches:
- "*"
branches-ignore:
- 'backport/**'
- 'create-pull-request/**'
- 'dependabot/**'
pull_request_target:
types: [opened, synchronize, reopened]

permissions:
id-token: write
contents: read

jobs:
Build-ml:
strategy:
matrix:
java: [11, 17, 20]

name: Build and Test MLCommons Plugin
if: github.repository == 'opensearch-project/ml-commons'
environment: ml-commons-cicd-env
runs-on: ubuntu-latest

steps:
Expand All @@ -22,19 +30,34 @@ jobs:
with:
java-version: ${{ matrix.java }}

# ml-commons
- uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.ML_ROLE }}
aws-region: us-west-2

- name: Checkout MLCommons
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Build and Run Tests
run: |
export OPENAI_KEY=$(aws secretsmanager get-secret-value --secret-id github_openai_key --query SecretString --output text)
export COHERE_KEY=$(aws secretsmanager get-secret-value --secret-id github_cohere_key --query SecretString --output text)
echo "::add-mask::$OPENAI_KEY"
echo "::add-mask::$COHERE_KEY"
./gradlew build
- name: Publish to Maven Local
run: |
./gradlew publishToMavenLocal
- name: Multi Nodes Integration Testing
run: |
export OPENAI_KEY=$(aws secretsmanager get-secret-value --secret-id github_openai_key --query SecretString --output text)
export COHERE_KEY=$(aws secretsmanager get-secret-value --secret-id github_cohere_key --query SecretString --output text)
echo "::add-mask::$OPENAI_KEY"
echo "::add-mask::$COHERE_KEY"
./gradlew integTest -PnumNodes=3

- name: Pull and Run Docker
run: |
plugin=`basename $(ls plugin/build/distributions/*.zip)`
Expand Down Expand Up @@ -71,6 +94,10 @@ jobs:
if: env.imagePresent == 'true'
run: |
security=`curl -XGET https://localhost:9200/_cat/plugins?v -u admin:admin --insecure |grep opensearch-security|wc -l`
export OPENAI_KEY=$(aws secretsmanager get-secret-value --secret-id github_openai_key --query SecretString --output text)
export COHERE_KEY=$(aws secretsmanager get-secret-value --secret-id github_cohere_key --query SecretString --output text)
echo "::add-mask::$OPENAI_KEY"
echo "::add-mask::$COHERE_KEY"
if [ $security -gt 0 ]
then
echo "Security plugin is available"
Expand All @@ -91,6 +118,8 @@ jobs:
matrix:
java: [11, 17, 20]
name: Build and Test MLCommons Plugin on Windows
if: github.repository == 'opensearch-project/ml-commons'
environment: ml-commons-cicd-env
runs-on: windows-latest

steps:
Expand All @@ -99,16 +128,33 @@ jobs:
with:
java-version: ${{ matrix.java }}

- uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.ML_ROLE }}
aws-region: us-west-2

# ml-commons
- name: Checkout MLCommons
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Build and Run Tests
shell: bash
run: |
export OPENAI_KEY=$(aws secretsmanager get-secret-value --secret-id github_openai_key --query SecretString --output text)
export COHERE_KEY=$(aws secretsmanager get-secret-value --secret-id github_cohere_key --query SecretString --output text)
echo "::add-mask::$OPENAI_KEY"
echo "::add-mask::$COHERE_KEY"
./gradlew.bat build
- name: Publish to Maven Local
run: |
./gradlew publishToMavenLocal
# - name: Multi Nodes Integration Testing
# shell: bash
# run: |
# export OPENAI_KEY=$(aws secretsmanager get-secret-value --secret-id github_openai_key --query SecretString --output text)
# export COHERE_KEY=$(aws secretsmanager get-secret-value --secret-id github_cohere_key --query SecretString --output text)
# echo "::add-mask::$OPENAI_KEY"
# echo "::add-mask::$COHERE_KEY"
# ./gradlew integTest -PnumNodes=3
18 changes: 0 additions & 18 deletions .github/workflows/dco.yml

This file was deleted.

135 changes: 107 additions & 28 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,81 @@
- [Developer Guide](#developer-guide)
- [Forking and Cloning](#forking-and-cloning)
- [Install Prerequisites](#install-prerequisites)
- [JDK 14](#jdk-14)
- [Setup](#setup)
- [Build](#build)
- [Building from the command line](#building-from-the-command-line)
- [Building from the IDE](#building-from-the-ide)
- [Debugging](#debugging)
<p center><img src="https://github.com/opensearch-project/opensearch-py/raw/main/OpenSearch.svg" height="64px" alt="Opensearch"/></p>
<h1 center>ML-Commons Developer Guide</h1>

## Developer Guide
This guide applies to the development within the ML-Commons project

### Forking and Cloning
- [Getting started guide](#getting-started-guide)
- [Key technologies](#key-technologies)
- [Prerequisites](#prerequisites)
- [Fork and clone ML-Commons](#fork-and-clone-ml-commons)
- [Run OpenSearch](#run-opensearch)
- [Build](#Build)
- [Building from the command line](#Building-from-the-command-line)
- [Debugging](#Debugging)
- [More documentation](#More-docs)
- [Code guidelines](#code-guidelines)

Fork this repository on GitHub, and clone locally with `git clone`.

### Install Prerequisites

#### JDK 14

OpenSearch components build using Java 14 at a minimum. This means you must have a JDK 14 installed with the environment variable `JAVA_HOME` referencing the path to Java home for your JDK 14 installation, e.g. `JAVA_HOME=/usr/lib/jvm/jdk-14`.
## Getting started guide

### Setup
This guide is for any developer who wants a running local development environment where you can make, see, and test changes. It's opinionated to get you running as quickly and easily as possible, but it's not the only way to set up a development environment.

1. Clone the repository (see [Forking and Cloning](#forking-and-cloning))
2. Make sure `JAVA_HOME` is pointing to a Java 14 JDK (see [Install Prerequisites](#install-prerequisites))
3. Launch Intellij IDEA, Choose Import Project.
If you're only interested in installing and using this plugin features, you can just install Opensearch and ml-commons plugin will be integrated with Opensearch.

If you're planning to contribute code (features or fixes) to this repository, great! Make sure to also read the [contributing guide](CONTRIBUTING.md).


### Key technologies

ml-commons is primarily a Java based plugin for machine learning in opensearch. To effectively contribute you need to be familiar with Java.

### Prerequisites

To develop on ml-commons, you'll need:

- A [GitHub account](https://docs.github.com/en/get-started/onboarding/getting-started-with-your-github-account)
- [`git`](https://git-scm.com/) for version control
- [`Java`](https://www.java.com/en/)
- A code editor of your choice, configured for Java. If you don't have a favorite editor, we suggest [Intellij](https://www.jetbrains.com/idea/)

If you already have these installed or have your own preferences for installing them, skip ahead to the [Fork and clone ml-commons](#fork-and-clone-ml-commons) section.


#### Install `git`

If you don't already have it installed (check with `git --version`) we recommend following [the `git` installation guide for your OS](https://git-scm.com/downloads).

#### Install `Java`

You can install any version of Java starting from 17. [`Jenv`](https://www.jenv.be/) is a good option to use so that you can have multiple versions of Java.


### Fork and clone ml-commons

All local development should be done in a [forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo).
Fork ml-commons by clicking the "Fork" button at the top of the [GitHub repository](https://github.com/opensearch-project/ml-commons).

Clone your forked version of ml-commons to your local machine (replace `opensearch-project` in the command below with your GitHub username):

```bash
$ git clone git@github.com:opensearch-project/ml-commons.git
```

### Run OpenSearch

You can install Opensearch multiple ways:

1. https://opensearch.org/downloads.html#docker-compose
2. https://opensearch.org/docs/2.5/install-and-configure/install-opensearch/tar/

#### Default setup for opensearch

```yml
opensearch.hosts: ["https://localhost:9200"]
opensearch.username: "admin" # Default username
opensearch.password: "admin" # Default password
```

### Build

Expand All @@ -33,20 +84,16 @@ This package uses the [Gradle](https://docs.gradle.org/current/userguide/usergui
#### Building from the command line

1. `./gradlew build` builds and tests, `./gradlew build buildDeb buildRpm` build RPM and DEB.
2. `./gradlew :run` launches a single node cluster with ml-commons plugin installed
3. `./gradlew :integTest` launches a single node cluster with ml-commons plugin installed and runs all integration tests except security. Use `./gradlew integTest -PnumNodes=<number>` to launch multi-node cluster.
4. ` ./gradlew :integTest --tests="<class path>.<test method>"` runs a single integration test class or method, for example `./gradlew integTest --tests="org.opensearch.ml.rest.RestMLTrainAndPredictIT.testTrainAndPredictKmeansWithEmptyParam"` or `./gradlew integTest --tests="org.opensearch.ml.rest.RestMLTrainAndPredictIT"`
2. `./gradlew run` launches a single node cluster with ml-commons plugin installed
3. `./gradlew integTest` launches a single node cluster with ml-commons plugin installed and runs all integration tests except security. Use `./gradlew integTest -PnumNodes=<number>` to launch multi-node cluster.
4. ` ./gradlew integTest --tests="<class path>.<test method>"` runs a single integration test class or method, for example `./gradlew integTest --tests="org.opensearch.ml.rest.RestMLTrainAndPredictIT.testTrainAndPredictKmeansWithEmptyParam"` or `./gradlew integTest --tests="org.opensearch.ml.rest.RestMLTrainAndPredictIT"`
5. `./gradlew integTest -Dtests.class="<class path>"` run specific integ test class, for example `./gradlew integTest -Dtests.class="org.opensearch.ml.rest.RestMLTrainAndPredictIT"`
6. `./gradlew integTest -Dtests.method="<method name>"` run specific integ test method, for example `./gradlew integTest -Dtests.method="testTrainAndPredictKmeans"`
7. `./gradlew integTest -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" -Dhttps=true -Duser=admin -Dpassword=admin` launches integration tests against a local cluster and run tests with security. Detail steps: (1)download OpenSearch tarball to local and install by running `opensearch-tar-install.sh`; (2)build ML plugin zip with your change and install ML plugin zip; (3)restart local test cluster; (4) run this gradle command to test.
7. `./gradlew integTest -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" -Dhttps=true -Duser=admin -Dpassword=admin` launches integration tests against a local cluster and run tests with security. Detail steps: (1)download OpenSearch tarball to local and install by running `opensearch-tar-install.sh`; (2)build ML plugin zip with your change and install ML plugin zip; (3)restart local test cluster; (4) run this gradle command to test.
8. `./gradlew spotlessApply` formats code. And/or import formatting rules in `.eclipseformat.xml` with IDE.

When launching a cluster using one of the above commands logs are placed in `/build/cluster/run node0/opensearch-<version>/logs`. Though the logs are teed to the console, in practices it's best to check the actual log file.

#### Building from the IDE

Currently, the only IDE we support is IntelliJ IDEA. It's free, it's open source, it works. The gradle tasks above can also be launched from IntelliJ's Gradle toolbar and the extra parameters can be passed in via the Launch Configurations VM arguments.

#### Debugging

Sometimes it's useful to attach a debugger to either the OpenSearch cluster or the integ tests to see what's going on. When running unit tests you can just hit 'Debug' from the IDE's gutter to debug the tests. To debug code running in an actual server run:
Expand All @@ -65,4 +112,36 @@ To debug code running in an integ test (which exercises the server from a separa
./gradlew -Dtest.debug :integTest
```

The test runner JVM will start suspended and wait for a debugger to attach to `localhost:5005` before running the tests.
The test runner JVM will start suspended and wait for a debugger to attach to `localhost:5005` before running the tests.

## More docs

1. [Model serving framework](https://opensearch.org/docs/latest/ml-commons-plugin/model-serving-framework/)
2. [Model Access Control](https://github.com/opensearch-project/ml-commons/blob/2.x/docs/model_access_control.md)
3. [How to add a new function](https://github.com/opensearch-project/ml-commons/blob/2.x/docs/how-to-add-new-function.md)

## Code guidelines

#### Filenames

All filenames should use `CamelCase`.

**Right:** `ml-commons/common/src/main/java/org.opensearch/ml/common/MLModelGroup.java`

**Wrong:** `ml-commons/common/src/main/java/org.opensearch/ml/common/ml_model_group.java`

#### Do not comment out code

We use a version management system. If a line of code is no longer needed,
remove it, don't simply comment it out.

#### Avoid global definitions

Don't do this. Everything should be wrapped in a module that can be depended on
by other modules. Even things as simple as a single value should be a module.

#### Write small functions

Keep your functions short. A good function fits on a slide that the people in
the last row of a big room can comfortably read. So don't count on them having
perfect vision and limit yourself to ~25 lines of code per function.
10 changes: 5 additions & 5 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ dependencies {
compileOnly "org.opensearch:common-utils:${common_utils_version}"
testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.4.0'

implementation group: 'org.apache.commons', name: 'commons-text', version: '1.10.0'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
implementation group: 'org.json', name: 'json', version: '20230227'
compileOnly group: 'org.apache.commons', name: 'commons-text', version: '1.10.0'
compileOnly group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
compileOnly group: 'org.json', name: 'json', version: '20230227'
}

lombok {
Expand All @@ -40,11 +40,11 @@ jacocoTestCoverageVerification {
rule {
limit {
counter = 'LINE'
minimum = 0.6 //TODO: add more test to meet the coverage bar 0.9
minimum = 0.8 //TODO: add more test to meet the coverage bar 0.9
}
limit {
counter = 'BRANCH'
minimum = 0.6 //TODO: add more test to meet the coverage bar 0.9
minimum = 0.7 //TODO: add more test to meet the coverage bar 0.9
}
}
}
Expand Down
Loading