Skip to content

[ML] Remove deprecated routes for ml trained models APIs #124019

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

Merged
merged 5 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@
"required":false,
"description":"A comma-separate list of fields to optionally include. Valid options are 'definition' and 'total_feature_importance'. Default is none."
},
"include_model_definition":{
"type":"boolean",
"required":false,
"description":"Should the full model definition be included in the results. These definitions can be large. So be cautious when including them. Defaults to false.",
"default":false,
"deprecated": true
},
"decompress_definition":{
"type":"boolean",
"required":false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,6 @@
"required":true
}
}
},
{
"path":"/_ml/trained_models/{model_id}/deployment/_infer",
"methods":[
"POST"
],
"parts":{
"model_id":{
"type":"string",
"description":"The unique identifier of the trained model.",
"required":true
}
},
"deprecated": {
"version":"8.3.0",
"description": "/_ml/trained_models/{model_id}/deployment/_infer is deprecated. Use /_ml/trained_models/{model_id}/_infer instead"
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
"required":false,
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)"
},
"allow_no_datafeeds":{
"type":"boolean",
"required":false,
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)",
"deprecated":true
},
"force":{
"type":"boolean",
"required":false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,6 @@ public void testInferWithMultipleDocs() throws IOException {
assertArrayEquals(expectedEmbeddings.get(i).toArray(), embedding.toArray());
}
}
{
// the deprecated deployment/_infer endpoint does not support multiple docs
Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/deployment/_infer");
request.setJsonEntity(String.format(Locale.ROOT, """
{ "docs": [%s] }
""", docsBuilder));
Exception ex = expectThrows(Exception.class, () -> client().performRequest(request));
assertThat(ex.getMessage(), containsString("multiple documents are not supported"));
}
}

