-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add explicit tests for dynamic template validation on bad mapping parameters #74177
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
Add explicit tests for dynamic template validation on bad mapping parameters #74177
Conversation
|
Pinging @elastic/es-search (Team:Search) |
javanna
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.
LGTM
| Map<String, Object> mapping = dynamicTemplate.mappingForName(name, dynamicType); | ||
| if (dynamicTemplate.isRuntimeMapping()) { | ||
| Mapper.TypeParser.ParserContext parserContext = context.parserContext(dateFormatter); | ||
| parserContext = parserContext.createDynamicTemplateFieldContext(parserContext); |
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.
oh boy this is super sneaky. I wonder how we can prevent this from happening again in the long run.
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.
Actually I think ParseContext.parserContext() is only ever called in the context of dynamic fields, so we can probably move this directly into that method. Will give that a go!
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 found the createDynamicTemplateFieldContext more misleading, because it returns again a parser context and it's' very easy to miss.
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 pushed a change which makes it unnecessary - let me know what you think
javanna
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.
thanks for the iteration, I had another question about it.
|
|
||
| ParserContext createDynamicTemplateFieldContext(ParserContext in) { | ||
| return new DynamicTemplateParserContext(in); | ||
| ParserContext createDynamicTemplateFieldContext() { |
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 the only usage of the parser context function? should we change the function argument directly to create the dynamic parser context directly instead of going through a parser context to create another one?
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.
It's also used when validating the templates where we do want to throw an error rather than issuing warnings, so we need to be able to distinguish between the two cases - hence the extra step.
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.
ok :)
…ameters (#74177) When a dynamic template is applied to a 7.x index, we do some validation checks against the generated mappings and issue a deprecation warning if the validation fails. We had some tests that were checking this at a low level, but nothing that exercised the full logic. When dynamic runtimes were added, we expected this behaviour to carry over; however, a bug in building the ParserContext to pass to the runtime Builder meant that we would instead always throw an error. In fact, erroring here is a good result, as the only reason we issue a deprecation warning for non-runtime fields is to preserve backward compatibility; given that runtime fields are new, it has never been possible to add a bad dynamic runtime template. This commit adds specific tests for both situations. It ensures that the parser context passed to a runtime builder will know that it is in a dynamic context, but it also removes the version check and deprecation warning, as they were never actually triggered and we can be stricter here.
DocumentParser takes care of parsing documents and applying dynamic mapping updates for each new field it encounters, if applicable, as well as applying the matching dynamic templates. To do this, it needs to be able to parse mappings, which requires a ParserContext that the ParseContext exposes given a DateFormatter. So far, we have carried around a function that allows to create a new ParserContext given a date formatter, and then call a specific method that allows to wrap it to provide a special parser context that is specific for dynamic templates, which is needed to make some decisions down the line based on whether mappings come from dynamic templates or not. This commit tries to simplify this by exposing the specific dynamic template parser context only to the document parse context, as that's all it needs. We recently ended up using the wrong context and with this change it would not be possible. The function that is passed around is the one that create a DynamicTemplateParserContext, so it cannot be mistaken for the one that creates a generic ParserContext. Relates to elastic#74177
DocumentParser takes care of parsing documents and applying dynamic mapping updates for each new field it encounters, if applicable, as well as applying the matching dynamic templates. To do this, it needs to be able to parse mappings, which requires a ParserContext that the ParseContext exposes given a DateFormatter. So far, we have carried around a function that allows to create a new ParserContext given a date formatter, and then call a specific method that allows to wrap it to provide a special parser context that is specific for dynamic templates, which is needed to make some decisions down the line based on whether mappings come from dynamic templates or not. This commit tries to simplify this by exposing the specific dynamic template parser context only to the document parse context, as that's all it needs. We recently ended up using the wrong context and with this change it would not be possible. Relates to #74177
DocumentParser takes care of parsing documents and applying dynamic mapping updates for each new field it encounters, if applicable, as well as applying the matching dynamic templates. To do this, it needs to be able to parse mappings, which requires a ParserContext that the ParseContext exposes given a DateFormatter. So far, we have carried around a function that allows to create a new ParserContext given a date formatter, and then call a specific method that allows to wrap it to provide a special parser context that is specific for dynamic templates, which is needed to make some decisions down the line based on whether mappings come from dynamic templates or not. This commit tries to simplify this by exposing the specific dynamic template parser context only to the document parse context, as that's all it needs. We recently ended up using the wrong context and with this change it would not be possible. Relates to #74177
When a dynamic template is applied to a 7.x index, we do some validation checks
against the generated mappings and issue a deprecation warning if the validation
fails. We had some tests that were checking this at a low level, but nothing that
exercised the full logic.
When dynamic runtimes were added, we expected this behaviour to carry over;
however, a bug in building the ParserContext to pass to the runtime Builder meant
that we would instead always throw an error. In fact, erroring here is a good result,
as the only reason we issue a deprecation warning for non-runtime fields is to
preserve backward compatibility; given that runtime fields are new, it has never
been possible to add a bad dynamic runtime template.
This commit adds specific tests for both situations. It ensures that the parser
context passed to a runtime builder will know that it is in a dynamic context,
but it also removes the version check and deprecation warning, as they were
never actually triggered and we can be stricter here.