Skip to content

Commit 7bcec6c

Browse files
author
Max Hniebergall
committed
Add deprecation warning and integration tests
1 parent fc72d8b commit 7bcec6c

File tree

5 files changed

+107
-2
lines changed

5 files changed

+107
-2
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/PutInferenceModelAction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import org.elasticsearch.common.bytes.BytesReference;
1616
import org.elasticsearch.common.io.stream.StreamInput;
1717
import org.elasticsearch.common.io.stream.StreamOutput;
18+
import org.elasticsearch.common.logging.DeprecationCategory;
19+
import org.elasticsearch.common.logging.DeprecationLogger;
1820
import org.elasticsearch.common.xcontent.XContentHelper;
1921
import org.elasticsearch.inference.ModelConfigurations;
2022
import org.elasticsearch.inference.TaskType;
@@ -37,6 +39,7 @@ public class PutInferenceModelAction extends ActionType<PutInferenceModelAction.
3739

3840
public static final PutInferenceModelAction INSTANCE = new PutInferenceModelAction();
3941
public static final String NAME = "cluster:admin/xpack/inference/put";
42+
private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(PutInferenceModelAction.class);
4043

4144
public PutInferenceModelAction() {
4245
super(NAME);
@@ -86,6 +89,13 @@ public BytesReference getRewrittenContent() {
8689
"Request cannot contain both [task_settings] and [parameters], use only [parameters]",
8790
RestStatus.BAD_REQUEST
8891
);
92+
} else if (newContent.containsKey(TASK_SETTINGS)) {
93+
DEPRECATION_LOGGER.critical(
94+
DeprecationCategory.API,
95+
"inference_api_task_settings_deprecated_use_parameters",
96+
"The [task_settings] field is deprecated and will be removed in a future release. "
97+
+ "Please use only the [parameters] field instead."
98+
);
8999
} else if (newContent.containsKey(PARAMETERS)) {
90100
newContent.put(TASK_SETTINGS, newContent.get(PARAMETERS));
91101
newContent.remove(PARAMETERS);

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceBaseRestTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.client.RequestOptions;
1313
import org.elasticsearch.client.Response;
1414
import org.elasticsearch.client.ResponseListener;
15+
import org.elasticsearch.client.WarningsHandler;
1516
import org.elasticsearch.common.Strings;
1617
import org.elasticsearch.common.settings.SecureString;
1718
import org.elasticsearch.common.settings.Settings;
@@ -81,6 +82,45 @@ static String mockSparseServiceModelConfig(@Nullable TaskType taskTypeInBody) {
8182
""", taskType);
8283
}
8384

85+
static String mockSparseServiceModelConfigWithParameters(@Nullable TaskType taskTypeInBody) {
86+
var taskType = taskTypeInBody == null ? "" : "\"task_type\": \"" + taskTypeInBody + "\",";
87+
return Strings.format("""
88+
{
89+
%s
90+
"service": "test_service",
91+
"service_settings": {
92+
"model": "my_model",
93+
"hidden_field": "my_hidden_value",
94+
"api_key": "abc64"
95+
},
96+
"parameters": {
97+
"temperature": 3
98+
}
99+
}
100+
""", taskType);
101+
}
102+
103+
static String mockSparseServiceModelConfigWithParametersAndTaskSettings(@Nullable TaskType taskTypeInBody) {
104+
var taskType = taskTypeInBody == null ? "" : "\"task_type\": \"" + taskTypeInBody + "\",";
105+
return Strings.format("""
106+
{
107+
%s
108+
"service": "test_service",
109+
"service_settings": {
110+
"model": "my_model",
111+
"hidden_field": "my_hidden_value",
112+
"api_key": "abc64"
113+
},
114+
"parameters": {
115+
"temperature": 3
116+
},
117+
"task_settings": {
118+
"temperature": 3
119+
}
120+
}
121+
""", taskType);
122+
}
123+
84124
static String mockCompletionServiceModelConfig(@Nullable TaskType taskTypeInBody) {
85125
var taskType = taskTypeInBody == null ? "" : "\"task_type\": \"" + taskTypeInBody + "\",";
86126
return Strings.format("""
@@ -230,6 +270,8 @@ protected Map<String, Object> putModel(String modelId, String modelConfig) throw
230270
Map<String, Object> putRequest(String endpoint, String body) throws IOException {
231271
var request = new Request("PUT", endpoint);
232272
request.setJsonEntity(body);
273+
request.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE).build()); // TODO remove
274+
// permissive warnings once the deprecation warnings are removed in 9.0
233275
var response = client().performRequest(request);
234276
assertOkOrCreated(response);
235277
return entityAsMap(response);

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceCrudIT.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.xpack.inference;
1111

1212
import org.apache.http.util.EntityUtils;
13+
import org.elasticsearch.ElasticsearchStatusException;
1314
import org.elasticsearch.client.ResponseException;
1415
import org.elasticsearch.common.settings.Settings;
1516
import org.elasticsearch.inference.TaskType;
@@ -66,6 +67,49 @@ public void testGet() throws IOException {
6667
}
6768
}
6869

70+
public void testGetWithParameters() throws IOException {
71+
72+
putModel("se_model_" + 1, mockSparseServiceModelConfigWithParameters(null), TaskType.SPARSE_EMBEDDING);
73+
74+
putModel("te_model_" + 1, mockSparseServiceModelConfigWithParameters(null), TaskType.TEXT_EMBEDDING);
75+
76+
var getAllModels = getAllModels();
77+
int numModels = 2 + 1; // 2 above + default model
78+
assertThat(getAllModels, hasSize(numModels));
79+
80+
var getSparseModels = getModels("_all", TaskType.SPARSE_EMBEDDING);
81+
int numSparseModels = 1 + 1; // 1 above + default model
82+
assertThat(getSparseModels, hasSize(numSparseModels));
83+
for (var sparseModel : getSparseModels) {
84+
assertEquals("sparse_embedding", sparseModel.get("task_type"));
85+
}
86+
87+
var getDenseModels = getModels("_all", TaskType.TEXT_EMBEDDING);
88+
assertThat(getDenseModels, hasSize(1));
89+
for (var denseModel : getDenseModels) {
90+
assertEquals("text_embedding", denseModel.get("task_type"));
91+
}
92+
93+
var singleModel = getModels("se_model_1", TaskType.SPARSE_EMBEDDING);
94+
assertThat(singleModel, hasSize(1));
95+
assertEquals("se_model_1", singleModel.get(0).get("inference_id"));
96+
97+
deleteModel("se_model_" + 1, TaskType.SPARSE_EMBEDDING);
98+
99+
deleteModel("te_model_" + 1, TaskType.TEXT_EMBEDDING);
100+
}
101+
102+
public void testGetWithParametersAndTaskSettingsFails() throws IOException {
103+
assertThrows(
104+
ResponseException.class,
105+
() -> putModel("se_model_" + 1, mockSparseServiceModelConfigWithParametersAndTaskSettings(null), TaskType.SPARSE_EMBEDDING)
106+
);
107+
assertThrows(
108+
ResponseException.class,
109+
() -> putModel("te_model_" + 1, mockSparseServiceModelConfigWithParametersAndTaskSettings(null), TaskType.TEXT_EMBEDDING)
110+
);
111+
}
112+
69113
public void testGetModelWithWrongTaskType() throws IOException {
70114
putModel("sparse_embedding_model", mockSparseServiceModelConfig(), TaskType.SPARSE_EMBEDDING);
71115
var e = expectThrows(ResponseException.class, () -> getModels("sparse_embedding_model", TaskType.TEXT_EMBEDDING));
@@ -123,6 +167,7 @@ public void testSkipValidationAndStart() throws IOException {
123167

124168
// We would expect an error about the invalid API key if the validation occurred
125169
putModel("unvalidated", openAiConfigWithBadApiKey, TaskType.TEXT_EMBEDDING);
170+
deleteModel("unvalidated");
126171
}
127172

128173
public void testDeleteEndpointWhileReferencedByPipeline() throws IOException {

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferencePermissionsIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
import org.apache.http.HttpHost;
1111
import org.elasticsearch.client.Request;
12+
import org.elasticsearch.client.RequestOptions;
1213
import org.elasticsearch.client.Response;
1314
import org.elasticsearch.client.ResponseException;
1415
import org.elasticsearch.client.RestClient;
16+
import org.elasticsearch.client.WarningsHandler;
1517
import org.elasticsearch.common.settings.SecureString;
1618
import org.elasticsearch.common.settings.Settings;
1719
import org.elasticsearch.common.util.concurrent.ThreadContext;
@@ -56,11 +58,15 @@ protected Settings restClientSettings() {
5658
public void testPermissions() throws IOException {
5759
var putRequest = new Request("PUT", "_inference/sparse_embedding/permissions_test");
5860
putRequest.setJsonEntity(InferenceBaseRestTest.mockSparseServiceModelConfig());
61+
putRequest.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE).build());
62+
// TODO remove permissive handling after the deprecation warning for task_settings is removed in 9.0
5963
var getAllRequest = new Request("GET", "_inference/sparse_embedding/_all");
6064
var deleteRequest = new Request("DELETE", "_inference/sparse_embedding/permissions_test");
6165

6266
var putModelForTestingInference = new Request("PUT", "_inference/sparse_embedding/model_to_test_user_priv");
6367
putModelForTestingInference.setJsonEntity(InferenceBaseRestTest.mockSparseServiceModelConfig());
68+
putModelForTestingInference.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE).build());
69+
// TODO remove permissive handling after the deprecation warning for task_settings is removed in 9.0
6470

6571
var inferRequest = new Request("POST", "_inference/sparse_embedding/model_to_test_user_priv");
6672
var bodyBuilder = new StringBuilder("{\"input\": [");

x-pack/plugin/inference/qa/mixed-cluster/src/javaRestTest/java/org/elasticsearch/xpack/inference/qa/mixed/BaseMixedTestCase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
import org.apache.http.util.EntityUtils;
1111
import org.elasticsearch.client.Request;
12+
import org.elasticsearch.client.RequestOptions;
1213
import org.elasticsearch.client.Response;
14+
import org.elasticsearch.client.WarningsHandler;
1315
import org.elasticsearch.common.Strings;
1416
import org.elasticsearch.common.settings.SecureString;
1517
import org.elasticsearch.common.settings.Settings;
@@ -105,9 +107,9 @@ protected void put(String inferenceId, String modelConfig, TaskType taskType) th
105107
String endpoint = Strings.format("_inference/%s/%s?error_trace", taskType, inferenceId);
106108
var request = new Request("PUT", endpoint);
107109
request.setJsonEntity(modelConfig);
110+
request.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE).build());
111+
// TODO remove permissive handling after the deprecation warning for task_settings is removed in 9.0
108112
var response = ESRestTestCase.client().performRequest(request);
109-
logger.warn("PUT response: {}", response.toString());
110-
System.out.println("PUT response: " + response.toString());
111113
ESRestTestCase.assertOKAndConsume(response);
112114
}
113115

0 commit comments

Comments
 (0)