Skip to content

Commit b8b97a6

Browse files
authored
[ML] Fix timeout attaching to missing deployment (#115517) (#115603)
Fixes a timeout in the Inference API where if connecting to an existing deployment and that deployment does not exist the listener was not called.
1 parent c5994c9 commit b8b97a6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ public void testModelIdDoesNotMatch() throws IOException {
109109
);
110110
}
111111

112+
public void testDeploymentDoesNotExist() {
113+
var deploymentId = "missing_deployment";
114+
115+
var inferenceId = "inference_on_missing_deployment";
116+
var e = expectThrows(ResponseException.class, () -> putModel(inferenceId, endpointConfig(deploymentId), TaskType.SPARSE_EMBEDDING));
117+
assertThat(e.getMessage(), containsString("Cannot find deployment [missing_deployment]"));
118+
}
119+
112120
public void testNumAllocationsIsUpdated() throws IOException {
113121
var modelId = "update_num_allocations";
114122
var deploymentId = modelId;

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.elasticsearch.xpack.core.inference.results.SparseEmbeddingResults;
3434
import org.elasticsearch.xpack.core.ml.action.GetDeploymentStatsAction;
3535
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction;
36-
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsStatsAction;
3736
import org.elasticsearch.xpack.core.ml.action.InferModelAction;
3837
import org.elasticsearch.xpack.core.ml.inference.assignment.AdaptiveAllocationsSettings;
3938
import org.elasticsearch.xpack.core.ml.inference.assignment.AssignmentStats;
@@ -898,7 +897,7 @@ private void validateAgainstDeployment(
898897
listener.onFailure(
899898
new ElasticsearchStatusException(
900899
"Deployment [{}] uses model [{}] which does not match the model [{}] in the request.",
901-
RestStatus.BAD_REQUEST, // TODO better message
900+
RestStatus.BAD_REQUEST,
902901
deploymentId,
903902
response.get().getModelId(),
904903
modelId
@@ -918,21 +917,22 @@ private void validateAgainstDeployment(
918917
checkTaskTypeForMlNodeModel(response.get().getModelId(), taskType, l.delegateFailureAndWrap((l2, compatibleTaskType) -> {
919918
l2.onResponse(updatedSettings);
920919
}));
920+
} else {
921+
listener.onFailure(new ElasticsearchStatusException("Cannot find deployment [{}]", RestStatus.NOT_FOUND, deploymentId));
921922
}
922923
}));
923924
}
924925

925926
private void getDeployment(String deploymentId, ActionListener<Optional<AssignmentStats>> listener) {
926927
client.execute(
927-
GetTrainedModelsStatsAction.INSTANCE,
928-
new GetTrainedModelsStatsAction.Request(deploymentId),
928+
GetDeploymentStatsAction.INSTANCE,
929+
new GetDeploymentStatsAction.Request(deploymentId),
929930
listener.delegateFailureAndWrap((l, response) -> {
930931
l.onResponse(
931-
response.getResources()
932+
response.getStats()
932933
.results()
933934
.stream()
934-
.filter(s -> s.getDeploymentStats() != null && s.getDeploymentStats().getDeploymentId().equals(deploymentId))
935-
.map(GetTrainedModelsStatsAction.Response.TrainedModelStats::getDeploymentStats)
935+
.filter(s -> s.getDeploymentId() != null && s.getDeploymentId().equals(deploymentId))
936936
.findFirst()
937937
);
938938
})

0 commit comments

Comments
 (0)