Skip to content

Commit

Permalink
Addressing Jack comments
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun committed Dec 29, 2023
1 parent 3cd927b commit 3a3d175
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 66 deletions.
18 changes: 9 additions & 9 deletions qa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ task pullBwcPlugin {
}
}

// Task to zip ml-commons plugin from archive
task zipBwcMlCommonsPlugin(type: Zip) {
// Task to unzip ml-commons plugin from archive
task unZipBwcMlCommonsPlugin(type: Zip) {
dependsOn "pullMlCommonsBwcPlugin"
from(Path.of(tmp_dir.absolutePath, "opensearch-ml"))
destinationDirectory = tmp_dir
Expand All @@ -168,10 +168,10 @@ task zipBwcMlCommonsPlugin(type: Zip) {
}
}

// Task to zip knn plugin from archive
task zipBwcKnnPlugin(type: Zip) {
// Task to unzip knn plugin from archive
task unZipBwcKnnPlugin(type: Zip) {
dependsOn "pullKnnBwcPlugin"
dependsOn "zipBwcMlCommonsPlugin"
dependsOn "unZipBwcMlCommonsPlugin"
from(Path.of(tmp_dir.absolutePath, "opensearch-knn"))
destinationDirectory = tmp_dir
archiveFileName = "opensearch-knn-${neural_search_bwc_version_no_qualifier}.zip"
Expand All @@ -180,9 +180,9 @@ task zipBwcKnnPlugin(type: Zip) {
}
}

// Task to zip neural search plugin from archive
task zipBwcPlugin(type: Zip) {
dependsOn "zipBwcKnnPlugin"
// Task to unzip neural search plugin from archive
task unZipBwcPlugin(type: Zip) {
dependsOn "unZipBwcKnnPlugin"
dependsOn "pullBwcPlugin"
from(Path.of(tmp_dir.absolutePath, "opensearch-neural-search"))
destinationDirectory = tmp_dir
Expand All @@ -194,6 +194,6 @@ task zipBwcPlugin(type: Zip) {


task bwcTestSuite {
dependsOn ":qa:restart-upgrade:testRestartUpgrade"
dependsOn ":qa:restart-upgrade:testAgainstNewCluster"
dependsOn ":qa:rolling-upgrade:testRollingUpgrade"
}
10 changes: 5 additions & 5 deletions qa/restart-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ testClusters {
versions = [neural_search_bwc_version, opensearch_version]
numberOfNodes = 3
jvmArgs("-Xms1g", "-Xmx4g")
plugin(project.tasks.zipBwcMlCommonsPlugin.archiveFile)
plugin(project.tasks.zipBwcKnnPlugin.archiveFile)
plugin(project.tasks.zipBwcPlugin.archiveFile)
plugin(project.tasks.unZipBwcMlCommonsPlugin.archiveFile)
plugin(project.tasks.unZipBwcKnnPlugin.archiveFile)
plugin(project.tasks.unZipBwcPlugin.archiveFile)
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'http.content_type.required', 'true'
}
}

// Task to run BWC tests against the old cluster
task testAgainstOldCluster(type: StandaloneRestIntegTestTask) {
dependsOn "zipBwcPlugin"
dependsOn "unZipBwcPlugin"
useCluster testClusters."${baseName}"
systemProperty 'tests.rest.bwcsuite_cluster', 'old_cluster'
systemProperty 'tests.is_old_cluster', 'true'
Expand All @@ -41,7 +41,7 @@ task testAgainstOldCluster(type: StandaloneRestIntegTestTask) {
}

// All nodes are upgraded to latest version and run the tests
task testRestartUpgrade(type: StandaloneRestIntegTestTask) {
task testAgainstNewCluster(type: StandaloneRestIntegTestTask) {
dependsOn "testAgainstOldCluster"
dependsOn rootProject.tasks.assemble
useCluster testClusters."${baseName}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import org.opensearch.test.rest.OpenSearchRestTestCase;

public abstract class AbstractRestartUpgradeRestTestCase extends BaseNeuralSearchIT {
protected static String testIndex;
// protected static String testIndex;

@Before
protected void setIndex() {
protected String getIndexNameForTest() {
// Creating index name by concatenating "neural-bwc-" prefix with test method name
// for all the tests in this sub-project
testIndex = NEURAL_SEARCH_BWC_PREFIX + getTestName().toLowerCase(Locale.ROOT);
return NEURAL_SEARCH_BWC_PREFIX + getTestName().toLowerCase(Locale.ROOT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
public class SemanticSearchIT extends AbstractRestartUpgradeRestTestCase {

private static final String PIPELINE_NAME = "nlp-pipeline";
private static String DOC_ID = "0";
private static final String TEST_FIELD = "passage_text";
private static final String TEXT = "Hello world";
private static final String TEXT_1 = "Hello world a";

// Test restart-upgrade Semantic Search
// Create Text Embedding Processor, Ingestion Pipeline and add document
Expand All @@ -33,32 +33,33 @@ public void testSemanticSearch() throws Exception {
loadModel(modelId);
createPipelineProcessor(modelId, PIPELINE_NAME);
createIndexWithConfiguration(
testIndex,
getIndexNameForTest(),
Files.readString(Path.of(classLoader.getResource("processor/IndexMappings.json").toURI())),
PIPELINE_NAME
);
addDocument(testIndex, DOC_ID, TEST_FIELD, TEXT);
addDocument(getIndexNameForTest(), "0", TEST_FIELD, TEXT);
} else {
Map<String, Object> pipeline = getIngestionPipeline(PIPELINE_NAME);
assertNotNull(pipeline);
String modelId = getModelId(pipeline, TEXT_EMBEDDING_PROCESSOR);
addDocument(getIndexNameForTest(), "1", TEST_FIELD, TEXT_1);
validateTestIndex(modelId);
deletePipeline(PIPELINE_NAME);
deleteModel(modelId);
deleteIndex(testIndex);
deleteIndex(getIndexNameForTest());
}
}

private void validateTestIndex(String modelId) throws Exception {
int docCount = getDocCount(testIndex);
assertEquals(1, docCount);
int docCount = getDocCount(getIndexNameForTest());
assertEquals(2, docCount);
loadModel(modelId);
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder();
neuralQueryBuilder.fieldName("passage_embedding");
neuralQueryBuilder.modelId(modelId);
neuralQueryBuilder.queryText(TEXT);
neuralQueryBuilder.k(1);
Map<String, Object> response = search(testIndex, neuralQueryBuilder, 1);
Map<String, Object> response = search(getIndexNameForTest(), neuralQueryBuilder, 1);
assertNotNull(response);
}

Expand All @@ -70,13 +71,11 @@ private String uploadTextEmbeddingModel() throws Exception {
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);
);
String modelGroupId = registerModelGroup(
String.format(LOCALE, modelGroupRegisterRequestBody, "public_model_" + RandomizedTest.randomAsciiAlphanumOfLength(8))
);
return uploadModelId(String.format(LOCALE, requestBody, modelGroupId));
}

protected void createPipelineProcessor(String modelId, String pipelineName, ProcessorType processorType) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "<MODEL_GROUP_NAME>",
"name": "%s",
"description": "This is a public model group"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"model_format": "TORCH_SCRIPT",
"model_task_type": "text_embedding",
"model_content_hash_value": "e13b74006290a9d0f58c1376f9629d4ebc05a0f9385f40db837452b167ae9021",
"model_group_id": "<MODEL_GROUP_ID>",
"model_group_id": "%s",
"model_config": {
"model_type": "bert",
"embedding_dimension": 768,
Expand Down
8 changes: 4 additions & 4 deletions qa/rolling-upgrade/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ testClusters {
testDistribution = "ARCHIVE"
versions = [neural_search_bwc_version, opensearch_version]
numberOfNodes = 3
plugin(project.tasks.zipBwcMlCommonsPlugin.archiveFile)
plugin(project.tasks.zipBwcKnnPlugin.archiveFile)
plugin(project.tasks.zipBwcPlugin.archiveFile)
plugin(project.tasks.unZipBwcMlCommonsPlugin.archiveFile)
plugin(project.tasks.unZipBwcKnnPlugin.archiveFile)
plugin(project.tasks.unZipBwcPlugin.archiveFile)
jvmArgs("-Xms1g", "-Xmx4g")
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'http.content_type.required', 'true'
Expand All @@ -29,7 +29,7 @@ testClusters {

// Task to run BWC tests against the old cluster
task testAgainstOldCluster(type: StandaloneRestIntegTestTask) {
dependsOn "zipBwcPlugin"
dependsOn "unZipBwcPlugin"
useCluster testClusters."${baseName}"
systemProperty 'tests.rest.bwcsuite_cluster', 'old_cluster'
systemProperty 'tests.plugin_bwc_version', neural_search_bwc_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import static org.opensearch.neuralsearch.TestUtils.NEURAL_SEARCH_BWC_PREFIX;

public abstract class AbstractRollingUpgradeTestCase extends BaseNeuralSearchIT {
protected String testIndex;
// protected String testIndex;

@Before
protected void setIndex() {
protected String getIndexNameForTest() {
// Creating index name by concatenating "neural-bwc-" prefix with test method name
// for all the tests in this sub-project
testIndex = NEURAL_SEARCH_BWC_PREFIX + getTestName().toLowerCase(Locale.ROOT);
return NEURAL_SEARCH_BWC_PREFIX + getTestName().toLowerCase(Locale.ROOT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SemanticSearchIT extends AbstractRollingUpgradeTestCase {
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;
private static final int NUM_DOCS_PER_ROUND = 1;

// Test rolling-upgrade Semantic Search
// Create Text Embedding Processor, Ingestion Pipeline and add document
Expand All @@ -32,48 +32,48 @@ public void testSemanticSearch() throws Exception {
loadModel(modelId);
createPipelineProcessor(modelId, PIPELINE_NAME);
createIndexWithConfiguration(
testIndex,
getIndexNameForTest(),
Files.readString(Path.of(classLoader.getResource("processor/IndexMappings.json").toURI())),
PIPELINE_NAME
);
addDocument(testIndex, "0", TEST_FIELD, TEXT);
addDocument(getIndexNameForTest(), "0", TEST_FIELD, TEXT);
break;
case MIXED:
modelId = getModelId(PIPELINE_NAME);
int totalDocsCountMixed;
if (isFirstMixedRound()) {
totalDocsCountMixed = NUM_DOCS;
totalDocsCountMixed = NUM_DOCS_PER_ROUND;
validateTestIndexOnUpgrade(totalDocsCountMixed, modelId, TEXT);
addDocument(testIndex, "1", TEST_FIELD, TEXT_MIXED);
addDocument(getIndexNameForTest(), "1", TEST_FIELD, TEXT_MIXED);

} else {
totalDocsCountMixed = 2 * NUM_DOCS;
totalDocsCountMixed = 2 * NUM_DOCS_PER_ROUND;
validateTestIndexOnUpgrade(totalDocsCountMixed, modelId, TEXT_MIXED);
}
break;
case UPGRADED:
modelId = getModelId(PIPELINE_NAME);
int totalDocsCountUpgraded = 3 * NUM_DOCS;
addDocument(testIndex, "2", TEST_FIELD, TEXT_UPGRADED);
int totalDocsCountUpgraded = 3 * NUM_DOCS_PER_ROUND;
addDocument(getIndexNameForTest(), "2", TEST_FIELD, TEXT_UPGRADED);
validateTestIndexOnUpgrade(totalDocsCountUpgraded, modelId, TEXT_UPGRADED);
deletePipeline(PIPELINE_NAME);
deleteModel(modelId);
deleteIndex(testIndex);
deleteIndex(getIndexNameForTest());
break;
}

}

private void validateTestIndexOnUpgrade(int numberOfDocs, String modelId, String text) throws Exception {
int docCount = getDocCount(testIndex);
int docCount = getDocCount(getIndexNameForTest());
assertEquals(numberOfDocs, docCount);
loadModel(modelId);
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder();
neuralQueryBuilder.fieldName("passage_embedding");
neuralQueryBuilder.modelId(modelId);
neuralQueryBuilder.queryText(text);
neuralQueryBuilder.k(1);
Map<String, Object> response = search(testIndex, neuralQueryBuilder, 1);
Map<String, Object> response = search(getIndexNameForTest(), neuralQueryBuilder, 1);
assertNotNull(response);
}

Expand All @@ -85,13 +85,11 @@ private String uploadTextEmbeddingModel() throws Exception {
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);
);
String modelGroupId = registerModelGroup(
String.format(LOCALE, modelGroupRegisterRequestBody, "public_model_" + RandomizedTest.randomAsciiAlphanumOfLength(8))
);
return uploadModelId(String.format(LOCALE, requestBody, modelGroupId));
}

protected void createPipelineProcessor(String modelId, String pipelineName, ProcessorType processorType) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "<MODEL_GROUP_NAME>",
"name": "%s",
"description": "This is a public model group"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"model_format": "TORCH_SCRIPT",
"model_task_type": "text_embedding",
"model_content_hash_value": "e13b74006290a9d0f58c1376f9629d4ebc05a0f9385f40db837452b167ae9021",
"model_group_id": "<MODEL_GROUP_ID>",
"model_group_id": "%s",
"model_config": {
"model_type": "bert",
"embedding_dimension": 768,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,15 +839,13 @@ protected void addDocument(String index, String docId, String fieldName, String
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field(fieldName, text).endObject();
request.setJsonEntity(builder.toString());
client().performRequest(request);

request = new Request("POST", "/" + index + "/_refresh");
Response response = client().performRequest(request);
assertEquals(request.getEndpoint() + ": failed", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode()));
}

/**
* Get ingest pipeline
* @param pipelineName of the ingest pipeline
* Get ingest pipeline
* @param pipelineName of the ingest pipeline
*
* @return get pipeline response as a map object
*/
@SneakyThrows
protected Map<String, Object> getIngestionPipeline(String pipelineName) {
Expand All @@ -863,6 +861,8 @@ protected Map<String, Object> getIngestionPipeline(String pipelineName) {
* Delete pipeline
*
* @param pipelineName of the pipeline
*
* @return delete pipeline response as a map object
*/
@SneakyThrows
protected Map<String, Object> deletePipeline(String pipelineName) {
Expand Down

0 comments on commit 3a3d175

Please sign in to comment.