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

Disallow merging existing mapping field definitions in templates #57701

Merged
merged 6 commits into from
Jun 8, 2020

Conversation

dakrone
Copy link
Member

@dakrone dakrone commented Jun 4, 2020

This commit changes the merge strategy introduced in #55607 and #55982. Instead of overwriting these
fields, we now prevent them from being merged with an exception when a user attempts to
overwrite a field.

As part of this, a more robust validation has been added. The existing validation checked whether
templates (composable and component) were valid on their own, this new validation now checks that
the composite template (mappings/settings/aliases) is valid. This means that when a composable
template is added or updated, we confirm that it is valid with its component pieces. When a
component template is updated we ensure that all composable templates that make use of the component
template continue to be valid before allowing the component template to be updated.

This change also necessitated changes in the tests, however, I have left tests that exercise mapping
merging with nested object fields as @AwaitsFix, as we intend to change the behavior soon to allow
merging in a recursive-with-replacement fashion (see: #57393). I have added tests that check the new
disallowing behavior in the meantime.

This commit changes the merge strategy introduced in elastic#55607 and elastic#55982. Instead of overwriting these
fields, we now prevent them from being merged with an exception when a user attempts to
overwrite a field.

As part of this, a more robust validation has been added. The existing validation checked whether
templates (composable and component) were valid on their own, this new validation now checks that
the composite template (mappings/settings/aliases) is valid. This means that when a composable
template is added or updated, we confirm that it is valid with its component pieces. When a
component template is updated we ensure that all composable templates that make use of the component
template continue to be valid before allowing the component template to be updated.

This change also necessitated changes in the tests, however, I have left tests that exercise mapping
merging with nested object fields as `@AwaitsFix`, as we intend to change the behavior soon to allow
merging in a recursive-with-replacement fashion (see: elastic#57393). I have added tests that check the new
disallowing behavior in the meantime.
@dakrone dakrone added blocker :Data Management/Indices APIs APIs to create and manage indices and templates v8.0.0 v7.8.0 v7.9.0 labels Jun 4, 2020
@dakrone dakrone requested review from andreidan and probakowski June 4, 2020 21:10
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features (:Core/Features/Indices APIs)

@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Jun 4, 2020
Copy link
Contributor

@andreidan andreidan left a comment

Choose a reason for hiding this comment

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

Thanks for working on this Lee! I left a few mostly minor comments

Comment on lines +954 to +959
/**
* Given a state and a composable template, validate that the final composite template
* generated by the composable template and all of its component templates contains valid
* settings, mappings, and aliases.
*/
private static void validateCompositeTemplate(final ClusterState state,
Copy link
Contributor

Choose a reason for hiding this comment

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

the composite term is a bit confusing (at least for me) - we have composable templates so composite template made me think of a possible v3 template of sorts that might combine other templates. Would it make sense to reuse resolve(d) for the final configuration of a composable template? ie. validateResolvedComposableTemplate ? resolveAndValidateComposableTemplate ?

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I dunno, I didn't think they were too different, I wanted to treat "resolved" as pertaining to a particular index, so I think the current name isn't too bad.

@dakrone dakrone requested a review from andreidan June 8, 2020 03:59
Copy link
Contributor

@andreidan andreidan left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for iterating on this Lee

@dakrone
Copy link
Member Author

dakrone commented Jun 8, 2020

@elasticmachine update branch

@dakrone dakrone merged commit c688eb6 into elastic:master Jun 8, 2020
@dakrone dakrone deleted the itv2-validate-composite-templates branch June 8, 2020 14:57
dakrone added a commit to dakrone/elasticsearch that referenced this pull request Jun 8, 2020
…stic#57701)

* Disallow merging existing mapping field definitions in templates

This commit changes the merge strategy introduced in elastic#55607 and elastic#55982. Instead of overwriting these
fields, we now prevent them from being merged with an exception when a user attempts to
overwrite a field.

As part of this, a more robust validation has been added. The existing validation checked whether
templates (composable and component) were valid on their own, this new validation now checks that
the composite template (mappings/settings/aliases) is valid. This means that when a composable
template is added or updated, we confirm that it is valid with its component pieces. When a
component template is updated we ensure that all composable templates that make use of the component
template continue to be valid before allowing the component template to be updated.

This change also necessitated changes in the tests, however, I have left tests that exercise mapping
merging with nested object fields as `@AwaitsFix`, as we intend to change the behavior soon to allow
merging in a recursive-with-replacement fashion (see: elastic#57393). I have added tests that check the new
disallowing behavior in the meantime.

* Use functional instead of imperative prefix collection

* Use IndexService.withTempIndexService

* Rename tests

* Fix tests

Co-authored-by: Elastic Machine <[email protected]>
dakrone added a commit to dakrone/elasticsearch that referenced this pull request Jun 8, 2020
…stic#57701)

* Disallow merging existing mapping field definitions in templates

This commit changes the merge strategy introduced in elastic#55607 and elastic#55982. Instead of overwriting these
fields, we now prevent them from being merged with an exception when a user attempts to
overwrite a field.

As part of this, a more robust validation has been added. The existing validation checked whether
templates (composable and component) were valid on their own, this new validation now checks that
the composite template (mappings/settings/aliases) is valid. This means that when a composable
template is added or updated, we confirm that it is valid with its component pieces. When a
component template is updated we ensure that all composable templates that make use of the component
template continue to be valid before allowing the component template to be updated.

This change also necessitated changes in the tests, however, I have left tests that exercise mapping
merging with nested object fields as `@AwaitsFix`, as we intend to change the behavior soon to allow
merging in a recursive-with-replacement fashion (see: elastic#57393). I have added tests that check the new
disallowing behavior in the meantime.

* Use functional instead of imperative prefix collection

* Use IndexService.withTempIndexService

* Rename tests

* Fix tests

Co-authored-by: Elastic Machine <[email protected]>
dakrone added a commit that referenced this pull request Jun 8, 2020
@jtibshirani
Copy link
Contributor

@dakrone and I discussed offline and determined that we should also throw an error when a metadata key is specified twice (like _source: enabled), and not just keys in the properties block. This will allow us to make changes to the metadata merge semantics in 7.9.

dakrone added a commit to dakrone/elasticsearch that referenced this pull request Jun 8, 2020
In elastic#57701 we changed mappings merging so that duplicate fields specified in mappings caused an
exception during validation. This change makes the same exception thrown when metadata fields are
duplicated. This will allow us to be strict currently with plans to make the merging more
fine-grained in a later release.
dakrone added a commit that referenced this pull request Jun 8, 2020
#57701) (#57822)

Backports the following commits to 7.x:

    Disallow merging existing mapping field definitions in templates (#57701)
dakrone added a commit to dakrone/elasticsearch that referenced this pull request Jun 8, 2020
In elastic#57701 we changed mappings merging so that duplicate fields specified in mappings caused an
exception during validation. This change makes the same exception thrown when metadata fields are
duplicated. This will allow us to be strict currently with plans to make the merging more
fine-grained in a later release.
dakrone added a commit to dakrone/elasticsearch that referenced this pull request Jun 8, 2020
In elastic#57701 we changed mappings merging so that duplicate fields specified in mappings caused an
exception during validation. This change makes the same exception thrown when metadata fields are
duplicated. This will allow us to be strict currently with plans to make the merging more
fine-grained in a later release.
dakrone added a commit that referenced this pull request Jun 8, 2020
…mplates (#57835)

In #57701 we changed mappings merging so that duplicate fields specified in mappings caused an
exception during validation. This change makes the same exception thrown when metadata fields are
duplicated. This will allow us to be strict currently with plans to make the merging more
fine-grained in a later release.
dakrone added a commit that referenced this pull request Jun 8, 2020
In #57701 we changed mappings merging so that duplicate fields specified in mappings caused an
exception during validation. This change makes the same exception thrown when metadata fields are
duplicated. This will allow us to be strict currently with plans to make the merging more
fine-grained in a later release.
dakrone added a commit that referenced this pull request Jun 8, 2020
This is a backport of #57835

In #57701 we changed mappings merging so that duplicate fields specified in mappings caused an
exception during validation. This change makes the same exception thrown when metadata fields are
duplicated. This will allow us to be strict currently with plans to make the merging more
fine-grained in a later release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker :Data Management/Indices APIs APIs to create and manage indices and templates >enhancement Team:Data Management Meta label for data/management team v7.8.0 v7.9.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants