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

Support specifying multiple templates names in delete composable index template api #70094

Conversation

martijnvg
Copy link
Member

Add support to delete composable index templates api to specify multiple template
names separated by a comma.

Change to cleanup template logic for rest tests to remove all composable index templates via a single delete composable index template request. This to optimize the cleanup logic. After each rest test we delete all templates. So deleting templates this via a single api call (and thus single cluster state update) saves a lot of time considering the number of rest tests.

If this pr is accepted then I will do the same change for the delete component template api.

Relates to #69973

…x template api.

Add support to delete composable index templates api to specify multiple template
names separated by a comma.

Change to cleanup template logic for rest tests to remove all composable index templates via a single delete composable index template request. This to optimize the cleanup logic. After each rest test we delete all templates. So deleting templates this via a single api call (and thus single cluster state update) saves a lot of time considering the number of rest tests.

If this pr is accepted then I will do the same change for the delete component template api.

Relates to elastic#69973
@martijnvg martijnvg added >enhancement :Data Management/Indices APIs APIs to create and manage indices and templates v8.0.0 v7.13.0 labels Mar 8, 2021
@martijnvg martijnvg requested review from dakrone and jakelandis March 8, 2021 15:58
@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Mar 8, 2021
@elasticmachine
Copy link
Collaborator

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

