From d8e70d468867119927d5e44f1e0fc5b6d8e5d24f Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 11 Mar 2020 16:44:47 -0400 Subject: [PATCH] Enable deprecation checks for removed settings (#53317) Today we do not have any infrastructure for adding a deprecation check for settings that are removed. This commit enables this by adding such infrastructure. Note that this infrastructure is unused in this commit, which is deliberate. However, the primary target for this commit is 7.x where this infrastructue will be used, in a follow-up. --- .../deprecation/NodeDeprecationChecks.java | 13 +++++++++ .../NodeDeprecationChecksTests.java | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) 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 b9505631ae4..5760a7db41a 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 @@ -124,4 +124,17 @@ class NodeDeprecationChecks { return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details); } + static DeprecationIssue checkRemovedSetting(final Settings settings, final Setting removedSetting, final String url) { + if (removedSetting.exists(settings) == false) { + return null; + } + final String removedSettingKey = removedSetting.getKey(); + final String value = removedSetting.get(settings).toString(); + final String message = + String.format(Locale.ROOT, "setting [%s] is deprecated and will be removed in the next major version", removedSettingKey); + final String details = + String.format(Locale.ROOT, "the setting [%s] is currently set to [%s], remove this setting", removedSettingKey, value); + return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details); + } + } 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 9c21ae3532d..4b5970f22e9 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 @@ -23,7 +23,9 @@ import java.util.Locale; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.startsWith; public class NodeDeprecationChecksTests extends ESTestCase { @@ -143,4 +145,29 @@ public class NodeDeprecationChecksTests extends ESTestCase { assertEquals(0, deprecationIssues.size()); } + + public void testRemovedSettingNotSet() { + final Settings settings = Settings.EMPTY; + final Setting removedSetting = Setting.simpleString("node.removed_setting"); + final DeprecationIssue issue = + NodeDeprecationChecks.checkRemovedSetting(settings, removedSetting, "http://removed-setting.example.com"); + assertThat(issue, nullValue()); + } + + public void testRemovedSetting() { + final Settings settings = Settings.builder().put("node.removed_setting", "value").build(); + final Setting removedSetting = Setting.simpleString("node.removed_setting"); + final DeprecationIssue issue = + NodeDeprecationChecks.checkRemovedSetting(settings, removedSetting, "https://removed-setting.example.com"); + assertThat(issue, not(nullValue())); + assertThat(issue.getLevel(), equalTo(DeprecationIssue.Level.CRITICAL)); + assertThat( + issue.getMessage(), + equalTo("setting [node.removed_setting] is deprecated and will be removed in the next major version")); + assertThat( + issue.getDetails(), + equalTo("the setting [node.removed_setting] is currently set to [value], remove this setting")); + assertThat(issue.getUrl(), equalTo("https://removed-setting.example.com")); + } + }