Skip to content

Commit

Permalink
Ignoring certain system templates with custom types (#82375)
Browse files Browse the repository at this point in the history
Ignoring watcher templates in the deprecation info API check for templates with custom types
  • Loading branch information
masseyke committed Jan 10, 2022
1 parent e5ef389 commit a73c9ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.Tuple;
Expand Down Expand Up @@ -602,6 +603,8 @@ static DeprecationIssue checkPollIntervalTooLow(ClusterState state) {
static DeprecationIssue checkTemplatesWithCustomAndMultipleTypes(ClusterState state) {
Set<String> templatesWithMultipleTypes = new TreeSet<>();
Set<String> templatesWithCustomTypes = new TreeSet<>();
// See https://github.com/elastic/elasticsearch/issues/82109#issuecomment-1006143687 for details:
Set<String> systemTemplatesWithCustomTypes = Sets.newHashSet(".triggered_watches", ".watch-history-9", ".watches");
state.getMetadata().getTemplates().forEach((templateCursor) -> {
String templateName = templateCursor.key;
ImmutableOpenMap<String, CompressedXContent> mappings = templateCursor.value.mappings();
Expand All @@ -614,7 +617,9 @@ static DeprecationIssue checkTemplatesWithCustomAndMultipleTypes(ClusterState st
return MapperService.SINGLE_MAPPING_NAME.equals(typeName) == false;
});
if (hasCustomType) {
templatesWithCustomTypes.add(templateName);
if (systemTemplatesWithCustomTypes.contains(templateName) == false) {
templatesWithCustomTypes.add(templateName);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,26 @@ public void testIndexTemplatesWithCustomTypes() throws IOException {
.patterns(Collections.singletonList("foo"))
.putMapping("_doc", "{\"_doc\":{}}")
.build();
// The following 3 have a custom type, but they should be ignored:
IndexTemplateMetadata triggeredWatches = IndexTemplateMetadata.builder(".triggered_watches")
.patterns(Collections.singletonList("foo"))
.putMapping("someType", "{\"type2\":{}}")
.build();
IndexTemplateMetadata watchHistory9 = IndexTemplateMetadata.builder(".watch-history-9")
.patterns(Collections.singletonList("foo"))
.putMapping("someType", "{\"type2\":{}}")
.build();
IndexTemplateMetadata watches = IndexTemplateMetadata.builder(".watches")
.patterns(Collections.singletonList("foo"))
.putMapping("someType", "{\"type2\":{}}")
.build();
ImmutableOpenMap<String, IndexTemplateMetadata> templates = ImmutableOpenMap.<String, IndexTemplateMetadata>builder()
.fPut("template1", template1)
.fPut("template2", template2)
.fPut("template3", template3)
.fPut(".triggered_watches", triggeredWatches)
.fPut(".watch-history-9", watchHistory9)
.fPut(".watches", watches)
.build();
Metadata badMetadata = Metadata.builder().templates(templates).build();
ClusterState badState = ClusterState.builder(new ClusterName("test")).metadata(badMetadata).build();
Expand Down

0 comments on commit a73c9ee

Please sign in to comment.