From a92e37c6d3d9bc8a1d87f063c4511e897765043d Mon Sep 17 00:00:00 2001 From: Varun Jain Date: Wed, 20 Dec 2023 12:18:45 -0800 Subject: [PATCH] Rolling Upgrade tests Signed-off-by: Varun Jain --- qa/restart-upgrade/build.gradle | 1 - .../neuralsearch/bwc/TextSearch.java | 14 ++++ qa/rolling-upgrade/build.gradle | 16 ++-- .../neuralsearch/bwc/TextSearch.java | 82 +++++++++++++++++++ .../CreateModelGroupRequestBody.json | 4 + .../resources/processor/IndexMappings.json | 32 ++++++++ .../processor/PipelineConfiguration.json | 18 ++++ .../processor/UploadModelRequestBody.json | 15 ++++ 8 files changed, 173 insertions(+), 9 deletions(-) create mode 100644 qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/TextSearch.java create mode 100644 qa/rolling-upgrade/src/test/resources/processor/CreateModelGroupRequestBody.json create mode 100644 qa/rolling-upgrade/src/test/resources/processor/IndexMappings.json create mode 100644 qa/rolling-upgrade/src/test/resources/processor/PipelineConfiguration.json create mode 100644 qa/rolling-upgrade/src/test/resources/processor/UploadModelRequestBody.json diff --git a/qa/restart-upgrade/build.gradle b/qa/restart-upgrade/build.gradle index fcf3df0e2..6ab0849dd 100644 --- a/qa/restart-upgrade/build.gradle +++ b/qa/restart-upgrade/build.gradle @@ -12,7 +12,6 @@ apply from : "$rootDir/qa/build.gradle" String default_bwc_version = System.getProperty("bwc.version") String neural_search_bwc_version = System.getProperty("tests.bwc.version", default_bwc_version) boolean isSnapshot = neural_search_bwc_version.contains("-SNAPSHOT") -String neural_search_bwc_version_no_qualifier = isSnapshot ? neural_search_bwc_version - "-SNAPSHOT" : neural_search_bwc_version String baseName = "neuralSearchBwcCluster-restart" String knn_bwc_version_no_qualifier = isSnapshot ? neural_search_bwc_version - "-SNAPSHOT" : neural_search_bwc_version diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/TextSearch.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/TextSearch.java index 7fd707b00..3a7ea2388 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/TextSearch.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/TextSearch.java @@ -9,10 +9,12 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; +import java.util.Map; import org.opensearch.client.Request; import org.opensearch.client.Response; import static org.opensearch.neuralsearch.TestUtils.NODES_BWC_CLUSTER; +import org.opensearch.neuralsearch.query.NeuralQueryBuilder; public class TextSearch extends AbstractRestartUpgradeRestTestCase{ @@ -43,6 +45,13 @@ public void testIndex() throws Exception{ private void validateTestIndex() throws Exception { int docCount=getDocCount(testIndex); assertEquals(1,docCount); + NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder(); + neuralQueryBuilder.fieldName(TEST_FIELD); + neuralQueryBuilder.queryText(TEXT); + neuralQueryBuilder.k(1); + Map searchResponseAsMap = search(testIndex,neuralQueryBuilder,1); + Map total = getTotalHits(searchResponseAsMap); + assertNotNull(total.get("value")); deleteIndex(testIndex); } @@ -67,4 +76,9 @@ protected void createPipelineProcessor(String modelId, String pipelineName, Proc String requestBody=Files.readString(Path.of(classLoader.getResource("processor/PipelineConfiguration.json").toURI())); createPipelineProcessor(requestBody,pipelineName,modelId); } + + private Map getTotalHits(Map searchResponseAsMap) { + Map hitsMap = (Map) searchResponseAsMap.get("hits"); + return (Map) hitsMap.get("total"); + } } diff --git a/qa/rolling-upgrade/build.gradle b/qa/rolling-upgrade/build.gradle index 863bfca9a..b03959645 100644 --- a/qa/rolling-upgrade/build.gradle +++ b/qa/rolling-upgrade/build.gradle @@ -23,14 +23,14 @@ testClusters { plugin(project.tasks.zipBwcPlugin.archiveFile) setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" setting 'http.content_type.required', 'true' -// environment "LD_LIBRARY_PATH", "${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/knnlib;${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/lib" -// if (Os.isFamily(Os.FAMILY_WINDOWS)) { -// // While running on Windows OS, setting the PATH environment variable to include the paths to dlls of JNI libraries and windows dependencies -// environment('PATH', System.getenv('PATH') + ";$rootDir/jni/release" + ";$rootDir/src/main/resources/windowsDependencies") -// systemProperty "java.library.path", "${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/knnlib;${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/lib" -// } else { -// systemProperty "java.library.path", "${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/knnlib:${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/lib" -// } + environment "LD_LIBRARY_PATH", "${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/knnlib;${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/lib" + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + // While running on Windows OS, setting the PATH environment variable to include the paths to dlls of JNI libraries and windows dependencies + environment('PATH', System.getenv('PATH') + ";$rootDir/jni/release" + ";$rootDir/src/main/resources/windowsDependencies") + systemProperty "java.library.path", "${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/knnlib;${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/lib" + } else { + systemProperty "java.library.path", "${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/knnlib:${buildDir}/testclusters/${baseName}-0/distro/${knn_bwc_version_no_qualifier}-ARCHIVE/plugins/opensearch-knn/lib" + } } } diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/TextSearch.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/TextSearch.java new file mode 100644 index 000000000..0e133ff40 --- /dev/null +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/TextSearch.java @@ -0,0 +1,82 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.neuralsearch.bwc; + +import com.carrotsearch.randomizedtesting.RandomizedTest; +import java.nio.file.Files; +import java.nio.file.Path; +import static org.opensearch.neuralsearch.TestUtils.NODES_BWC_CLUSTER; + +public class TextSearch extends AbstractRollingUpgradeTestCase{ + private static final String PIPELINE_NAME = "nlp-pipeline"; + private static final String TEST_FIELD = "test-field"; + private static final String TEXT= "Hello world"; + private static final String TEXT_MIXED= "Hello world mixed"; + private static final String TEXT_UPGRADED= "Hello world upgraded"; + private static final int NUM_DOCS = 1; + + public void testIndex() throws Exception{ + waitForClusterHealthGreen(NODES_BWC_CLUSTER); + switch (getClusterType()){ + case OLD: + String modelId= uploadTextEmbeddingModel(); + loadModel(modelId); + createPipelineProcessor(modelId,PIPELINE_NAME); + createIndexWithConfiguration( + testIndex, + Files.readString(Path.of(classLoader.getResource("processor/IndexMappings.json").toURI())), + PIPELINE_NAME + ); + addDocument(testIndex, "0",TEST_FIELD,TEXT); + break; + case MIXED: + int totalDocsCountMixed; + if (isFirstMixedRound()){ + totalDocsCountMixed=NUM_DOCS; + validateTestIndexOnUpgrade(totalDocsCountMixed); + addDocument(testIndex, "1",TEST_FIELD,TEXT_MIXED); + }else{ + totalDocsCountMixed=2*NUM_DOCS; + validateTestIndexOnUpgrade(totalDocsCountMixed); + } + break; + case UPGRADED: + int totalDocsCountUpgraded=3*NUM_DOCS; + addDocument(testIndex, "2",TEST_FIELD,TEXT_UPGRADED); + validateTestIndexOnUpgrade(totalDocsCountUpgraded); + deleteIndex(testIndex); + break; + } + + } + + private void validateTestIndexOnUpgrade(int numberOfDocs) throws Exception { + int docCount=getDocCount(testIndex); + assertEquals(numberOfDocs,docCount); + } + + private String uploadTextEmbeddingModel() throws Exception { + String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); + return registerModelGroupAndGetModelId(requestBody); + } + + private String registerModelGroupAndGetModelId(String requestBody) throws Exception { + String modelGroupRegisterRequestBody = Files.readString( + Path.of(classLoader.getResource("processor/CreateModelGroupRequestBody.json").toURI()) + ).replace("", "public_model_" + RandomizedTest.randomAsciiAlphanumOfLength(8)); + + String modelGroupId=registerModelGroup(modelGroupRegisterRequestBody); + + requestBody = requestBody.replace("", modelGroupId); + + return uploadModelId(requestBody); + } + + protected void createPipelineProcessor(String modelId, String pipelineName, ProcessorType processorType) throws Exception { + String requestBody=Files.readString(Path.of(classLoader.getResource("processor/PipelineConfiguration.json").toURI())); + createPipelineProcessor(requestBody,pipelineName,modelId); + } +} diff --git a/qa/rolling-upgrade/src/test/resources/processor/CreateModelGroupRequestBody.json b/qa/rolling-upgrade/src/test/resources/processor/CreateModelGroupRequestBody.json new file mode 100644 index 000000000..91f68e222 --- /dev/null +++ b/qa/rolling-upgrade/src/test/resources/processor/CreateModelGroupRequestBody.json @@ -0,0 +1,4 @@ +{ + "name": "", + "description": "This is a public model group" +} \ No newline at end of file diff --git a/qa/rolling-upgrade/src/test/resources/processor/IndexMappings.json b/qa/rolling-upgrade/src/test/resources/processor/IndexMappings.json new file mode 100644 index 000000000..03a683079 --- /dev/null +++ b/qa/rolling-upgrade/src/test/resources/processor/IndexMappings.json @@ -0,0 +1,32 @@ +{ + "settings": { + "index": { + "knn": true, + "knn.algo_param.ef_search": 100, + "refresh_interval": "30s", + "default_pipeline": "%s" + }, + "number_of_shards": 1, + "number_of_replicas": 0 + }, + "mappings": { + "properties": { + "passage_embedding": { + "type": "knn_vector", + "dimension": 768, + "method": { + "name": "hnsw", + "space_type": "l2", + "engine": "lucene", + "parameters": { + "ef_construction": 128, + "m": 24 + } + } + }, + "passage_text": { + "type": "text" + } + } + } +} \ No newline at end of file diff --git a/qa/rolling-upgrade/src/test/resources/processor/PipelineConfiguration.json b/qa/rolling-upgrade/src/test/resources/processor/PipelineConfiguration.json new file mode 100644 index 000000000..5d0bfe90f --- /dev/null +++ b/qa/rolling-upgrade/src/test/resources/processor/PipelineConfiguration.json @@ -0,0 +1,18 @@ +{ + "description": "text embedding pipeline for hybrid", + "processors": [ + { + "text_embedding": { + "model_id": "%s", + "field_map": { + "title": "title_knn", + "favor_list": "favor_list_knn", + "favorites": { + "game": "game_knn", + "movie": "movie_knn" + } + } + } + } + ] +} \ No newline at end of file diff --git a/qa/rolling-upgrade/src/test/resources/processor/UploadModelRequestBody.json b/qa/rolling-upgrade/src/test/resources/processor/UploadModelRequestBody.json new file mode 100644 index 000000000..6769e78c7 --- /dev/null +++ b/qa/rolling-upgrade/src/test/resources/processor/UploadModelRequestBody.json @@ -0,0 +1,15 @@ +{ + "name": "traced_small_model", + "version": "1.0.0", + "model_format": "TORCH_SCRIPT", + "model_task_type": "text_embedding", + "model_content_hash_value": "e13b74006290a9d0f58c1376f9629d4ebc05a0f9385f40db837452b167ae9021", + "model_group_id": "", + "model_config": { + "model_type": "bert", + "embedding_dimension": 768, + "framework_type": "sentence_transformers", + "all_config": "{\"architectures\":[\"BertModel\"],\"max_position_embeddings\":512,\"model_type\":\"bert\",\"num_attention_heads\":12,\"num_hidden_layers\":6}" + }, + "url": "https://github.com/opensearch-project/ml-commons/blob/2.x/ml-algorithms/src/test/resources/org/opensearch/ml/engine/algorithms/text_embedding/traced_small_model.zip?raw=true" +} \ No newline at end of file