-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Begin centralizing XContentParser creation into RestRequest #22041
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
Conversation
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 removed these because they didn't look used and I was breaking backwards compatibility with them anyway....
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'd kind of prefer to drop this in favor of contentOrSourceParamParserOrNull because of the nice dichotomy between it and contentOrSourceParamParser but that'd be a larger.
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've removed contentOrSourceParamParserOrNull and use withContentOrSourceParamParserOrNull everywhere now because closing nullable parsers is fiddly.
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'm not really sure how much I like this. It saves a few lines every time but only a few. If we could entirely replace contentOrSourceParamParserOrNull with this then I'd like it, otherwise I'm tempted to remove this.
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 removed contentOrSourceParamParserOrNull this morning so this comment is now out of date. Ignore please.
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.
Originally I'd exposed this as @Deprecated, that is why the two methods. I feel like it should be deprecated because we want to work with parsers where we can and we're parsing on the coordinating node, but too many APIs use it.
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 eventually we can remove this one as well. Because as a followup to #22003 we'll be able to remove IndicesQueriesRegistry and ParseFieldMatcher is also going to go eventually.
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 moved the try into the calling method so this is mostly indentation changing.
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 feel like I should add more here.
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'm about to push a patch that adds more here.
|
@rjernst, can you have a look at this when you get a chance? This isn't strictly required by #22003 but will make the kind of centralizing of the parser that we'd talked about easier. Or at least more consistent. Ultimately I'd love to never expose a |
|
elasticsearch-ci, retest this please |
rjernst
left a comment
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.
This looks ok to me. I'm not a fan of all the variants of parsing methods on RestRequest, but I realize this is mostly a rote consolidation of all the many ways we already created parsers. But I'm hoping we can continue to improve this to cut down on the different methodologies.
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.
Can you move out the CheckedConsumer I added to ActionListener and reuse 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.
I think so. I'll have a look.
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.
Shouldn't callers call hasContentOrSourceParam() first, so a precondition for this method should be content != null?
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.
This is fairly rarely used so we can do what we like. For the most part they don't but we can certainly force them to.
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'm just removing it.
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.
Is this helper really needed?
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 added it when I thought I could get away with making contentOrSourceParam private or at least deprecated. Now that I've pretty much given up on that we don't need this. In fact I can probably drop contentOrSourceParamXContentType as well under the same logic. Good intentions led to bad results I think.
Right. I think smashing them all into one place will help us to look at them and say "I don't need this one". |
I didn't mean to leave this comment for times.... |
Moves `RestActions.hasBody` to a much more obvious location and method name `RestRequest.hasContentOrSourceParam` and documents when you should use it. This should make is more obvious and is going to go well with subsequent refactorings.
Move `RestActions.guessBodyContentType` to `RestRequest.contentOrSourceParamXContentType` and document that is only useful if you need to do something different if the request is plain text.
`RestActions.getRestContent` is easy to forget to use. This starts to move calls to that method to the more obvious spot `RestRequest.contentOrSourceParamXContentType`. In addition to being a more obvious place this facilites moving most `XContentParser` creation into `RestRequest` which would make future changes much more convenient.
Since it only exists to support deprecated APIs it is deprecated. Prefer `RestRequest.contentOrSourceParamParser`.
This makes it compatible with `RestRequest.contentOrSourceParamParser`.
It has been entirely replaced by `RestRequest.contentOrSourceParamParser` and friends.
Use `withContentOrSourceParamParserOrNull` instead.
I give up on making `RestRequest.contentOrBodyParam` private or deprecated. I just advise folks to use the other methods if you need a parser.
31c13f2 to
c10fb1f
Compare
To get #22003 in cleanly we need to centralize as much `XContentParser` creation as possible into `RestRequest`. That'll mean we have to plumb the `NamedXContentRegistry` into fewer places. This removes `RestAction.hasBody`, `RestAction.guessBodyContentType`, and `RestActions.getRestContent`, moving callers over to `RestRequest.hasContentOrSourceParam`, `RestRequest.contentOrSourceParam`, and `RestRequest.contentOrSourceParamParser` and `RestRequest.withContentOrSourceParamParserOrNull`. The idea is to use `withContentOrSourceParamParserOrNull` if you need to handle requests without any sort of body content and to use `contentOrSourceParamParser` otherwise. I believe the vast majority of this PR to be purely mechanical but I know I've made the following behavioral change (I'll add more if I think of more): * If you make a request to an endpoint that requires a request body and has cut over to the new APIs instead of getting `Failed to derive xcontent` you'll get `Body required`. * Template parsing is now non-strict by default. This is important because we need to be able to deprecate things without requests failing.
To get #22003 in cleanly we need to centralize as much
XContentParsercreation as possible intoRestRequest. That'll mean we have to plumb theNamedXContentRegistryinto fewer places.This removes
RestAction.hasBody,RestAction.guessBodyContentType, andRestActions.getRestContent, moving callers over toRestRequest.hasContentOrSourceParam,RestRequest.contentOrSourceParam, andRestRequest.contentOrSourceParamParserandRestRequest.withContentOrSourceParamParserOrNull. The idea is to usewithContentOrSourceParamParserOrNullif you need to handle requests without any sort of body content and to usecontentOrSourceParamParserotherwise.I believe the vast majority of this PR to be purely mechanical but I know I've made the following behavioral change (I'll add more if I think of more):
Failed to derive xcontentyou'll getBody required.