@@ -641,8 +641,10 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
static ClusterState innerRemoveIndexTemplateV2(ClusterState currentState, String name) {
Copy link
Member Author

@martijnvg martijnvg Mar 8, 2021

Choose a reason for hiding this comment

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

The name should be a string[], and also the name field on request class. Otherwise the request can't be introspected correctly by security.

@@ -575,18 +575,14 @@ private void wipeCluster() throws Exception {
Request getTemplatesRequest = new Request("GET", "_index_template");
Map<String, Object> composableIndexTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent,
EntityUtils.toString(adminClient().performRequest(getTemplatesRequest).getEntity()), false);
List<String> names = ((List<?>) composableIndexTemplates.get("index_templates")).stream()
String names = ((List<?>) composableIndexTemplates.get("index_templates")).stream()
Copy link
Member Author

Choose a reason for hiding this comment

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

and obviously bwc logic is needed...

@martijnvg martijnvg marked this pull request as draft March 8, 2021 16:45
@dakrone
Copy link
Member

dakrone commented Mar 8, 2021

I think we may want to reconsider supporting wildcards if we want to support comma-separated values. We already have strangeness with response codes when you mix concrete names with a *, for example, DELETE /_index_template/* already doesn't return an error if there are no matching templates, but what about DELETE /_index_template/foo,*? or DELETE /_index_template/foo,bar-*,*?

At some point it becomes very hard to describe to the user whether we did the thing they asked for when we can't be fine-grained in our response. Because we have some issues with this in other APIs, we originally didn't add this for the composable index templates.

@martijnvg
Copy link
Member Author

I'm not a big fan of adding support for comma-separated values too. I just like to remove all templates in a single request (cluster state update) just for reducing the time it takes to run the tests.

So currently these delete APIs already support simple wildcards. However the xpack templates we need to exclude have many different names and are not sharing a common prefix (See ESRestTestCase#isXPackTemplate). Also simple wildcard matching is not enough and we need some kind of negation, because we need exclude pattern like: -ilm-history,-.*,-metrics*,-logs*,-synthetics*,-security_audit_log,-saml-service-provider. In order exclude these pattern, multiple expressions still need to be provided.

I'm not sure what is best here. Looks like our testing infrastructure does benefit from being able to remove all templates besides the templates managed by ES. Perhaps if comma-separated values are provided then we should prohibit the use of *?

@dakrone
Copy link
Member

dakrone commented Mar 8, 2021

Perhaps if comma-separated values are provided then we should prohibit the use of *?

I think we could do:

  • if * is specified, delete all templates (no error)
  • if foo-* is specified, delete everything starting with foo
  • if foo,bar,baz are specified, delete those three templates exactly, don't support wildcards, throw an error if any of the three don't exist.

What do you think?

@martijnvg
Copy link
Member Author

👍 that proposal sounds good to me.

@martijnvg martijnvg marked this pull request as ready for review March 9, 2021 09:54
@martijnvg
Copy link
Member Author

@dakrone Do you want to take another look at this PR?

@dakrone
Copy link
Member

dakrone commented Mar 10, 2021

@martijnvg yep, I will look at it today.

Copy link
Member

@dakrone dakrone 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 Martijn! I left one really minor comment

this.name = name;
return this;
public Request(String... names) {
this.names = names;
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit, can you do something like:

Suggested change
this.names = names;
this.names = Objects.requireNonNull(names, "templates to delete must not be null");

martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Mar 11, 2021
…x template api

Backporting elastic#70094 to 7.12 branch.

Add support to delete composable index templates api to specify multiple template
names separated by a comma.

Change to cleanup template logic for rest tests to remove all composable index templates via a single delete composable index template request. This to optimize the cleanup logic. After each rest test we delete all templates. So deleting templates this via a single api call (and thus single cluster state update) saves a lot of time considering the number of rest tests.

Relates to elastic#69973
probakowski pushed a commit to probakowski/elasticsearch that referenced this pull request Mar 15, 2021
…x template api (elastic#70094)

Add support to delete composable index templates api to specify multiple template
names separated by a comma.

Change to cleanup template logic for rest tests to remove all composable index templates via a single delete composable index template request. This to optimize the cleanup logic. After each rest test we delete all templates. So deleting templates this via a single api call (and thus single cluster state update) saves a lot of time considering the number of rest tests.

If this pr is accepted then I will do the same change for the delete component template api.

Relates to elastic#69973
probakowski pushed a commit to probakowski/elasticsearch that referenced this pull request Mar 15, 2021
martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Mar 16, 2021
martijnvg added a commit that referenced this pull request Mar 16, 2021
martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Mar 16, 2021
martijnvg added a commit that referenced this pull request Mar 16, 2021
martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Mar 22, 2021
… APIs is not supported.

The delete legacy template API doesn't support comma-separated list of names in any version.

For versions 7.12 and before, the delete component API and delete composable index template API
don't support comma-separated list of names.

From 7.13 and later, the delete component API and delete composable index template API do support
comma-separated list of names.

Relates to elastic#70094 and elastic#70314
martijnvg added a commit that referenced this pull request Mar 24, 2021
… APIs is not supported (#70649)

The delete legacy template API doesn't support comma-separated list of names in any version.

For versions 7.12 and before, the delete component API and delete composable index template API
don't support comma-separated list of names.

From 7.13 and later, the delete component API and delete composable index template API do support
comma-separated list of names.

Relates to #70094 and #70314

Co-authored-by: James Rodewig <[email protected]>
martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Mar 24, 2021
… APIs is not supported (elastic#70649)

The delete legacy template API doesn't support comma-separated list of names in any version.

For versions 7.12 and before, the delete component API and delete composable index template API
don't support comma-separated list of names.

From 7.13 and later, the delete component API and delete composable index template API do support
comma-separated list of names.

Relates to elastic#70094 and elastic#70314

Co-authored-by: James Rodewig <[email protected]>
martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Mar 24, 2021
… APIs is not supported (elastic#70649)

The delete legacy template API doesn't support comma-separated list of names in any version.

For versions 7.12 and before, the delete component API and delete composable index template API
don't support comma-separated list of names.

From 7.13 and later, the delete component API and delete composable index template API do support
comma-separated list of names.

Relates to elastic#70094 and elastic#70314

Co-authored-by: James Rodewig <[email protected]>
martijnvg added a commit that referenced this pull request Mar 24, 2021
… APIs is not supported (#70797)

Backporting #70649 to 7.11 branch.

The delete legacy template API doesn't support comma-separated list of names in any version.

For versions 7.12 and before, the delete component API and delete composable index template API
don't support comma-separated list of names.

From 7.13 and later, the delete component API and delete composable index template API do support
comma-separated list of names.

Relates to #70094 and #70314

Co-authored-by: James Rodewig <[email protected]>
martijnvg added a commit that referenced this pull request Mar 24, 2021
… APIs is not supported (#70799)

Backporting #70649 to 7.10 branch.

The delete legacy template API doesn't support comma-separated list of names in any version.

For versions 7.12 and before, the delete component API and delete composable index template API
don't support comma-separated list of names.

From 7.13 and later, the delete component API and delete composable index template API do support
comma-separated list of names.

Relates to #70094 and #70314

Co-authored-by: James Rodewig <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Indices APIs APIs to create and manage indices and templates >enhancement Team:Data Management Meta label for data/management team v7.13.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants