Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -351,6 +351,7 @@ static TransportVersion def(int id) {
public static final TransportVersion SHARD_WRITE_LOAD_IN_CLUSTER_INFO = def(9_126_0_00);
public static final TransportVersion ESQL_SAMPLE_OPERATOR_STATUS = def(9_127_0_00);
public static final TransportVersion ESQL_TOPN_TIMINGS = def(9_128_0_00);
public static final TransportVersion INFERENCE_UPDATE_ML = def(9_129_0_00);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.util.Objects;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing a bit of context: why do we need to distinguish between these cases?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a corresponding Serverless PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let me ping you with the internal documentation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing a bit of context: why do we need to distinguish between these cases?

We need to allow updates to num_allocations in serverless that originate from the AdaptiveAllocationsScalerService (ADAPTIVE_ALLOCATIONS), but we want to disallow updates from users (API and INFERENCE). The only alternative I thought of was refactoring AdaptiveAllocationsScalerService to update directly rather than through the API, but that felt more intrusive.


import static org.elasticsearch.TransportVersions.INFERENCE_UPDATE_ML;
import static org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction.Request.ADAPTIVE_ALLOCATIONS;
import static org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction.Request.MODEL_ID;
import static org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction.Request.NUMBER_OF_ALLOCATIONS;
Expand Down Expand Up @@ -74,6 +75,7 @@ public static Request parseRequest(String deploymentId, XContentParser parser) {
private Integer numberOfAllocations;
private AdaptiveAllocationsSettings adaptiveAllocationsSettings;
private boolean isInternal;
private boolean fromInference;

private Request() {
super(TRAPPY_IMPLICIT_DEFAULT_MASTER_NODE_TIMEOUT, DEFAULT_ACK_TIMEOUT);
Expand All @@ -96,6 +98,7 @@ public Request(StreamInput in) throws IOException {
adaptiveAllocationsSettings = in.readOptionalWriteable(AdaptiveAllocationsSettings::new);
isInternal = in.readBoolean();
}
fromInference = in.getTransportVersion().onOrAfter(INFERENCE_UPDATE_ML) && in.readBoolean();
}

public final void setDeploymentId(String deploymentId) {
Expand Down Expand Up @@ -126,6 +129,15 @@ public void setIsInternal(boolean isInternal) {
this.isInternal = isInternal;
}

public boolean fromInference() {
return fromInference;
}

public void setFromInference(boolean fromInference) {
this.fromInference = fromInference;
this.isInternal = fromInference;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks confusing the setFromInference also sets isInternal.

}

public AdaptiveAllocationsSettings getAdaptiveAllocationsSettings() {
return adaptiveAllocationsSettings;
}
Expand All @@ -141,6 +153,9 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalWriteable(adaptiveAllocationsSettings);
out.writeBoolean(isInternal);
}
if (out.getTransportVersion().onOrAfter(INFERENCE_UPDATE_ML)) {
out.writeBoolean(fromInference);
}
}

@Override
Expand Down Expand Up @@ -183,7 +198,7 @@ public ActionRequestValidationException validate() {

@Override
public int hashCode() {
return Objects.hash(deploymentId, numberOfAllocations, adaptiveAllocationsSettings, isInternal);
return Objects.hash(deploymentId, numberOfAllocations, adaptiveAllocationsSettings, isInternal, fromInference);
}

@Override
Expand All @@ -198,7 +213,8 @@ public boolean equals(Object obj) {
return Objects.equals(deploymentId, other.deploymentId)
&& Objects.equals(numberOfAllocations, other.numberOfAllocations)
&& Objects.equals(adaptiveAllocationsSettings, other.adaptiveAllocationsSettings)
&& isInternal == other.isInternal;
&& isInternal == other.isInternal
&& fromInference == other.fromInference;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private void updateInClusterEndpoint(
var updateRequest = new UpdateTrainedModelDeploymentAction.Request(deploymentId);
updateRequest.setNumberOfAllocations(elasticServiceSettings.getNumAllocations());
updateRequest.setAdaptiveAllocationsSettings(elasticServiceSettings.getAdaptiveAllocationsSettings());
updateRequest.setIsInternal(true);
updateRequest.setFromInference(true);

var delegate = listener.<CreateTrainedModelAssignmentAction.Response>delegateFailure((l2, response) -> {
modelRegistry.updateModelTransaction(newModel, existingParsedModel, l2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
model_id: "missing-model"
body: >
{
"number_of_allocations": 4
"adaptive_allocations": {
"enabled": true,
"min_number_of_allocations": 0,
"max_number_of_allocations": 1
}
}