Add deprecation check for processors (#45925)

The processors setting is deprecated. This commit adds a deprecation
check for the use of the processors setting.
This commit is contained in:
Jason Tedor 2019-08-23 20:16:40 -04:00 committed by GitHub
parent 377ff7e9ce
commit 43ca652d11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 1 deletions

View File

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

View File

@ -0,0 +1,39 @@
/*
* 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.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import java.util.Locale;
class NodeDeprecationChecks {
static DeprecationIssue checkProcessors(final Settings settings , final PluginsAndModules pluginsAndModules) {
if (EsExecutors.PROCESSORS_SETTING.exists(settings) == false) {
return null;
}
final String message = String.format(
Locale.ROOT,
"setting [%s] is deprecated in favor of setting [%s]",
EsExecutors.PROCESSORS_SETTING.getKey(),
EsExecutors.NODE_PROCESSORS_SETTING.getKey());
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(
Locale.ROOT,
"the setting [%s] is currently set to [%d], instead set [%s] to [%d]",
EsExecutors.PROCESSORS_SETTING.getKey(),
EsExecutors.PROCESSORS_SETTING.get(settings),
EsExecutors.NODE_PROCESSORS_SETTING.getKey(),
EsExecutors.PROCESSORS_SETTING.get(settings));
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details);
}
}

View File

@ -0,0 +1,47 @@
/*
* 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.common.util.concurrent.EsExecutors;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
import java.util.Collections;
import java.util.List;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
public class NodeDeprecationChecksTests extends ESTestCase {
public void testCheckProcessors() {
final int processors = randomIntBetween(1, 4);
final Settings settings = Settings.builder().put(EsExecutors.PROCESSORS_SETTING.getKey(), processors).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 [processors] is deprecated in favor of setting [node.processors]",
"https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-processors",
"the setting [processors] is currently set to [" + processors + "], instead set [node.processors] to [" + processors + "]");
assertThat(issues, contains(expected));
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());
}
}