Skip to content

Commit

Permalink
[Backport 2.x]Fix github ci linux build and RAG tool missing return (#…
Browse files Browse the repository at this point in the history
…477) (#480)

* Fix github ci linux build and RAG tool missing return (#477)

* fix github ci linux build

Signed-off-by: Hailong Cui <[email protected]>

* add missing dependencies

Signed-off-by: Hailong Cui <[email protected]>

* spotless

Signed-off-by: Hailong Cui <[email protected]>

* add logs for debug

Signed-off-by: Hailong Cui <[email protected]>

* update security test ci

Signed-off-by: Hailong Cui <[email protected]>

* fix missing return for RAGTool

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: Hailong Cui <[email protected]>
(cherry picked from commit f66c53b)

* add missing distribution

Signed-off-by: Hailong Cui <[email protected]>

* fix verssion mismatch

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: Hailong Cui <[email protected]>
Co-authored-by: zhichao-aws <[email protected]>
  • Loading branch information
Hailong-am and zhichao-aws authored Jan 17, 2025
1 parent 637169d commit 0ab1bfe
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 42 deletions.
51 changes: 18 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,35 @@ on:

jobs:
Get-CI-Image-Tag:
runs-on: ubuntu-latest
outputs:
ci-image-version-linux: ${{ steps.step-ci-image-version-linux.outputs.ci-image-version-linux }}
steps:
- name: Install crane
uses: iarekylew00t/crane-installer@v1
with:
crane-release: v0.15.2
- name: Checkout opensearch-build repository
uses: actions/checkout@v2
with:
repository: 'opensearch-project/opensearch-build'
ref: 'main'
path: 'opensearch-build'
- name: Get ci image version from opensearch-build repository scripts
id: step-ci-image-version-linux
run: |
crane version
CI_IMAGE_VERSION=`opensearch-build/docker/ci/get-ci-images.sh -p centos7 -u opensearch -t build | head -1`
echo $CI_IMAGE_VERSION
echo "ci-image-version-linux=$CI_IMAGE_VERSION" >> $GITHUB_OUTPUT
uses: opensearch-project/opensearch-build/.github/workflows/get-ci-image-tag.yml@main
with:
product: opensearch

build-linux:
needs: Get-CI-Image-Tag
strategy:
matrix:
java: [11, 17, 21]
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
name: Build and Test skills plugin on Linux
runs-on: ubuntu-latest
container:
# using the same image which is used by opensearch-build team to build the OpenSearch Distribution
# this image tag is subject to change as more dependencies and updates will arrive over time
image: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-version-linux }}
# need to switch to root so that github actions can install runner binary on container without permission issues.
options: --user root
options: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-start-options }}

steps:
- name: Run start commands
run: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-start-command }}

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin

- name: Build and Test
run: |
Expand All @@ -63,7 +46,7 @@ jobs:
./gradlew publishToMavenLocal"
- name: Upload Coverage Report
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

Expand All @@ -78,11 +61,12 @@ jobs:

steps:
- name: Checkout skills
uses: actions/checkout@v1
uses: actions/checkout@v4
- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin
- name: Install dependencies on macos
run: |
brew reinstall gcc
Expand All @@ -101,12 +85,13 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin

- name: Build and Test
run: |
Expand All @@ -117,7 +102,7 @@ jobs:
./gradlew publishToMavenLocal
- name: Upload Coverage Report
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

9 changes: 5 additions & 4 deletions .github/workflows/test_security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ jobs:
# using the same image which is used by opensearch-build team to build the OpenSearch Distribution
# this image tag is subject to change as more dependencies and updates will arrive over time
image: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-version-linux }}
# need to switch to root so that github actions can install runner binary on container without permission issues.
options: --user root
options: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-start-options }}

steps:
- name: Run start commands
run: ${{ needs.Get-CI-Image-Tag.outputs.ci-image-start-command }}
- name: Checkout Skills
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ dependencies {
compileOnly("com.google.guava:guava:33.2.1-jre")
compileOnly group: 'org.apache.commons', name: 'commons-lang3', version: '3.16.0'
compileOnly group: 'org.apache.commons', name: 'commons-text', version: '1.11.0'
compileOnly("com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}")
compileOnly("com.fasterxml.jackson.core:jackson-databind:${versions.jackson_databind}")

// Plugin dependencies
compileOnly group: 'org.opensearch', name:'opensearch-ml-client', version: "${opensearch_build}"
Expand Down Expand Up @@ -147,8 +149,8 @@ dependencies {
testImplementation group: 'org.json', name: 'json', version: '20240205'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.14.2'
testImplementation group: 'org.mockito', name: 'mockito-inline', version: '5.2.0'
testImplementation("net.bytebuddy:byte-buddy:1.15.4")
testImplementation("net.bytebuddy:byte-buddy-agent:1.15.4")
testImplementation("net.bytebuddy:byte-buddy:1.15.10")
testImplementation("net.bytebuddy:byte-buddy-agent:1.15.10")
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.2'
testImplementation 'org.mockito:mockito-junit-jupiter:5.14.2'
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/opensearch/agent/tools/RAGTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
T queryToolOutput;
if (!this.enableContentGeneration) {
listener.onResponse(r);
return;
}
if (r.equals("Can not get any match from search result.")) {
queryToolOutput = (T) "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void setup() {
Collections.emptyMap(),
new DataSources(),
null,
false,
""
);
}
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/org/opensearch/integTest/BaseAgentToolsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ protected void updateClusterSettings(String settingKey, Object value) {

@SneakyThrows
private Map<String, Object> parseResponseToMap(Response response) {
Map<String, Object> responseInMap = XContentHelper
.convertToMap(XContentType.JSON.xContent(), EntityUtils.toString(response.getEntity()), false);
return responseInMap;
String responseBody = EntityUtils.toString(response.getEntity());
try {
return XContentHelper.convertToMap(XContentType.JSON.xContent(), responseBody, false);
} catch (Exception e) {
logger.error("failed to parse response to map: {}", responseBody, e);
return Collections.emptyMap();
}
}

@SneakyThrows
Expand Down Expand Up @@ -335,6 +339,7 @@ private String parseStringResponseFromExecuteAgentResponse(Response response) {

// execute the agent, and return the String response from the json structure
// {"inference_results": [{"output": [{"name": "response","result": "the result to return."}]}]}
@SneakyThrows
public String executeAgent(String agentId, String requestBody) {
Response response = makeRequest(client(), "POST", "/_plugins/_ml/agents/" + agentId + "/_execute", null, requestBody, null);
return parseStringResponseFromExecuteAgentResponse(response);
Expand Down

0 comments on commit 0ab1bfe

Please sign in to comment.