-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Collect config for XContentParser #79814
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
Collect config for XContentParser #79814
Conversation
This shifts the internal API for building an `XContentParser` to make maintenance easier. To build an `XContentParser` you need three things: 1. An `XContentType` that knows whether you are reading json, smile, yaml, or cbor 2. Configuration information 3. A place to get the bytes Years ago, there wasn't any configration. But we've since added stuff like `NamedXContentRegistry` and `DeprecationHandler` and `RestApiVersion` and, more lately, filtering configuration. Each time we added one we modified the method signature to add it. Each "place to get the bytes" also needs its own method. All of which are implemented by each `XContentType`. All together we had dozens of these methods for different ways of building parser. All because of the combinatorial explosion of `config x type x source`. This tames the combinatorial explosion somewhat by bundling all of the configuration into an immutable `XContentParserConfiguration`. Sadly, it has to add `createParser` methods that consume the configuration objects. Luckilly, we can remove some of the old methods. We *could* remove all of them, but that'd make this change *huge*. Instead we deprecate the old methods and point them to the new ones.
Pinging @elastic/es-core-infra (Team:Core/Infra) |
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 - great work :)
the only real concern I have is with the PLAIN name
btw we have a similar issue with XContentBuilder constructors :)
@@ -207,7 +215,7 @@ public static void readMultiLineFormat(BytesReference data, | |||
break; | |||
} | |||
// support first line with \n | |||
if (restApiVersion == RestApiVersion.V_7 && nextMarker == 0) { | |||
if (config.restApiVersion() == RestApiVersion.V_7 && nextMarker == 0) { |
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.
might be worth calling it parserConfig
as it is in other places. Not because of consistency, but because I think it reads better
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.
Sure.
public RestApiVersion getRestApiVersion() { | ||
return restApiVersion; | ||
return parserConfig.restApiVersion(); |
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.
just a thought..
restApiVersion is used for both XContentParser
and XContentBuilder
we create a builder with
new XContentBuilder(XContentFactory.xContent(responseContentType), unclosableOutputStream,
includes, excludes, responseMediaType, request.getRestApiVersion());
in AbstractRestChannel
. I wonder if it would be confusing that the version is taken from a request which takes it from parserConfig? Obviously we now know that it only wrapps parameters..
I wonder if maybe for RestRequest
it would make sense to keep the restApiVersion
field together with parserConfig
. Or would it be more complex ?
I am a little biased, because when working on RestApiCompatibility I got used to thinking that RestRequest
keeps the version.
How does this read to you?
tldr ;] I am not convinced myself about this, but might be worth taking a second look at this class
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 it's ok to keep it separate. It'd be worried if they didn't line up but it'd be fine to add an assertion I think.
* Configuration for {@link XContentParser}. | ||
*/ | ||
public class XContentParserConfiguration { | ||
public static final XContentParserConfiguration PLAIN = new XContentParserConfiguration( |
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 DEFAULT? or EMPTY?
PLAIN reminds me of plaint/text
and I think it would be better away from that
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.
That's a pretty compelling reason not to call it PLAIN
. I think EMPTY
is pretty good though. It sort of implies at least a chunk of the configuration it encodes.
@elasticmachine update branch |
In elastic#79814 I deprecated many variants of `XContent#createParser` in favor of some new variants that bundle many of the arguments. This removes one of the deprecated variants by converting all call sites to the new variant.
In elastic#79814 I deprecated many variants of XContent#createParser in favor of some new variants that bundle many of the arguments. This replaces the variants used by the search execution context with the new variants.
In #79814 I deprecated many variants of `XContent#createParser` in favor of some new variants that bundle many of the arguments. This removes one of the deprecated variants by converting all call sites to the new variant.
In elastic#79814 I deprecated many variants of XContent#createParser in favor of some new variants that bundle many of the arguments. This replaces the variants used by the search execution context with the new variants.
This removes one of the `createParser` methods that I deprecated in elastic#79814, migrating callers to one of the new methods that it created.
This removes one of the `createParser` methods that I deprecated in #79814, migrating callers to one of the new methods that it created.
This removes one of the `createParser` methods that I deprecated in elastic#79814, migrating callers to one of the new methods that it created.
This removes many calls to the last remaining `createParser` method that I deprecated in elastic#79814, migrating callers to one of the new methods that it created.
This removes many calls to the last remaining `createParser` method that I deprecated in #79814, migrating callers to one of the new methods that it created.
This shifts the internal API for building an
XContentParser
to makemaintenance easier.
To build an
XContentParser
you need three things:XContentType
that knows whether you are reading json, smile,yaml, or cbor
Years ago, there wasn't any configuration. But we've since added stuff
like
NamedXContentRegistry
andDeprecationHandler
andRestApiVersion
and, more lately, filtering configuration. Each time weadded one we modified the method signature to add it. Each "place to get
the bytes" also needs its own method. All of which are implemented by
each
XContentType
. All together we had dozens of these methods fordifferent ways of building parser. All because of the combinatorial
explosion of
config x type x source
.This tames the combinatorial explosion somewhat by bundling all of the
configuration into an immutable
XContentParserConfiguration
. Sadly, ithas to add
createParser
methods that consume the configuration objects.Luckily, we can remove some of the old methods. We could remove all of
them, but that'd make this change huge. Instead we deprecate the old
methods and point them to the new ones.