Add deprecation check for pidfile setting (#45939)

The pidfile setting is deprecated. This commit adds a deprecation check
for usage of this setting.
This commit is contained in:
Jason Tedor 2019-08-24 17:19:20 -04:00 committed by GitHub
parent 599bf2d68b
commit 040a810b3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 18 deletions

View File

@ -41,6 +41,7 @@ public class DeprecationChecks {
static List<BiFunction<Settings, PluginsAndModules, DeprecationIssue>> NODE_SETTINGS_CHECKS = static List<BiFunction<Settings, PluginsAndModules, DeprecationIssue>> NODE_SETTINGS_CHECKS =
Collections.unmodifiableList(Arrays.asList( Collections.unmodifiableList(Arrays.asList(
NodeDeprecationChecks::checkPidfile,
NodeDeprecationChecks::checkProcessors NodeDeprecationChecks::checkProcessors
)); ));

View File

@ -7,32 +7,59 @@
package org.elasticsearch.xpack.deprecation; package org.elasticsearch.xpack.deprecation;
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.env.Environment;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import java.util.Locale; import java.util.Locale;
class NodeDeprecationChecks { class NodeDeprecationChecks {
static DeprecationIssue checkPidfile(final Settings settings, final PluginsAndModules pluginsAndModules) {
return checkDeprecatedSetting(
settings,
pluginsAndModules,
Environment.PIDFILE_SETTING,
Environment.NODE_PIDFILE_SETTING,
"https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-pidfile");
}
static DeprecationIssue checkProcessors(final Settings settings , final PluginsAndModules pluginsAndModules) { static DeprecationIssue checkProcessors(final Settings settings , final PluginsAndModules pluginsAndModules) {
if (EsExecutors.PROCESSORS_SETTING.exists(settings) == false) { return checkDeprecatedSetting(
settings,
pluginsAndModules,
EsExecutors.PROCESSORS_SETTING,
EsExecutors.NODE_PROCESSORS_SETTING,
"https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-processors");
}
private static DeprecationIssue checkDeprecatedSetting(
final Settings settings,
final PluginsAndModules pluginsAndModules,
final Setting<?> deprecatedSetting,
final Setting<?> replacementSetting,
final String url) {
assert deprecatedSetting.isDeprecated() : deprecatedSetting;
if (deprecatedSetting.exists(settings) == false) {
return null; return null;
} }
final String deprecatedSettingKey = deprecatedSetting.getKey();
final String replacementSettingKey = replacementSetting.getKey();
final String value = deprecatedSetting.get(settings).toString();
final String message = String.format( final String message = String.format(
Locale.ROOT, Locale.ROOT,
"setting [%s] is deprecated in favor of setting [%s]", "setting [%s] is deprecated in favor of setting [%s]",
EsExecutors.PROCESSORS_SETTING.getKey(), deprecatedSettingKey,
EsExecutors.NODE_PROCESSORS_SETTING.getKey()); replacementSettingKey);
final String url =
"https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-processors";
final String details = String.format( final String details = String.format(
Locale.ROOT, Locale.ROOT,
"the setting [%s] is currently set to [%d], instead set [%s] to [%d]", "the setting [%s] is currently set to [%s], instead set [%s] to [%s]",
EsExecutors.PROCESSORS_SETTING.getKey(), deprecatedSettingKey,
EsExecutors.PROCESSORS_SETTING.get(settings), value,
EsExecutors.NODE_PROCESSORS_SETTING.getKey(), replacementSettingKey,
EsExecutors.PROCESSORS_SETTING.get(settings)); value);
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details); return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details);
} }

View File

@ -10,6 +10,7 @@ import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
@ -21,6 +22,29 @@ import static org.hamcrest.Matchers.empty;
public class NodeDeprecationChecksTests extends ESTestCase { public class NodeDeprecationChecksTests extends ESTestCase {
public void testCheckDefaults() {
final Settings settings = Settings.EMPTY;
final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList());
final List<DeprecationIssue> issues =
DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings, pluginsAndModules));
assertThat(issues, empty());
}
public void testCheckPidfile() {
final String pidfile = randomAlphaOfLength(16);
final Settings settings = Settings.builder().put(Environment.PIDFILE_SETTING.getKey(), pidfile).build();
final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList());
final List<DeprecationIssue> issues =
DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings, pluginsAndModules));
final DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"setting [pidfile] is deprecated in favor of setting [node.pidfile]",
"https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-pidfile",
"the setting [pidfile] is currently set to [" + pidfile + "], instead set [node.pidfile] to [" + pidfile + "]");
assertThat(issues, contains(expected));
assertSettingDeprecationsAndWarnings(new Setting<?>[]{Environment.PIDFILE_SETTING});
}
public void testCheckProcessors() { public void testCheckProcessors() {
final int processors = randomIntBetween(1, 4); final int processors = randomIntBetween(1, 4);
final Settings settings = Settings.builder().put(EsExecutors.PROCESSORS_SETTING.getKey(), processors).build(); final Settings settings = Settings.builder().put(EsExecutors.PROCESSORS_SETTING.getKey(), processors).build();
@ -36,12 +60,4 @@ public class NodeDeprecationChecksTests extends ESTestCase {
assertSettingDeprecationsAndWarnings(new Setting<?>[]{EsExecutors.PROCESSORS_SETTING}); assertSettingDeprecationsAndWarnings(new Setting<?>[]{EsExecutors.PROCESSORS_SETTING});
} }
public void testCheckProcessorsNotSet() {
final Settings settings = Settings.EMPTY;
final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList());
final List<DeprecationIssue> issues =
DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings, pluginsAndModules));
assertThat(issues, empty());
}
} }