From 00c9d99bca955288317d79f1e5122196c53f78c5 Mon Sep 17 00:00:00 2001 From: Kostas Krikellas Date: Fri, 17 Jan 2025 16:18:50 +0200 Subject: [PATCH 1/4] Node deprecation warning for indexes and component templates with source mode in mapping --- .../xpack/deprecation/DeprecationChecks.java | 3 +- .../deprecation/NodeDeprecationChecks.java | 68 +++++++++++++++++++ .../logsdb/LogsIndexModeCustomSettingsIT.java | 25 +++++++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index 0b9a538d505c9..6a44afa8ea82c 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -88,7 +88,8 @@ private DeprecationChecks() {} NodeDeprecationChecks::checkEqlEnabledSetting, NodeDeprecationChecks::checkNodeAttrData, NodeDeprecationChecks::checkWatcherBulkConcurrentRequestsSetting, - NodeDeprecationChecks::checkTracingApmSettings + NodeDeprecationChecks::checkTracingApmSettings, + NodeDeprecationChecks::checkSourceModeInMappingsAndTemplates ); static List> INDEX_SETTINGS_CHECKS = List.of( diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index b6fff5a82f0cd..811a1b8c1c2d3 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -9,12 +9,16 @@ import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.ComponentTemplate; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.common.settings.SecureSetting; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.core.TimeValue; import org.elasticsearch.env.Environment; +import org.elasticsearch.index.mapper.SourceFieldMapper; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.script.ScriptService; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; @@ -1012,4 +1016,68 @@ static DeprecationIssue checkTracingApmSettings( DeprecationIssue.Level.CRITICAL ); } + + static DeprecationIssue checkSourceModeInMappingsAndTemplates( + final Settings settings, + final PluginsAndModules pluginsAndModules, + final ClusterState clusterState, + final XPackLicenseState licenseState + ) { + List indexes = new ArrayList<>(); + for (String indexName : clusterState.metadata().getIndices().keySet()) { + IndexMetadata indexMetadata = clusterState.metadata().getIndices().get(indexName); + if (SourceFieldMapper.onOrAfterDeprecateModeVersion(indexMetadata.getCreationVersion())) { + if (indexMetadata.mapping() != null) { + Map sourceAsMap = indexMetadata.mapping().sourceAsMap(); + Object source = sourceAsMap.get("_source"); + if (source instanceof Map sourceMap) { + if (sourceMap.containsKey("mode")) { + indexes.add(indexName); + } + } + } + } + } + List templates = new ArrayList<>(); + var templateNames = clusterState.metadata().componentTemplates().keySet(); + for (String templateName : templateNames) { + ComponentTemplate template = clusterState.metadata().componentTemplates().get(templateName); + if (template.template().mappings() != null) { + var sourceAsMap = (Map) XContentHelper.convertToMap(template.template().mappings().uncompressed(), true) + .v2() + .get("_doc"); + if (sourceAsMap != null) { + Object source = sourceAsMap.get("_source"); + if (source instanceof Map sourceMap) { + if (sourceMap.containsKey("mode")) { + templates.add(templateName); + } + } + } + } + + } + if (indexes.isEmpty() == false || templates.isEmpty() == false) { + var details = new StringBuilder(SourceFieldMapper.DEPRECATION_WARNING); + if (indexes.isEmpty() == false) { + details.append(" Affected indexes: ["); + details.append(String.join(", ", indexes)); + details.append("]"); + } + if (templates.isEmpty() == false) { + details.append(" Affected component templates: ["); + details.append(String.join(", ", templates)); + details.append("]"); + } + return new DeprecationIssue( + DeprecationIssue.Level.CRITICAL, + SourceFieldMapper.DEPRECATION_WARNING, + "https://github.com/elastic/elasticsearch/pull/117172", + details.toString(), + false, + null + ); + } + return null; + } } diff --git a/x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeCustomSettingsIT.java b/x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeCustomSettingsIT.java index 99acbec04551e..442347a59c5a0 100644 --- a/x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeCustomSettingsIT.java +++ b/x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeCustomSettingsIT.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.function.Function; +import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -122,6 +123,18 @@ public void testConfigureStoredSourceBeforeIndexCreation() throws IOException { var mapping = getMapping(client, getDataStreamBackingIndex(client, "logs-custom-dev", 0)); String sourceMode = (String) subObject("_source").apply(mapping).get("mode"); assertThat(sourceMode, equalTo("stored")); + + request = new Request("GET", "/_migration/deprecations"); + var nodeSettings = (Map) ((List) entityAsMap(client.performRequest(request)).get("node_settings")).getFirst(); + assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING)); + assertThat( + (String) nodeSettings.get("details"), + allOf( + containsString(SourceFieldMapper.DEPRECATION_WARNING), + containsString("Affected indexes: [.ds-logs-custom-dev-"), + containsString("Affected component templates: [logs@custom]") + ) + ); } public void testConfigureDisabledSourceBeforeIndexCreation() { @@ -196,6 +209,18 @@ public void testConfigureStoredSourceWhenIndexIsCreated() throws IOException { var mapping = getMapping(client, getDataStreamBackingIndex(client, "logs-custom-dev", 0)); String sourceMode = (String) subObject("_source").apply(mapping).get("mode"); assertThat(sourceMode, equalTo("stored")); + + request = new Request("GET", "/_migration/deprecations"); + var nodeSettings = (Map) ((List) entityAsMap(client.performRequest(request)).get("node_settings")).getFirst(); + assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING)); + assertThat( + (String) nodeSettings.get("details"), + allOf( + containsString(SourceFieldMapper.DEPRECATION_WARNING), + containsString("Affected indexes: [.ds-logs-custom-dev-"), + containsString("Affected component templates: [logs@custom]") + ) + ); } public void testConfigureDisabledSourceWhenIndexIsCreated() throws IOException { From c417017fd63111a7d7e13b355fe71503a37acfe4 Mon Sep 17 00:00:00 2001 From: Kostas Krikellas Date: Mon, 20 Jan 2025 14:17:04 +0200 Subject: [PATCH 2/4] remove index warnings --- .../xpack/deprecation/DeprecationChecks.java | 3 +-- .../deprecation/IndexDeprecationChecks.java | 26 ------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index 6a44afa8ea82c..1bda6e1ca0a5b 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -98,8 +98,7 @@ private DeprecationChecks() {} IndexDeprecationChecks::checkIndexDataPath, IndexDeprecationChecks::storeTypeSettingCheck, IndexDeprecationChecks::frozenIndexSettingCheck, - IndexDeprecationChecks::deprecatedCamelCasePattern, - IndexDeprecationChecks::checkSourceModeInMapping + IndexDeprecationChecks::deprecatedCamelCasePattern ); static List> DATA_STREAM_CHECKS = List.of( diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index de06e270a867e..1bef1464152db 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -15,7 +15,6 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexVersion; import org.elasticsearch.index.engine.frozen.FrozenEngine; -import org.elasticsearch.index.mapper.SourceFieldMapper; import org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; @@ -203,31 +202,6 @@ static List findInPropertiesRecursively( return issues; } - static DeprecationIssue checkSourceModeInMapping(IndexMetadata indexMetadata, ClusterState clusterState) { - if (SourceFieldMapper.onOrAfterDeprecateModeVersion(indexMetadata.getCreationVersion())) { - boolean[] useSourceMode = { false }; - fieldLevelMappingIssue(indexMetadata, ((mappingMetadata, sourceAsMap) -> { - Object source = sourceAsMap.get("_source"); - if (source instanceof Map sourceMap) { - if (sourceMap.containsKey("mode")) { - useSourceMode[0] = true; - } - } - })); - if (useSourceMode[0]) { - return new DeprecationIssue( - DeprecationIssue.Level.CRITICAL, - SourceFieldMapper.DEPRECATION_WARNING, - "https://github.com/elastic/elasticsearch/pull/117172", - SourceFieldMapper.DEPRECATION_WARNING, - false, - null - ); - } - } - return null; - } - static DeprecationIssue deprecatedCamelCasePattern(IndexMetadata indexMetadata, ClusterState clusterState) { List fields = new ArrayList<>(); fieldLevelMappingIssue( From 0fbdbe07ba74e1238bdf5b65da9c38b4b291c0e7 Mon Sep 17 00:00:00 2001 From: Kostas Krikellas Date: Mon, 20 Jan 2025 17:06:52 +0200 Subject: [PATCH 3/4] restrict to component templates --- .../xpack/deprecation/DeprecationChecks.java | 2 +- .../deprecation/NodeDeprecationChecks.java | 49 +++++-------------- .../NodeDeprecationChecksTests.java | 34 +++++++++++++ .../logsdb/LogsIndexModeCustomSettingsIT.java | 13 +---- 4 files changed, 48 insertions(+), 50 deletions(-) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index 1bda6e1ca0a5b..1bc040418bf07 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -89,7 +89,7 @@ private DeprecationChecks() {} NodeDeprecationChecks::checkNodeAttrData, NodeDeprecationChecks::checkWatcherBulkConcurrentRequestsSetting, NodeDeprecationChecks::checkTracingApmSettings, - NodeDeprecationChecks::checkSourceModeInMappingsAndTemplates + NodeDeprecationChecks::checkSourceModeInComponentTemplates ); static List> INDEX_SETTINGS_CHECKS = List.of( diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index 811a1b8c1c2d3..d2a6b8cac86ef 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -10,7 +10,6 @@ import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.ComponentTemplate; -import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.common.settings.SecureSetting; import org.elasticsearch.common.settings.Setting; @@ -1017,27 +1016,12 @@ static DeprecationIssue checkTracingApmSettings( ); } - static DeprecationIssue checkSourceModeInMappingsAndTemplates( + static DeprecationIssue checkSourceModeInComponentTemplates( final Settings settings, final PluginsAndModules pluginsAndModules, final ClusterState clusterState, final XPackLicenseState licenseState ) { - List indexes = new ArrayList<>(); - for (String indexName : clusterState.metadata().getIndices().keySet()) { - IndexMetadata indexMetadata = clusterState.metadata().getIndices().get(indexName); - if (SourceFieldMapper.onOrAfterDeprecateModeVersion(indexMetadata.getCreationVersion())) { - if (indexMetadata.mapping() != null) { - Map sourceAsMap = indexMetadata.mapping().sourceAsMap(); - Object source = sourceAsMap.get("_source"); - if (source instanceof Map sourceMap) { - if (sourceMap.containsKey("mode")) { - indexes.add(indexName); - } - } - } - } - } List templates = new ArrayList<>(); var templateNames = clusterState.metadata().componentTemplates().keySet(); for (String templateName : templateNames) { @@ -1057,27 +1041,16 @@ static DeprecationIssue checkSourceModeInMappingsAndTemplates( } } - if (indexes.isEmpty() == false || templates.isEmpty() == false) { - var details = new StringBuilder(SourceFieldMapper.DEPRECATION_WARNING); - if (indexes.isEmpty() == false) { - details.append(" Affected indexes: ["); - details.append(String.join(", ", indexes)); - details.append("]"); - } - if (templates.isEmpty() == false) { - details.append(" Affected component templates: ["); - details.append(String.join(", ", templates)); - details.append("]"); - } - return new DeprecationIssue( - DeprecationIssue.Level.CRITICAL, - SourceFieldMapper.DEPRECATION_WARNING, - "https://github.com/elastic/elasticsearch/pull/117172", - details.toString(), - false, - null - ); + if (templates.isEmpty()) { + return null; } - return null; + return new DeprecationIssue( + DeprecationIssue.Level.CRITICAL, + SourceFieldMapper.DEPRECATION_WARNING, + "https://github.com/elastic/elasticsearch/pull/117172", + SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [" + String.join(", ", templates) + "]", + false, + null + ); } } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 3aaee0e5cdb52..22b1b80f291c8 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -11,23 +11,29 @@ import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.ComponentTemplate; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.Template; import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.settings.MockSecureSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.env.Environment; +import org.elasticsearch.index.mapper.SourceFieldMapper; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -832,4 +838,32 @@ public void testCheckNodeAttrData() { ); assertThat(issues, hasItem(expected)); } + + public void testCheckSourceModeInComponentTemplates() throws IOException { + Template template = Template.builder().mappings(CompressedXContent.fromJSON(""" + { "_doc": { "_source": { "mode": "stored"} } }""")).build(); + ComponentTemplate componentTemplate = new ComponentTemplate(template, 1L, new HashMap<>()); + ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE) + .metadata(Metadata.builder().componentTemplates(Map.of("my-template", componentTemplate))) + .build(); + + final List issues = DeprecationChecks.filterChecks( + DeprecationChecks.NODE_SETTINGS_CHECKS, + c -> c.apply( + Settings.EMPTY, + new PluginsAndModules(Collections.emptyList(), Collections.emptyList()), + clusterState, + new XPackLicenseState(() -> 0) + ) + ); + final DeprecationIssue expected = new DeprecationIssue( + DeprecationIssue.Level.CRITICAL, + SourceFieldMapper.DEPRECATION_WARNING, + "https://github.com/elastic/elasticsearch/pull/117172", + SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [my-template]", + false, + null + ); + assertThat(issues, hasItem(expected)); + } } diff --git a/x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeCustomSettingsIT.java b/x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeCustomSettingsIT.java index 442347a59c5a0..b5a3ff482c3cf 100644 --- a/x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeCustomSettingsIT.java +++ b/x-pack/plugin/logsdb/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/LogsIndexModeCustomSettingsIT.java @@ -22,7 +22,6 @@ import java.util.Map; import java.util.function.Function; -import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -129,11 +128,7 @@ public void testConfigureStoredSourceBeforeIndexCreation() throws IOException { assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING)); assertThat( (String) nodeSettings.get("details"), - allOf( - containsString(SourceFieldMapper.DEPRECATION_WARNING), - containsString("Affected indexes: [.ds-logs-custom-dev-"), - containsString("Affected component templates: [logs@custom]") - ) + containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [logs@custom]") ); } @@ -215,11 +210,7 @@ public void testConfigureStoredSourceWhenIndexIsCreated() throws IOException { assertThat(nodeSettings.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING)); assertThat( (String) nodeSettings.get("details"), - allOf( - containsString(SourceFieldMapper.DEPRECATION_WARNING), - containsString("Affected indexes: [.ds-logs-custom-dev-"), - containsString("Affected component templates: [logs@custom]") - ) + containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [logs@custom]") ); } From 526f718ad09b55829788170e4e136131b470a410 Mon Sep 17 00:00:00 2001 From: Kostas Krikellas Date: Mon, 20 Jan 2025 17:53:04 +0200 Subject: [PATCH 4/4] refine --- .../xpack/deprecation/NodeDeprecationChecks.java | 1 + .../deprecation/NodeDeprecationChecksTests.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index d2a6b8cac86ef..f1a1f91ba35a0 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -1044,6 +1044,7 @@ static DeprecationIssue checkSourceModeInComponentTemplates( if (templates.isEmpty()) { return null; } + Collections.sort(templates); return new DeprecationIssue( DeprecationIssue.Level.CRITICAL, SourceFieldMapper.DEPRECATION_WARNING, diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 22b1b80f291c8..7fe2be2736ea8 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -843,8 +843,18 @@ public void testCheckSourceModeInComponentTemplates() throws IOException { Template template = Template.builder().mappings(CompressedXContent.fromJSON(""" { "_doc": { "_source": { "mode": "stored"} } }""")).build(); ComponentTemplate componentTemplate = new ComponentTemplate(template, 1L, new HashMap<>()); + + Template template2 = Template.builder().mappings(CompressedXContent.fromJSON(""" + { "_doc": { "_source": { "enabled": false} } }""")).build(); + ComponentTemplate componentTemplate2 = new ComponentTemplate(template2, 1L, new HashMap<>()); + ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE) - .metadata(Metadata.builder().componentTemplates(Map.of("my-template", componentTemplate))) + .metadata( + Metadata.builder() + .componentTemplates( + Map.of("my-template-1", componentTemplate, "my-template-2", componentTemplate, "my-template-3", componentTemplate2) + ) + ) .build(); final List issues = DeprecationChecks.filterChecks( @@ -860,7 +870,7 @@ public void testCheckSourceModeInComponentTemplates() throws IOException { DeprecationIssue.Level.CRITICAL, SourceFieldMapper.DEPRECATION_WARNING, "https://github.com/elastic/elasticsearch/pull/117172", - SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [my-template]", + SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [my-template-1, my-template-2]", false, null );