From 1fe1055aef157c7042f466bf5de049b28fc486f6 Mon Sep 17 00:00:00 2001 From: Mary Gouseti Date: Fri, 7 Feb 2025 19:55:14 +0200 Subject: [PATCH] [Deprecation API] Adjust details in the SourceFieldMapper deprecation warning (#122041) In this PR we improve the deprecation warning about configuring source in the mapping. - We reduce the size of the warning message so it looks better in kibana. - We keep the original message in the details. - We use an alias help url, so we can associate it with the guide when it's created. --- .../upgrades/SourceModeRollingUpgradeIT.java | 10 ++++++++-- .../elasticsearch/index/mapper/SourceFieldMapper.java | 2 ++ .../xpack/deprecation/TemplateDeprecationChecker.java | 4 ++-- .../deprecation/TemplateDeprecationCheckerTests.java | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/SourceModeRollingUpgradeIT.java b/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/SourceModeRollingUpgradeIT.java index 8bf870edc5ec..55a03da7c9e9 100644 --- a/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/SourceModeRollingUpgradeIT.java +++ b/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/SourceModeRollingUpgradeIT.java @@ -85,7 +85,13 @@ public class SourceModeRollingUpgradeIT extends AbstractRollingUpgradeTestCase { assertThat(response.containsKey("templates"), equalTo(true)); Map issuesByTemplate = (Map) response.get("templates"); assertThat(issuesByTemplate.containsKey(templateName), equalTo(true)); - var templateIssues = (List) issuesByTemplate.get(templateName); - assertThat(((Map) templateIssues.getFirst()).get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING)); + var templateIssue = (Map) ((List) issuesByTemplate.get(templateName)).getFirst(); + // Bwc compatible logic until backports are complete. + if (templateIssue.containsKey("details")) { + assertThat(templateIssue.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING_TITLE)); + assertThat(templateIssue.get("details"), equalTo(SourceFieldMapper.DEPRECATION_WARNING)); + } else { + assertThat(templateIssue.get("message"), equalTo(SourceFieldMapper.DEPRECATION_WARNING)); + } } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java index a6cb5561f2e7..5ee7ee2ae9bf 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java @@ -58,6 +58,8 @@ public class SourceFieldMapper extends MetadataFieldMapper { public static final String LOSSY_PARAMETERS_ALLOWED_SETTING_NAME = "index.lossy.source-mapping-parameters"; + public static final String DEPRECATION_WARNING_TITLE = "Configuring source mode in mappings is deprecated."; + public static final String DEPRECATION_WARNING = "Configuring source mode in mappings is deprecated and will be removed " + "in future versions. Use [index.mapping.source.mode] index setting instead."; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationChecker.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationChecker.java index d68e31a1fde4..ff0ff982d11b 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationChecker.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationChecker.java @@ -122,9 +122,9 @@ public class TemplateDeprecationChecker implements ResourceDeprecationChecker { if (sourceMap.containsKey("mode")) { return new DeprecationIssue( DeprecationIssue.Level.CRITICAL, + SourceFieldMapper.DEPRECATION_WARNING_TITLE, + "https://ela.st/migrate-source-mode", SourceFieldMapper.DEPRECATION_WARNING, - "https://github.com/elastic/elasticsearch/pull/117172", - null, false, null ); diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationCheckerTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationCheckerTests.java index 69bb396a50a9..4e1b28b34128 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationCheckerTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationCheckerTests.java @@ -51,9 +51,9 @@ public class TemplateDeprecationCheckerTests extends ESTestCase { Map> issuesByComponentTemplate = checker.check(clusterState); final DeprecationIssue expected = new DeprecationIssue( DeprecationIssue.Level.CRITICAL, + SourceFieldMapper.DEPRECATION_WARNING_TITLE, + "https://ela.st/migrate-source-mode", SourceFieldMapper.DEPRECATION_WARNING, - "https://github.com/elastic/elasticsearch/pull/117172", - null, false, null );