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.
This commit is contained in:
Jason Tedor 2020-03-11 16:44:47 -04:00
parent 89668c5ea0
commit d8e70d4688
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
2 changed files with 40 additions and 0 deletions

View File

@ -124,4 +124,17 @@ class NodeDeprecationChecks {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details); 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);
}
} }

View File

@ -23,7 +23,9 @@ import java.util.Locale;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
public class NodeDeprecationChecksTests extends ESTestCase { public class NodeDeprecationChecksTests extends ESTestCase {
@ -143,4 +145,29 @@ public class NodeDeprecationChecksTests extends ESTestCase {
assertEquals(0, deprecationIssues.size()); 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"));
}
} }