From e54110e2e9ef6dbef0f977efa4e971e34afa5470 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 9 Mar 2020 17:54:02 -0400 Subject: [PATCH 1/5] Enable deprecation checks for removed settings 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. --- .../xpack/deprecation/DeprecationChecks.java | 3 +- .../deprecation/NodeDeprecationChecks.java | 38 ++++++++++++++++ .../NodeDeprecationChecksTests.java | 45 +++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java create mode 100644 x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java 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 9a77d94fd0e5a..5c137bb386883 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 @@ -33,7 +33,8 @@ private DeprecationChecks() { static List> CLUSTER_SETTINGS_CHECKS = Collections.emptyList(); - static List> NODE_SETTINGS_CHECKS = Collections.emptyList(); + static List> NODE_SETTINGS_CHECKS = + NodeDeprecationChecks.NODE_SETTINGS_CHECKS; static List> INDEX_SETTINGS_CHECKS = List.of(IndexDeprecationChecks::oldIndicesCheck, IndexDeprecationChecks::translogRetentionSettingCheck); 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 new file mode 100644 index 0000000000000..5b6d511fa05ac --- /dev/null +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -0,0 +1,38 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.deprecation; + +import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; + +import java.util.List; +import java.util.Locale; +import java.util.function.BiFunction; + +public class NodeDeprecationChecks { + + public static List> NODE_SETTINGS_CHECKS; + + static { + NODE_SETTINGS_CHECKS = List.of(); + } + + 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("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 new file mode 100644 index 0000000000000..1dad1be8d653e --- /dev/null +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.deprecation; + +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.*; + +public class NodeDeprecationChecksTests extends ESTestCase { + + 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")); + } + +} From b29c683068d42010a7b3660b97e7e221eccce932 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 9 Mar 2020 17:57:03 -0400 Subject: [PATCH 2/5] Fix imports --- .../xpack/deprecation/NodeDeprecationChecksTests.java | 1 - 1 file changed, 1 deletion(-) 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 1dad1be8d653e..00c49aedbe223 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 @@ -14,7 +14,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.*; public class NodeDeprecationChecksTests extends ESTestCase { From c36611760b19cb9988eed01e9085c36f40ace52a Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 9 Mar 2020 18:49:09 -0400 Subject: [PATCH 3/5] Fix forbidden call --- .../elasticsearch/xpack/deprecation/NodeDeprecationChecks.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 5b6d511fa05ac..095e44edb09f1 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 @@ -31,7 +31,8 @@ static DeprecationIssue checkRemovedSetting(final Settings settings, final Setti 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("the setting [%s] is currently set to [%s], remove this setting", removedSettingKey, value); + 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); } From 42b5aadae1e857a09d734569ba9af1417cd9c7fc Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 9 Mar 2020 19:05:08 -0400 Subject: [PATCH 4/5] Consistency --- .../xpack/deprecation/DeprecationChecks.java | 3 +-- .../xpack/deprecation/NodeDeprecationChecks.java | 9 --------- 2 files changed, 1 insertion(+), 11 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 5c137bb386883..05d55559ac1b3 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 @@ -33,8 +33,7 @@ private DeprecationChecks() { static List> CLUSTER_SETTINGS_CHECKS = Collections.emptyList(); - static List> NODE_SETTINGS_CHECKS = - NodeDeprecationChecks.NODE_SETTINGS_CHECKS; + static List> NODE_SETTINGS_CHECKS = List.of(); static List> INDEX_SETTINGS_CHECKS = List.of(IndexDeprecationChecks::oldIndicesCheck, IndexDeprecationChecks::translogRetentionSettingCheck); 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 095e44edb09f1..c5087622404ab 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 @@ -6,23 +6,14 @@ package org.elasticsearch.xpack.deprecation; -import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; -import java.util.List; import java.util.Locale; -import java.util.function.BiFunction; public class NodeDeprecationChecks { - public static List> NODE_SETTINGS_CHECKS; - - static { - NODE_SETTINGS_CHECKS = List.of(); - } - static DeprecationIssue checkRemovedSetting(final Settings settings, final Setting removedSetting, final String url) { if (removedSetting.exists(settings) == false) { return null; From e9a24da88caea12d0d272806051cc7a8aec5d74d Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 11 Mar 2020 08:44:07 -0400 Subject: [PATCH 5/5] Update x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java --- .../org/elasticsearch/xpack/deprecation/DeprecationChecks.java | 2 +- 1 file changed, 1 insertion(+), 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 05d55559ac1b3..9a77d94fd0e5a 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 @@ -33,7 +33,7 @@ private DeprecationChecks() { static List> CLUSTER_SETTINGS_CHECKS = Collections.emptyList(); - static List> NODE_SETTINGS_CHECKS = List.of(); + static List> NODE_SETTINGS_CHECKS = Collections.emptyList(); static List> INDEX_SETTINGS_CHECKS = List.of(IndexDeprecationChecks::oldIndicesCheck, IndexDeprecationChecks::translogRetentionSettingCheck);