Skip to content

Operator/index templates#90143

Merged
grcevski merged 14 commits intoelastic:mainfrom
grcevski:operator/index_templates
Oct 14, 2022
Merged

Operator/index templates#90143
grcevski merged 14 commits intoelastic:mainfrom
grcevski:operator/index_templates

Conversation

@grcevski
Copy link
Copy Markdown
Contributor

This PR adds support for /_index_template/ and /_component_template/ in file based settings.

Relates to #89183

@grcevski grcevski added >enhancement :Core/Infra/Core Core issues without another label Team:Core/Infra Meta label for core/infra team Team:Data Management (obsolete) DO NOT USE. This team no longer exists. v8.5.0 labels Sep 19, 2022
@elasticsearchmachine elasticsearchmachine removed the Team:Data Management (obsolete) DO NOT USE. This team no longer exists. label Sep 19, 2022
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @grcevski, I've created a changelog YAML for you.

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@grcevski grcevski requested a review from dakrone September 20, 2022 13:51
@csoulios csoulios added v8.6.0 and removed v8.5.0 labels Sep 21, 2022
@dakrone dakrone requested a review from andreidan October 6, 2022 15:32
Copy link
Copy Markdown
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 Nikola

This looks great, I've left a few very minor suggestions

Comment on lines +35 to +45
/**
* This {@link ReservedClusterStateHandler} is responsible for reserved state
* CRUD operations on composable index templates and component templates, e.g. file based settings.
* <p>
* Internally it uses {@link MetadataIndexTemplateService} to add, update and delete both composable
* index templates and component templates. The reserved state handler is implemented as a joint handler
* for both component templates and composable index templates, because of the inherent interdependencies
* of the two separate types. For example, one cannot create composable index templates without first the
* component definitions being in the cluster state, however, the opposite is true when deleting. This
* circular dependency makes it impossible for separation of the two handlers.
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is awesome ❤️

Comment on lines +71 to +87
public static String componentName(String name) {
return COMPONENT_PREFIX + name;
}

public static String nameFromComponentName(String name) {
assert name.startsWith(COMPONENT_PREFIX);
return name.substring(COMPONENT_PREFIX.length());
}

public static String composableIndexName(String name) {
return COMPOSABLE_PREFIX + name;
}

public static String nameFromComposableIndexName(String name) {
assert name.startsWith(COMPOSABLE_PREFIX);
return name.substring(COMPOSABLE_PREFIX.length());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we maybe document the purpose of these prefixes? It was a bit trappy for me to identify why we do this PREFIX concatenation and parsing.

Maybe componentName can become reservedComponentName ? And nameFromComponentName -> componentNameFromReservedName? (or something along those lines)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

return ClusterState.builder(currentState).metadata(Metadata.builder(currentState.metadata()).put(name, finalIndexTemplate)).build();
}

public Map<String, List<String>> v2TemplateOverlaps(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shall we document this method and since it's now called explicitly maybe add a test in MetadataIndexTemplateServiceTests ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion, let me do that!

grcevski and others added 5 commits October 13, 2022 14:57
…state/service/ComponentTemplatesFileSettingsIT.java


Fix double wording.

Co-authored-by: Andrei Dan <andrei.dan@elastic.co>
@andreidan
Copy link
Copy Markdown
Contributor

@grcevski A final question that just dawned on me.

How are we handling existing clusters that might have component/composable templates that start with the chosen prefix for the reserved templates?
Will they essentially become reserved when upgrading to a version that has the reserved templates feature?

@grcevski
Copy link
Copy Markdown
Contributor Author

How are we handling existing clusters that might have component/composable templates that start with the chosen prefix for the reserved templates? Will they essentially become reserved when upgrading to a version that has the reserved templates feature?

I don't think it should be a problem, nothing should happen to the templates, but maybe I'm missing a case here.

Essentially we only add the prefix when we store the names of the templates in the reserved cluster state section of the metadata, the templates themselves get stored in the custom storage without the prefix. To store any reserved state we must have defined a template in the file settings, otherwise there's nothing that modifies the reserved sections of the cluster state metadata.

Here's what I think the potential situations might be:

  1. We have an existing composable index template called composable_index_template:foo which uses the same prefix we intend to use for reservation in the metadata.

    • We want to add new reserved template foo through file based settings. We store composable_index_template:foo in the reserved section of the metadata and a template with name foo in the composable index templates metadata. There should be nothing that prevents this, we'll end up with two different composable index templates, one called foo another called composable_index_template:foo, but only foo is reserved. If one were to look at the full metadata dump, it might look confusing, but I think that's the extent of it.
    • Now we want to modify a template through the REST calls, say through TransportPutComponentTemplateAction, which defines the modified keys as Set.of(ReservedComposableIndexTemplateAction.reservedComponentName(request.name())), essentially prefixing the name with composable_index_template:.
      • If we wanted to modify foo through REST the modified keys we produce for conflict detection will be composable_index_template:foo, which will match the reserved keys metadata and we'll disallow the modification.
      • if we wanted to modify composable_index_template:foo through REST, the modified keys will produce a doubled prefix composable_index_template:composable_index_template:foo which won't match our reserved metadata and the REST call will be allowed.
  2. We have an existing composable index template called foo. In this case the file based settings will overwrite it and put reserved metadata with composable_index_template:foo. This is the same behaviour as all other file based settings.

This was a very good call-out, I'm going to write some tests to see if I can break the logic and cause a conflict where there shouldn't be one if the user had already used our prefix in the name of a template.

@grcevski grcevski merged commit 9b0363e into elastic:main Oct 14, 2022
@grcevski grcevski deleted the operator/index_templates branch October 14, 2022 17:37
@andreidan
Copy link
Copy Markdown
Contributor

andreidan commented Oct 18, 2022

@grcevski thanks so much for the detailed explanation and extra tests 🚀 ❤️

Just toyed around a bit with upgrading an 8.4 cluster that had component_template:abc and composable template composable_template:logs_data_stream and indeed modifying and retrieving them through REST works like a champ after upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Core Core issues without another label >enhancement Team:Core/Infra Meta label for core/infra team v8.6.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants