Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ private DeprecationChecks() {}
NodeDeprecationChecks::checkEqlEnabledSetting,
NodeDeprecationChecks::checkNodeAttrData,
NodeDeprecationChecks::checkWatcherBulkConcurrentRequestsSetting,
NodeDeprecationChecks::checkTracingApmSettings
NodeDeprecationChecks::checkTracingApmSettings,
NodeDeprecationChecks::checkSourceModeInComponentTemplates
);

static List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> INDEX_SETTINGS_CHECKS = List.of(
Expand All @@ -97,8 +98,7 @@ private DeprecationChecks() {}
IndexDeprecationChecks::checkIndexDataPath,
IndexDeprecationChecks::storeTypeSettingCheck,
IndexDeprecationChecks::frozenIndexSettingCheck,
IndexDeprecationChecks::deprecatedCamelCasePattern,
IndexDeprecationChecks::checkSourceModeInMapping
IndexDeprecationChecks::deprecatedCamelCasePattern
);

static List<BiFunction<DataStream, ClusterState, DeprecationIssue>> DATA_STREAM_CHECKS = List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -203,31 +202,6 @@ static List<String> 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<String> fields = new ArrayList<>();
fieldLevelMappingIssue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.ComponentTemplate;
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;
Expand Down Expand Up @@ -1012,4 +1015,43 @@ static DeprecationIssue checkTracingApmSettings(
DeprecationIssue.Level.CRITICAL
);
}

static DeprecationIssue checkSourceModeInComponentTemplates(
final Settings settings,
final PluginsAndModules pluginsAndModules,
final ClusterState clusterState,
final XPackLicenseState licenseState
) {
List<String> 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 (templates.isEmpty()) {
return null;
}
Collections.sort(templates);
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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -832,4 +838,42 @@ 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<>());

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-1", componentTemplate, "my-template-2", componentTemplate, "my-template-3", componentTemplate2)
)
)
.build();

final List<DeprecationIssue> 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-1, my-template-2]",
false,
null
);
assertThat(issues, hasItem(expected));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ 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"),
containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [logs@custom]")
);
}

public void testConfigureDisabledSourceBeforeIndexCreation() {
Expand Down Expand Up @@ -196,6 +204,14 @@ 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"),
containsString(SourceFieldMapper.DEPRECATION_WARNING + " Affected component templates: [logs@custom]")
);
}

public void testConfigureDisabledSourceWhenIndexIsCreated() throws IOException {
Expand Down