From bd410f0277f5b7ff465614cc39ce786fe0f29be6 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Tue, 9 Jan 2024 16:27:10 +0800 Subject: [PATCH 1/7] Fix flaky test Signed-off-by: Hailong Cui --- .../ml/engine/encryptor/EncryptorImpl.java | 5 +++-- .../ml/rest/RestMemoryGetConversationsActionIT.java | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java b/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java index b500709bc5..617c6871e5 100644 --- a/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java +++ b/ml-algorithms/src/main/java/org/opensearch/ml/engine/encryptor/EncryptorImpl.java @@ -68,7 +68,8 @@ public String encrypt(String plainText) { initMasterKey(); final AwsCrypto crypto = AwsCrypto.builder().withCommitmentPolicy(CommitmentPolicy.RequireEncryptRequireDecrypt).build(); byte[] bytes = Base64.getDecoder().decode(masterKey); - JceMasterKey jceMasterKey = JceMasterKey.getInstance(new SecretKeySpec(bytes, "AES"), "Custom", "", "AES/GCM/NoPadding"); + // https://github.com/aws/aws-encryption-sdk-java/issues/1879 + JceMasterKey jceMasterKey = JceMasterKey.getInstance(new SecretKeySpec(bytes, "AES"), "Custom", "", "AES/GCM/NOPADDING"); final CryptoResult encryptResult = crypto .encryptData(jceMasterKey, plainText.getBytes(StandardCharsets.UTF_8)); @@ -81,7 +82,7 @@ public String decrypt(String encryptedText) { final AwsCrypto crypto = AwsCrypto.builder().withCommitmentPolicy(CommitmentPolicy.RequireEncryptRequireDecrypt).build(); byte[] bytes = Base64.getDecoder().decode(masterKey); - JceMasterKey jceMasterKey = JceMasterKey.getInstance(new SecretKeySpec(bytes, "AES"), "Custom", "", "AES/GCM/NoPadding"); + JceMasterKey jceMasterKey = JceMasterKey.getInstance(new SecretKeySpec(bytes, "AES"), "Custom", "", "AES/GCM/NOPADDING"); final CryptoResult decryptedResult = crypto .decryptData(jceMasterKey, Base64.getDecoder().decode(encryptedText)); diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java index 2112793166..50b5e75b57 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java @@ -20,10 +20,12 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Map; +import java.util.concurrent.TimeUnit; import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.message.BasicHeader; +import org.junit.Assert; import org.junit.Before; import org.opensearch.client.Response; import org.opensearch.core.rest.RestStatus; @@ -33,6 +35,8 @@ import com.google.common.collect.ImmutableList; +import lombok.SneakyThrows; + public class RestMemoryGetConversationsActionIT extends MLCommonsRestTestCase { @Before @@ -120,7 +124,7 @@ public void testConversations_MorePages() throws IOException { assert (((Double) map.get("next_token")).intValue() == 1); } - public void testGetConversations_nextPage() throws IOException { + public void testGetConversations_nextPage() throws IOException, InterruptedException { Response ccresponse1 = TestHelper.makeRequest(client(), "POST", ActionConstants.CREATE_CONVERSATION_REST_PATH, null, "", null); assert (ccresponse1 != null); assert (TestHelper.restStatus(ccresponse1) == RestStatus.OK); @@ -128,8 +132,12 @@ public void testGetConversations_nextPage() throws IOException { String ccentityString1 = TestHelper.httpEntityToString(cchttpEntity1); Map ccmap1 = gson.fromJson(ccentityString1, Map.class); assert (ccmap1.containsKey("conversation_id")); + logger.info("ccentityString1={}", ccentityString1); String id1 = (String) ccmap1.get("conversation_id"); + // wait for 0.1s to make sure update time is different between conversation 1 and 2 + TimeUnit.MICROSECONDS.sleep(100); + Response ccresponse2 = TestHelper.makeRequest(client(), "POST", ActionConstants.CREATE_CONVERSATION_REST_PATH, null, "", null); assert (ccresponse2 != null); assert (TestHelper.restStatus(ccresponse2) == RestStatus.OK); @@ -159,7 +167,7 @@ public void testGetConversations_nextPage() throws IOException { ArrayList conversations1 = (ArrayList) map1.get("conversations"); assert (conversations1.size() == 1); assert (conversations1.get(0).containsKey("conversation_id")); - assert (((String) conversations1.get(0).get("conversation_id")).equals(id2)); + Assert.assertEquals(conversations1.get(0).get("conversation_id"), id2); assert (((Double) map1.get("next_token")).intValue() == 1); Response response = TestHelper From 19cec1028b8440e62ddf0426ca10d55674ea4ba8 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Tue, 9 Jan 2024 16:35:39 +0800 Subject: [PATCH 2/7] remove unused import Signed-off-by: Hailong Cui --- .../opensearch/ml/rest/RestMemoryGetConversationsActionIT.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java index 50b5e75b57..2b2f409908 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java @@ -35,8 +35,6 @@ import com.google.common.collect.ImmutableList; -import lombok.SneakyThrows; - public class RestMemoryGetConversationsActionIT extends MLCommonsRestTestCase { @Before From 0a59fd1f9e20451bedd2de08778e7a905f32f5af Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Tue, 9 Jan 2024 23:47:36 +0800 Subject: [PATCH 3/7] replace deprecated openAI model in test Signed-off-by: Hailong Cui --- .../org/opensearch/ml/rest/RestMLRemoteInferenceIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java index 0c8a7c779c..b00606a24d 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java @@ -39,7 +39,7 @@ public class RestMLRemoteInferenceIT extends MLCommonsRestTestCase { + " \"content_type\": \"application/json\",\n" + " \"max_tokens\": 7,\n" + " \"temperature\": 0,\n" - + " \"model\": \"text-davinci-003\"\n" + + " \"model\": \"gpt-3.5-turbo-instruct\"\n" + " },\n" + " \"credential\": {\n" + " \"openAI_key\": \"" @@ -265,7 +265,7 @@ public void testOpenAIEditsModel() throws IOException, InterruptedException { + " \"endpoint\": \"api.openai.com\",\n" + " \"auth\": \"API_Key\",\n" + " \"content_type\": \"application/json\",\n" - + " \"model\": \"text-davinci-edit-001\"\n" + + " \"model\": \"gpt-3.5-turbo\"\n" + " },\n" + " \"credential\": {\n" + " \"openAI_key\": \"" @@ -276,7 +276,7 @@ public void testOpenAIEditsModel() throws IOException, InterruptedException { + " {\n" + " \"action_type\": \"predict\",\n" + " \"method\": \"POST\",\n" - + " \"url\": \"https://api.openai.com/v1/edits\",\n" + + " \"url\": \"https://api.openai.com/v1/chat/completions\",\n" + " \"headers\": { \n" + " \"Authorization\": \"Bearer ${credential.openAI_key}\"\n" + " },\n" From 48ac39d1d3bdcd3eeb33205d589786ed35c669a7 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Wed, 10 Jan 2024 00:20:17 +0800 Subject: [PATCH 4/7] ignore testOpenAIEditsModel as it's deprecated Signed-off-by: Hailong Cui --- .../org/opensearch/ml/rest/RestMLRemoteInferenceIT.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java index b00606a24d..94a1055525 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java @@ -15,6 +15,7 @@ import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.message.BasicHeader; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.rules.ExpectedException; import org.opensearch.client.Response; @@ -251,6 +252,7 @@ public void testOpenAIChatCompletionModel() throws IOException, InterruptedExcep assertNotNull(responseMap); } + @Ignore("text-davinci-edit-001 been deprecated on 2024-01-04 and replaced by /v1/chat/completions") public void testOpenAIEditsModel() throws IOException, InterruptedException { // Skip test if key is null if (OPENAI_KEY == null) { @@ -265,7 +267,7 @@ public void testOpenAIEditsModel() throws IOException, InterruptedException { + " \"endpoint\": \"api.openai.com\",\n" + " \"auth\": \"API_Key\",\n" + " \"content_type\": \"application/json\",\n" - + " \"model\": \"gpt-3.5-turbo\"\n" + + " \"model\": \"text-davinci-edit-001\"\n" + " },\n" + " \"credential\": {\n" + " \"openAI_key\": \"" @@ -276,7 +278,7 @@ public void testOpenAIEditsModel() throws IOException, InterruptedException { + " {\n" + " \"action_type\": \"predict\",\n" + " \"method\": \"POST\",\n" - + " \"url\": \"https://api.openai.com/v1/chat/completions\",\n" + + " \"url\": \"https://api.openai.com/v1/edit\",\n" + " \"headers\": { \n" + " \"Authorization\": \"Bearer ${credential.openAI_key}\"\n" + " },\n" From 920592a935d0de704fb6fe242f879906a3ac481f Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Wed, 10 Jan 2024 11:38:06 +0800 Subject: [PATCH 5/7] typo fix Signed-off-by: Hailong Cui --- .../java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java index 94a1055525..07280c2e1c 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMLRemoteInferenceIT.java @@ -278,7 +278,7 @@ public void testOpenAIEditsModel() throws IOException, InterruptedException { + " {\n" + " \"action_type\": \"predict\",\n" + " \"method\": \"POST\",\n" - + " \"url\": \"https://api.openai.com/v1/edit\",\n" + + " \"url\": \"https://api.openai.com/v1/edits\",\n" + " \"headers\": { \n" + " \"Authorization\": \"Bearer ${credential.openAI_key}\"\n" + " },\n" From 79b4ff320a3c1b422a0cdc35fc920d0e69512e07 Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Thu, 11 Jan 2024 00:15:48 +0800 Subject: [PATCH 6/7] update admin password Signed-off-by: Hailong Cui --- .github/workflows/CI-workflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI-workflow.yml b/.github/workflows/CI-workflow.yml index da4d64c33c..e3119c4837 100644 --- a/.github/workflows/CI-workflow.yml +++ b/.github/workflows/CI-workflow.yml @@ -145,12 +145,12 @@ jobs: if: env.imagePresent == 'true' run: | cd .. - docker run -p 9200:9200 -d -p 9600:9600 -e "discovery.type=single-node" opensearch-ml:test + docker run -p 9200:9200 -d -p 9600:9600 -e "discovery.type=single-node" -e OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! opensearch-ml:test sleep 90 - name: Run MLCommons Test if: env.imagePresent == 'true' run: | - security=`curl -XGET https://localhost:9200/_cat/plugins?v -u admin:admin --insecure |grep opensearch-security|wc -l` + security=`curl -XGET https://localhost:9200/_cat/plugins?v -u admin:myStrongPassword123! --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" @@ -158,7 +158,7 @@ jobs: 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 + ./gradlew integTest -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" -Dhttps=true -Duser=admin -Dpassword=myStrongPassword123! else echo "Security plugin is NOT available" ./gradlew integTest -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="docker-cluster" From 1b2bde4466ea7ba5665023050b732301b73890db Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Thu, 11 Jan 2024 10:22:51 +0800 Subject: [PATCH 7/7] test on personal repo Signed-off-by: Hailong Cui --- .github/workflows/CI-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI-workflow.yml b/.github/workflows/CI-workflow.yml index e3119c4837..29d141e92b 100644 --- a/.github/workflows/CI-workflow.yml +++ b/.github/workflows/CI-workflow.yml @@ -91,7 +91,7 @@ jobs: java: [11, 17, 21] name: Test MLCommons Plugin on linux docker - if: github.repository == 'opensearch-project/ml-commons' + # if: github.repository == 'opensearch-project/ml-commons' environment: ml-commons-cicd-env runs-on: ubuntu-latest