Skip to content

[8.18] [ML] Adding missing onFailure call for Inference API start model request (#126930) #126941

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
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
5 changes: 5 additions & 0 deletions docs/changelog/126930.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 126930
summary: Adding missing `onFailure` call for Inference API start model request
area: Machine Learning
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void start(Model model, TimeValue timeout, ActionListener<Boolean> finalL
})
.<Boolean>andThen((l2, modelDidPut) -> {
var startRequest = esModel.getStartTrainedModelDeploymentActionRequest(timeout);
var responseListener = esModel.getCreateTrainedModelAssignmentActionListener(model, finalListener);
var responseListener = esModel.getCreateTrainedModelAssignmentActionListener(model, l2);
client.execute(StartTrainedModelDeploymentAction.INSTANCE, startRequest, responseListener);
})
.addListener(finalListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public void onFailure(Exception e) {
&& statusException.getRootCause() instanceof ResourceAlreadyExistsException) {
// Deployment is already started
listener.onResponse(Boolean.TRUE);
} else {
listener.onFailure(e);
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.elasticsearch.inference.ModelConfigurations;
import org.elasticsearch.inference.SimilarityMeasure;
import org.elasticsearch.inference.TaskType;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.ParseField;
Expand All @@ -47,13 +48,16 @@
import org.elasticsearch.xpack.core.inference.results.ChunkedInferenceEmbeddingSparse;
import org.elasticsearch.xpack.core.inference.results.ChunkedInferenceError;
import org.elasticsearch.xpack.core.ml.MachineLearningField;
import org.elasticsearch.xpack.core.ml.action.CreateTrainedModelAssignmentAction;
import org.elasticsearch.xpack.core.ml.action.GetDeploymentStatsAction;
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction;
import org.elasticsearch.xpack.core.ml.action.InferModelAction;
import org.elasticsearch.xpack.core.ml.action.InferTrainedModelDeploymentAction;
import org.elasticsearch.xpack.core.ml.action.PutTrainedModelAction;
import org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction;
import org.elasticsearch.xpack.core.ml.inference.TrainedModelConfig;
import org.elasticsearch.xpack.core.ml.inference.TrainedModelPrefixStrings;
import org.elasticsearch.xpack.core.ml.inference.assignment.AdaptiveAllocationsSettings;
import org.elasticsearch.xpack.core.ml.inference.assignment.AssignmentStats;
import org.elasticsearch.xpack.core.ml.inference.results.ErrorInferenceResults;
import org.elasticsearch.xpack.core.ml.inference.results.MlTextEmbeddingResults;
Expand Down Expand Up @@ -1870,6 +1874,49 @@ public void testUpdateWithMlEnabled() throws IOException, InterruptedException {
}
}

public void testStart_OnFailure_WhenTimeoutOccurs() throws IOException {
var model = new ElserInternalModel(
"inference_id",
TaskType.SPARSE_EMBEDDING,
"elasticsearch",
new ElserInternalServiceSettings(
new ElasticsearchInternalServiceSettings(1, 1, "id", new AdaptiveAllocationsSettings(false, 0, 0), null)
),
new ElserMlNodeTaskSettings(),
null
);

var client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);

doAnswer(invocationOnMock -> {
ActionListener<GetTrainedModelsAction.Response> listener = invocationOnMock.getArgument(2);
var builder = GetTrainedModelsAction.Response.builder();
builder.setModels(List.of(mock(TrainedModelConfig.class)));
builder.setTotalCount(1);

listener.onResponse(builder.build());
return Void.TYPE;
}).when(client).execute(eq(GetTrainedModelsAction.INSTANCE), any(), any());

doAnswer(invocationOnMock -> {
ActionListener<CreateTrainedModelAssignmentAction.Response> listener = invocationOnMock.getArgument(2);
listener.onFailure(new ElasticsearchStatusException("failed", RestStatus.GATEWAY_TIMEOUT));
return Void.TYPE;
}).when(client).execute(eq(StartTrainedModelDeploymentAction.INSTANCE), any(), any());

try (var service = createService(client)) {
var actionListener = new PlainActionFuture<Boolean>();
service.start(model, TimeValue.timeValueSeconds(30), actionListener);
var exception = expectThrows(
ElasticsearchStatusException.class,
() -> actionListener.actionGet(TimeValue.timeValueSeconds(30))
);

assertThat(exception.getMessage(), is("failed"));
}
}

private ElasticsearchInternalService createService(Client client) {
var cs = mock(ClusterService.class);
var cSettings = new ClusterSettings(Settings.EMPTY, Set.of(MachineLearningField.MAX_LAZY_ML_NODES));
Expand Down