Skip to content

Commit

Permalink
Rolling Upgrade tests
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun committed Dec 20, 2023
1 parent 1f880dd commit a92e37c
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 9 deletions.
1 change: 0 additions & 1 deletion qa/restart-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{

Expand Down Expand Up @@ -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<String, Object> searchResponseAsMap = search(testIndex,neuralQueryBuilder,1);
Map<String, Object> total = getTotalHits(searchResponseAsMap);
assertNotNull(total.get("value"));
deleteIndex(testIndex);
}

Expand All @@ -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<String, Object> getTotalHits(Map<String, Object> searchResponseAsMap) {
Map<String, Object> hitsMap = (Map<String, Object>) searchResponseAsMap.get("hits");
return (Map<String, Object>) hitsMap.get("total");
}
}
16 changes: 8 additions & 8 deletions qa/rolling-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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("<MODEL_GROUP_NAME>", "public_model_" + RandomizedTest.randomAsciiAlphanumOfLength(8));

String modelGroupId=registerModelGroup(modelGroupRegisterRequestBody);

requestBody = requestBody.replace("<MODEL_GROUP_ID>", 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "<MODEL_GROUP_NAME>",
"description": "This is a public model group"
}
32 changes: 32 additions & 0 deletions qa/rolling-upgrade/src/test/resources/processor/IndexMappings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -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_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"
}

0 comments on commit a92e37c

Please sign in to comment.