-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Add mixed cluster tests for inference #108392
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4286d64
mixed cluster tests are executable
maxhniebergall 4cfa0a6
add tests from upgrade tests
maxhniebergall 16aab6b
[ML] Add mixed cluster tests for existing services
maxhniebergall 95b4c62
clean up
maxhniebergall 1e586fe
review improvements
maxhniebergall c6759aa
spotless
maxhniebergall 2e9d555
remove blocked AzureOpenAI mixed IT
maxhniebergall 5fda71b
improvements from DK review
maxhniebergall fca46fd
temp for testing
maxhniebergall 57cfdc9
refactoring and documentation
maxhniebergall a3bbfce
Revert manual testing configs of "temp for testing"
maxhniebergall 354deb0
Merge branch 'main' into addMixedClusterTestsForInference
maxhniebergall 9d487c4
revert TESTING.asciidoc formatting
maxhniebergall 8a591b9
Update TESTING.asciidoc to avoid reformatting
maxhniebergall c44899b
add minimum version for tests to match minimum version in services
maxhniebergall 9b4c04e
Merge branch 'addMixedClusterTestsForInference' of https://github.com…
maxhniebergall 539d59e
spotless
maxhniebergall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import org.elasticsearch.gradle.Version | ||
import org.elasticsearch.gradle.VersionProperties | ||
import org.elasticsearch.gradle.util.GradleUtils | ||
import org.elasticsearch.gradle.internal.info.BuildParams | ||
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask | ||
|
||
apply plugin: 'elasticsearch.internal-java-rest-test' | ||
apply plugin: 'elasticsearch.internal-test-artifact-base' | ||
apply plugin: 'elasticsearch.bwc-test' | ||
|
||
dependencies { | ||
testImplementation project(path: ':x-pack:plugin:inference:qa:inference-service-tests') | ||
compileOnly project(':x-pack:plugin:core') | ||
javaRestTestImplementation(testArtifact(project(xpackModule('core')))) | ||
javaRestTestImplementation project(path: xpackModule('inference')) | ||
clusterPlugins project( | ||
':x-pack:plugin:inference:qa:test-service-plugin' | ||
) | ||
} | ||
|
||
// inference is available in 8.11 or later | ||
def supportedVersion = bwcVersion -> { | ||
return bwcVersion.onOrAfter(Version.fromString("8.11.0")); | ||
} | ||
|
||
BuildParams.bwcVersions.withWireCompatible(supportedVersion) { bwcVersion, baseName -> | ||
def javaRestTest = tasks.register("v${bwcVersion}#javaRestTest", StandaloneRestIntegTestTask) { | ||
usesBwcDistribution(bwcVersion) | ||
systemProperty("tests.old_cluster_version", bwcVersion) | ||
maxParallelForks = 1 | ||
} | ||
|
||
tasks.register(bwcTaskName(bwcVersion)) { | ||
dependsOn javaRestTest | ||
} | ||
} | ||
|
129 changes: 129 additions & 0 deletions
129
...r/src/javaRestTest/java/org/elasticsearch/xpack/inference/qa/mixed/BaseMixedTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.qa.mixed; | ||
|
||
import org.apache.http.util.EntityUtils; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.settings.SecureString; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
import org.elasticsearch.inference.TaskType; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.http.MockWebServer; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
import org.hamcrest.Matchers; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public abstract class BaseMixedTestCase extends MixedClusterSpecTestCase { | ||
protected static String getUrl(MockWebServer webServer) { | ||
return Strings.format("http://%s:%s", webServer.getHostName(), webServer.getPort()); | ||
} | ||
|
||
@Override | ||
protected Settings restClientSettings() { | ||
String token = ESRestTestCase.basicAuthHeaderValue("x_pack_rest_user", new SecureString("x-pack-test-password".toCharArray())); | ||
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build(); | ||
} | ||
|
||
protected void delete(String inferenceId, TaskType taskType) throws IOException { | ||
var request = new Request("DELETE", Strings.format("_inference/%s/%s", taskType, inferenceId)); | ||
var response = ESRestTestCase.client().performRequest(request); | ||
ESRestTestCase.assertOK(response); | ||
} | ||
|
||
protected void delete(String inferenceId) throws IOException { | ||
var request = new Request("DELETE", Strings.format("_inference/%s", inferenceId)); | ||
var response = ESRestTestCase.client().performRequest(request); | ||
ESRestTestCase.assertOK(response); | ||
} | ||
|
||
protected Map<String, Object> getAll() throws IOException { | ||
var request = new Request("GET", "_inference/_all"); | ||
var response = ESRestTestCase.client().performRequest(request); | ||
ESRestTestCase.assertOK(response); | ||
return ESRestTestCase.entityAsMap(response); | ||
} | ||
|
||
protected Map<String, Object> get(String inferenceId) throws IOException { | ||
var endpoint = Strings.format("_inference/%s", inferenceId); | ||
var request = new Request("GET", endpoint); | ||
var response = ESRestTestCase.client().performRequest(request); | ||
ESRestTestCase.assertOK(response); | ||
return ESRestTestCase.entityAsMap(response); | ||
} | ||
|
||
protected Map<String, Object> get(TaskType taskType, String inferenceId) throws IOException { | ||
var endpoint = Strings.format("_inference/%s/%s", taskType, inferenceId); | ||
var request = new Request("GET", endpoint); | ||
var response = ESRestTestCase.client().performRequest(request); | ||
ESRestTestCase.assertOK(response); | ||
return ESRestTestCase.entityAsMap(response); | ||
} | ||
|
||
protected Map<String, Object> inference(String inferenceId, TaskType taskType, String input) throws IOException { | ||
var endpoint = Strings.format("_inference/%s/%s", taskType, inferenceId); | ||
var request = new Request("POST", endpoint); | ||
request.setJsonEntity("{\"input\": [" + '"' + input + '"' + "]}"); | ||
|
||
var response = ESRestTestCase.client().performRequest(request); | ||
ESRestTestCase.assertOK(response); | ||
return ESRestTestCase.entityAsMap(response); | ||
} | ||
|
||
protected Map<String, Object> rerank(String inferenceId, List<String> inputs, String query) throws IOException { | ||
var endpoint = Strings.format("_inference/rerank/%s", inferenceId); | ||
var request = new Request("POST", endpoint); | ||
|
||
StringBuilder body = new StringBuilder("{").append("\"query\":\"").append(query).append("\",").append("\"input\":["); | ||
|
||
for (int i = 0; i < inputs.size(); i++) { | ||
body.append("\"").append(inputs.get(i)).append("\""); | ||
if (i < inputs.size() - 1) { | ||
body.append(","); | ||
} | ||
} | ||
|
||
body.append("]}"); | ||
request.setJsonEntity(body.toString()); | ||
|
||
var response = ESRestTestCase.client().performRequest(request); | ||
ESRestTestCase.assertOK(response); | ||
return ESRestTestCase.entityAsMap(response); | ||
} | ||
|
||
protected void put(String inferenceId, String modelConfig, TaskType taskType) throws IOException { | ||
String endpoint = Strings.format("_inference/%s/%s?error_trace", taskType, inferenceId); | ||
var request = new Request("PUT", endpoint); | ||
request.setJsonEntity(modelConfig); | ||
var response = ESRestTestCase.client().performRequest(request); | ||
logger.warn("PUT response: {}", response.toString()); | ||
System.out.println("PUT response: " + response.toString()); | ||
ESRestTestCase.assertOKAndConsume(response); | ||
} | ||
|
||
protected static void assertOkOrCreated(Response response) throws IOException { | ||
int statusCode = response.getStatusLine().getStatusCode(); | ||
// Once EntityUtils.toString(entity) is called the entity cannot be reused. | ||
// Avoid that call with check here. | ||
if (statusCode == 200 || statusCode == 201) { | ||
return; | ||
} | ||
|
||
String responseStr = EntityUtils.toString(response.getEntity()); | ||
ESTestCase.assertThat( | ||
responseStr, | ||
response.getStatusLine().getStatusCode(), | ||
Matchers.anyOf(Matchers.equalTo(200), Matchers.equalTo(201)) | ||
); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious why we need to change the version in ml cpp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you increment the elasticsearch version to one that doesn't exist, then the build system will not find the (non-existent) ML-CPP artifact. If, instead, we hardcode the current version of elasticsearch, the existing ML-CPP artifact will be downloaded.