Skip to content

Commit b2ab9df

Browse files
authored
[ML] Fix timeout attaching to missing deployment (#115517)
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 d5265be commit b2ab9df

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
@@ -34,7 +34,6 @@
3434
import org.elasticsearch.xpack.core.inference.results.SparseEmbeddingResults;
3535
import org.elasticsearch.xpack.core.ml.action.GetDeploymentStatsAction;
3636
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction;
37-
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsStatsAction;
3837
import org.elasticsearch.xpack.core.ml.action.InferModelAction;
3938
import org.elasticsearch.xpack.core.ml.inference.assignment.AdaptiveAllocationsSettings;
4039
import org.elasticsearch.xpack.core.ml.inference.assignment.AssignmentStats;
@@ -913,7 +912,7 @@ private void validateAgainstDeployment(
913912
listener.onFailure(
914913
new ElasticsearchStatusException(
915914
"Deployment [{}] uses model [{}] which does not match the model [{}] in the request.",
916-
RestStatus.BAD_REQUEST, // TODO better message
915+
RestStatus.BAD_REQUEST,
917916
deploymentId,
918917
response.get().getModelId(),
919918
modelId
@@ -933,21 +932,22 @@ private void validateAgainstDeployment(
933932
checkTaskTypeForMlNodeModel(response.get().getModelId(), taskType, l.delegateFailureAndWrap((l2, compatibleTaskType) -> {
934933
l2.onResponse(updatedSettings);
935934
}));
935+
} else {
936+
listener.onFailure(new ElasticsearchStatusException("Cannot find deployment [{}]", RestStatus.NOT_FOUND, deploymentId));
936937
}
937938
}));
938939
}
939940

940941
private void getDeployment(String deploymentId, ActionListener<Optional<AssignmentStats>> listener) {
941942
client.execute(
942-
GetTrainedModelsStatsAction.INSTANCE,
943-
new GetTrainedModelsStatsAction.Request(deploymentId),
943+
GetDeploymentStatsAction.INSTANCE,
944+
new GetDeploymentStatsAction.Request(deploymentId),
944945
listener.delegateFailureAndWrap((l, response) -> {
945946
l.onResponse(
946-
response.getResources()
947+
response.getStats()
947948
.results()
948949
.stream()
949-
.filter(s -> s.getDeploymentStats() != null && s.getDeploymentStats().getDeploymentId().equals(deploymentId))
950-
.map(GetTrainedModelsStatsAction.Response.TrainedModelStats::getDeploymentStats)
950+
.filter(s -> s.getDeploymentId() != null && s.getDeploymentId().equals(deploymentId))
951951
.findFirst()
952952
);
953953
})

0 commit comments

Comments
 (0)