Skip to content

Commit d8e70d4

Browse files
committed
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.
1 parent 89668c5 commit d8e70d4

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java

+13
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,17 @@ private static DeprecationIssue checkDeprecatedSetting(
124124
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details);
125125
}
126126

127+
static DeprecationIssue checkRemovedSetting(final Settings settings, final Setting<?> removedSetting, final String url) {
128+
if (removedSetting.exists(settings) == false) {
129+
return null;
130+
}
131+
final String removedSettingKey = removedSetting.getKey();
132+
final String value = removedSetting.get(settings).toString();
133+
final String message =
134+
String.format(Locale.ROOT, "setting [%s] is deprecated and will be removed in the next major version", removedSettingKey);
135+
final String details =
136+
String.format(Locale.ROOT, "the setting [%s] is currently set to [%s], remove this setting", removedSettingKey, value);
137+
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details);
138+
}
139+
127140
}

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java

+27
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import static org.hamcrest.Matchers.contains;
2424
import static org.hamcrest.Matchers.containsString;
2525
import static org.hamcrest.Matchers.empty;
26+
import static org.hamcrest.Matchers.equalTo;
2627
import static org.hamcrest.Matchers.not;
28+
import static org.hamcrest.Matchers.nullValue;
2729
import static org.hamcrest.Matchers.startsWith;
2830

2931
public class NodeDeprecationChecksTests extends ESTestCase {
@@ -143,4 +145,29 @@ public void testCorrectRealmOrders() {
143145

144146
assertEquals(0, deprecationIssues.size());
145147
}
148+
149+
public void testRemovedSettingNotSet() {
150+
final Settings settings = Settings.EMPTY;
151+
final Setting<?> removedSetting = Setting.simpleString("node.removed_setting");
152+
final DeprecationIssue issue =
153+
NodeDeprecationChecks.checkRemovedSetting(settings, removedSetting, "http://removed-setting.example.com");
154+
assertThat(issue, nullValue());
155+
}
156+
157+
public void testRemovedSetting() {
158+
final Settings settings = Settings.builder().put("node.removed_setting", "value").build();
159+
final Setting<?> removedSetting = Setting.simpleString("node.removed_setting");
160+
final DeprecationIssue issue =
161+
NodeDeprecationChecks.checkRemovedSetting(settings, removedSetting, "https://removed-setting.example.com");
162+
assertThat(issue, not(nullValue()));
163+
assertThat(issue.getLevel(), equalTo(DeprecationIssue.Level.CRITICAL));
164+
assertThat(
165+
issue.getMessage(),
166+
equalTo("setting [node.removed_setting] is deprecated and will be removed in the next major version"));
167+
assertThat(
168+
issue.getDetails(),
169+
equalTo("the setting [node.removed_setting] is currently set to [value], remove this setting"));
170+
assertThat(issue.getUrl(), equalTo("https://removed-setting.example.com"));
171+
}
172+
146173
}

0 commit comments

Comments
 (0)