public void testGetPytorchModelWithDefinition() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@
import org.elasticsearch.xpack.ml.rest.inference.RestGetTrainedModelsAction;
import org.elasticsearch.xpack.ml.rest.inference.RestGetTrainedModelsStatsAction;
import org.elasticsearch.xpack.ml.rest.inference.RestInferTrainedModelAction;
import org.elasticsearch.xpack.ml.rest.inference.RestInferTrainedModelDeploymentAction;
import org.elasticsearch.xpack.ml.rest.inference.RestPutTrainedModelAction;
import org.elasticsearch.xpack.ml.rest.inference.RestPutTrainedModelAliasAction;
import org.elasticsearch.xpack.ml.rest.inference.RestPutTrainedModelDefinitionPartAction;
Expand Down Expand Up @@ -1503,7 +1502,6 @@ public List<RestHandler> getRestHandlers(
if (machineLearningExtension.get().isNlpEnabled()) {
restHandlers.add(new RestStartTrainedModelDeploymentAction(machineLearningExtension.get().disableInferenceProcessCache()));
restHandlers.add(new RestStopTrainedModelDeploymentAction());
restHandlers.add(new RestInferTrainedModelDeploymentAction());
restHandlers.add(new RestUpdateTrainedModelDeploymentAction());
restHandlers.add(new RestPutTrainedModelVocabularyAction());
restHandlers.add(new RestClearDeploymentCacheAction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.injection.guice.Inject;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
Expand Down Expand Up @@ -87,7 +85,6 @@ protected CacheInfo nodeOperation(NodeModelCacheInfoRequest nodeModelCacheInfoRe
);
}

@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) // this can be replaced with TransportRequest.Empty in v9
public static class NodeModelCacheInfoRequest extends TransportRequest {

NodeModelCacheInfoRequest() {}
Expand All @@ -100,10 +97,5 @@ public NodeModelCacheInfoRequest(StreamInput in) throws IOException {
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) {
return new CancellableTask(id, type, action, "", parentTaskId, headers);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.Scope;
Expand All @@ -28,22 +27,9 @@
@ServerlessScope(Scope.PUBLIC)
public class RestDeleteTrainedModelAction extends BaseRestHandler {

@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING)
// one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access
// that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will
// continue to emit deprecations warnings but will not require any special headers to access the API in v9.
// Please review and update the code and tests as needed. The original code remains commented out below for reference.
@Override
public List<Route> routes() {
return List.of(
// Route.builder(DELETE, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}")
// .replaces(DELETE, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}", RestApiVersion.V_8)
// .build()
new Route(DELETE, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"),
Route.builder(DELETE, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}")
.deprecateAndKeep("Use the trained_models API instead.")
.build()
);
return List.of(new Route(DELETE, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestRequest;
Expand All @@ -38,35 +35,18 @@

import static java.util.Arrays.asList;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Includes.DEFINITION;
import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Request.ALLOW_NO_MATCH;
import static org.elasticsearch.xpack.core.ml.utils.ToXContentParams.EXCLUDE_GENERATED;
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;

@ServerlessScope(Scope.PUBLIC)
public class RestGetTrainedModelsAction extends BaseRestHandler {

private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestGetTrainedModelsAction.class);
private static final String INCLUDE_MODEL_DEFINITION = "include_model_definition";

@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING)
// one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access
// that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will
// continue to emit deprecations warnings but will not require any special headers to access the API in v9.
// Please review and update the code and tests as needed. The original code remains commented out below for reference.
@Override
public List<Route> routes() {
return List.of(
// Route.builder(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}")
// .replaces(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}", RestApiVersion.V_8)
// .build(),
// Route.builder(GET, BASE_PATH + "trained_models").replaces(GET, BASE_PATH + "inference", RestApiVersion.V_8).build()
new Route(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"),
Route.builder(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}")
.deprecateAndKeep("Use the trained_models API instead.")
.build(),
new Route(GET, BASE_PATH + "trained_models"),
Route.builder(GET, BASE_PATH + "inference").deprecateAndKeep("Use the trained_models API instead.").build()
new Route(GET, BASE_PATH + "trained_models")
);
}

Expand All @@ -90,22 +70,9 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
Set<String> includes = new HashSet<>(
asList(restRequest.paramAsStringArray(GetTrainedModelsAction.Request.INCLUDE.getPreferredName(), Strings.EMPTY_ARRAY))
);
final GetTrainedModelsAction.Request request;
if (restRequest.hasParam(INCLUDE_MODEL_DEFINITION)) {
deprecationLogger.warn(
DeprecationCategory.API,
INCLUDE_MODEL_DEFINITION,
"[{}] parameter is deprecated! Use [include=definition] instead.",
INCLUDE_MODEL_DEFINITION
);
request = new GetTrainedModelsAction.Request(
modelId,
tags,
restRequest.paramAsBoolean(INCLUDE_MODEL_DEFINITION, false) ? Set.of(DEFINITION) : Set.of()
);
} else {
request = new GetTrainedModelsAction.Request(modelId, tags, includes);
}

final GetTrainedModelsAction.Request request = new GetTrainedModelsAction.Request(modelId, tags, includes);

if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) {
request.setPageParams(
new PageParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.core.UpdateForV9;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.Scope;
Expand All @@ -30,26 +29,11 @@
@ServerlessScope(Scope.PUBLIC)
public class RestGetTrainedModelsStatsAction extends BaseRestHandler {

@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING)
// one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access
// that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will
// continue to emit deprecations warnings but will not require any special headers to access the API in v9.
// Please review and update the code and tests as needed. The original code remains commented out below for reference.
@Override
public List<Route> routes() {
return List.of(
// Route.builder(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}/_stats")
// .replaces(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}/_stats", RestApiVersion.V_8)
// .build(),
// Route.builder(GET, BASE_PATH + "trained_models/_stats")
// .replaces(GET, BASE_PATH + "inference/_stats", RestApiVersion.V_8)
// .build()
new Route(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}/_stats"),
Route.builder(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}/_stats")
.deprecateAndKeep("Use the trained_models API instead.")
.build(),
new Route(GET, BASE_PATH + "trained_models/_stats"),
Route.builder(GET, BASE_PATH + "inference/_stats").deprecateAndKeep("Use the trained_models API instead.").build()
new Route(GET, BASE_PATH + "trained_models/_stats")
);
}

Expand Down

This file was deleted.

Loading