Skip to content

Commit 43ca652

Browse files
authored
Add deprecation check for processors (#45925)
The processors setting is deprecated. This commit adds a deprecation check for the use of the processors setting.
1 parent 377ff7e commit 43ca652

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private DeprecationChecks() {
4141

4242
static List<BiFunction<Settings, PluginsAndModules, DeprecationIssue>> NODE_SETTINGS_CHECKS =
4343
Collections.unmodifiableList(Arrays.asList(
44-
// STUB
44+
NodeDeprecationChecks::checkProcessors
4545
));
4646

4747
static List<Function<IndexMetaData, DeprecationIssue>> INDEX_SETTINGS_CHECKS =
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.deprecation;
8+
9+
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
10+
import org.elasticsearch.common.settings.Settings;
11+
import org.elasticsearch.common.util.concurrent.EsExecutors;
12+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
13+
14+
import java.util.Locale;
15+
16+
class NodeDeprecationChecks {
17+
18+
static DeprecationIssue checkProcessors(final Settings settings , final PluginsAndModules pluginsAndModules) {
19+
if (EsExecutors.PROCESSORS_SETTING.exists(settings) == false) {
20+
return null;
21+
}
22+
final String message = String.format(
23+
Locale.ROOT,
24+
"setting [%s] is deprecated in favor of setting [%s]",
25+
EsExecutors.PROCESSORS_SETTING.getKey(),
26+
EsExecutors.NODE_PROCESSORS_SETTING.getKey());
27+
final String url =
28+
"https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-processors";
29+
final String details = String.format(
30+
Locale.ROOT,
31+
"the setting [%s] is currently set to [%d], instead set [%s] to [%d]",
32+
EsExecutors.PROCESSORS_SETTING.getKey(),
33+
EsExecutors.PROCESSORS_SETTING.get(settings),
34+
EsExecutors.NODE_PROCESSORS_SETTING.getKey(),
35+
EsExecutors.PROCESSORS_SETTING.get(settings));
36+
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details);
37+
}
38+
39+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.deprecation;
8+
9+
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
10+
import org.elasticsearch.common.settings.Setting;
11+
import org.elasticsearch.common.settings.Settings;
12+
import org.elasticsearch.common.util.concurrent.EsExecutors;
13+
import org.elasticsearch.test.ESTestCase;
14+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
15+
16+
import java.util.Collections;
17+
import java.util.List;
18+
19+
import static org.hamcrest.Matchers.contains;
20+
import static org.hamcrest.Matchers.empty;
21+
22+
public class NodeDeprecationChecksTests extends ESTestCase {
23+
24+
public void testCheckProcessors() {
25+
final int processors = randomIntBetween(1, 4);
26+
final Settings settings = Settings.builder().put(EsExecutors.PROCESSORS_SETTING.getKey(), processors).build();
27+
final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList());
28+
final List<DeprecationIssue> issues =
29+
DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings, pluginsAndModules));
30+
final DeprecationIssue expected = new DeprecationIssue(
31+
DeprecationIssue.Level.CRITICAL,
32+
"setting [processors] is deprecated in favor of setting [node.processors]",
33+
"https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-processors",
34+
"the setting [processors] is currently set to [" + processors + "], instead set [node.processors] to [" + processors + "]");
35+
assertThat(issues, contains(expected));
36+
assertSettingDeprecationsAndWarnings(new Setting<?>[]{EsExecutors.PROCESSORS_SETTING});
37+
}
38+
39+
public void testCheckProcessorsNotSet() {
40+
final Settings settings = Settings.EMPTY;
41+
final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList());
42+
final List<DeprecationIssue> issues =
43+
DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings, pluginsAndModules));
44+
assertThat(issues, empty());
45+
}
46+
47+
}

0 commit comments

Comments
 (0)