Skip to content
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

Distinguish Negotiated vs Default Rest API Version #98121

Merged
merged 5 commits into from
Aug 10, 2023

Conversation

tvernum
Copy link
Contributor

@tvernum tvernum commented Aug 2, 2023

This commit changes the RestApiVersion parsing code to return an Optional so that the RestRequest can distinguish between reqeust that included an explicit API version, and requests that should use the server's default version.

This is needed because "compatible-with=8" will have a specific meaning on serverless that is not the same as the default API behaviour.

This commit changes the RestApiVersion parsing code to return an
Optional<RestApiVersion> so that the RestRequest can distinguish
between reqeust that included an explicit API version, and requests
that should use the server's default version.

This is needed because "compatible-with=8" will have a specific
meaning on serverless that is not the same as the default API
behaviour.
@tvernum tvernum added the :Core/Infra/REST API REST infrastructure and utilities label Aug 2, 2023
@tvernum
Copy link
Contributor Author

tvernum commented Aug 4, 2023

@elasticmachine update branch

@tvernum tvernum requested review from jakelandis and pgomulka August 4, 2023 02:41
@tvernum tvernum marked this pull request as ready for review August 4, 2023 02:44
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Aug 4, 2023
@tvernum
Copy link
Contributor Author

tvernum commented Aug 4, 2023

This is a first step towards having API version negotiation in serverless.

In Serverless we want:

  • compatible-with=8 to be respected if specified
  • A new Elastic-Api-Version header to be respected if specified
  • Reject request that include both compatible-with and Elastic-Api-Version
  • Default to the latest Elastic-Api-Version if neither are specified

To do that we need to keep the "compatible-with" parsing code in place, but distinguish be able to tell whether the parameter was specified or not.

Copy link
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -62,7 +63,7 @@ public class RestRequest implements ToXContent.Params {
private final HttpChannel httpChannel;
private final ParsedMediaType parsedAccept;
private final ParsedMediaType parsedContentType;
private final RestApiVersion restApiVersion;
private final Optional<RestApiVersion> restApiVersion;
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 reason why this is kept as an optional field, and we do a orElse(RestApiVersion.current()); every time? Can RestApiVersion.current() change, or could we resolve this at construction time and avoid the Optional field?

Copy link
Contributor Author

@tvernum tvernum Aug 8, 2023

Choose a reason for hiding this comment

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

Technically we can replace it with a nullable field instead of an Optional.

I didn't do that because I appreciate the support that the compiler provides in avoiding accidental access to a potentially null value, but preferences will vary.

Or alternatively 2 fields (RestApiVersion and boolean) that effectively replicate the behaviour of an Optional (but resolve the orElse at construction time)

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about the 2 fields, but the difference is indeed minimal and I think a matter of preference. Thanks for looking into this though!

@tvernum
Copy link
Contributor Author

tvernum commented Aug 9, 2023

@elasticmachine update branch

@tvernum tvernum added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Aug 9, 2023
@tvernum
Copy link
Contributor Author

tvernum commented Aug 9, 2023

@elasticmachine run elasticsearch-ci/part-1 please

Failed to fetch https://esm.ubuntu.com/ubuntu/dists/trusty-infra-updates/main/binary-amd64/Packages  HttpError503

😿

@tvernum
Copy link
Contributor Author

tvernum commented Aug 10, 2023

@elasticmachine update branch

@elasticsearchmachine elasticsearchmachine merged commit 6269744 into elastic:main Aug 10, 2023
@tvernum tvernum deleted the serverless-api-version branch August 10, 2023 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Core/Infra/REST API REST infrastructure and utilities >non-issue Team:Core/Infra Meta label for core/infra team v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants