-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[ML] StartTrainedModelDeployment Request query params override body params #109487
Conversation
Pinging @elastic/ml-core (Team:ML) |
Hi @maxhniebergall, I've created a changelog YAML for you. |
docs/changelog/109487.yaml
Outdated
@@ -0,0 +1,5 @@ | |||
pr: 109487 | |||
summary: StartTrainedModelDeployment request query params now override body params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we remove the reference to the class name (users won't know what that means). Maybe something like `Star trained model deployment API requests query params now override body params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Is this considered a breaking change?
No this is bug fix. The option of using providing the params in the body is not documented but people may be relying on it so let's keep it. If it is not too complicated it would be good to check if the params are in both body and query params and error if they are different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max and I talked about this offline but I wanted to make sure I don't forget haha.
If I specify a body setting the cache_size
in serverless, this will result in false
for the block: if (restRequest.hasParam(CACHE_SIZE.getPreferredName())) {
and that means it'll get overridden with a cache size of 0 in serverless.
We'll need to add some logic to check if cache_size
has been specified in the body and not override it in that scenario.
@elasticmachine merge upstream |
…equal to the defaults were not specified in the body. This means that errors will not be thrown if the body and query parameters don't match as long as the body parameter is the same as the default.
…astic/elasticsearch into fixDisableInferenceCacheLogic # Conflicts: # x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartTrainedModelDeploymentAction.java # x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestStartTrainedModelDeploymentAction.java
@elasticmachine merge upstream |
Now, if a parameter is provided in both the query params and body, an exception will be thrown if the parameters are different, unless the parameter provided in the body is the same as the default parameter. |
...ore/src/main/java/org/elasticsearch/xpack/core/ml/inference/assignment/AllocationStatus.java
Outdated
Show resolved
Hide resolved
...plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/assignment/Priority.java
Outdated
Show resolved
Hide resolved
return channel -> client.execute(StartTrainedModelDeploymentAction.INSTANCE, request, new RestToXContentListener<>(channel)); | ||
} | ||
|
||
private Object sameParamInQueryAndBody(Object bodyParam, Object queryParam, Object paramDefault) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know what you think of this: How about we determine which value to use by passing either the already set value from the body (request.get*()
) or if that's null then a default value in the restRequest.param*()
call?
I think that'd look something like this:
var queueCap = request.getQueueCapacity();
request.setQueueCapacity(
restRequest.paramAsInt(QUEUE_CAPACITY.getPreferredName(), Objects.requireNonNullElse(queueCap, StartTrainedModelDeploymentAction.DEFAULT_QUEUE_CAPACITY))
);
That way the query parameter will override the body if it is specified, or we'll take the body value, or if it wasn't set we'll either take the default already set when initializing the StartTrainedModelDeploymentAction.Request
or we'll take the default passed to Objects.requireNonNullElse
.
If I overlooked the logic and we still need this method then here are a few suggestions:
Let's make it static and I think it can be generic so we can remove the need to cast the return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main difference from what you're proposing is that the sameParamInQueryAndBody throws an exception if the body does not match the query param.
Making the function static and generic does make sense though, I can do do that I think.
@elasticmachine merge upstream |
@jonathan-buttner recently discovered an issue with the change I recently made to disable inference cache in serverless where the cache would not be disabled if the
start deployment
request contained a body.This was surprising to me, and upon closer inspection I noticed that there were two parallel paths for parsing the the request, one which used the body and one which used the parameters. This had the effect of ignoring path parameters if a body was included. Additionally, if a body was included, parameters such as
cache_size
would cause errors if a body (including empty body) was included:Now, if a parameter is provided in both the query params and body, an exception will be thrown if the parameters are different, unless the parameter provided in the body is the same as the default parameter.