From 43ca652d11ffe71d4d203a2ff62b54cb64455cc0 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 23 Aug 2019 20:16:40 -0400 Subject: [PATCH] Add deprecation check for processors (#45925) The processors setting is deprecated. This commit adds a deprecation check for the use of the processors setting. --- .../xpack/deprecation/DeprecationChecks.java | 2 +- .../deprecation/NodeDeprecationChecks.java | 39 +++++++++++++++ .../NodeDeprecationChecksTests.java | 47 +++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java create mode 100644 x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index dfb344f829d..4bdccc267fb 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -41,7 +41,7 @@ public class DeprecationChecks { static List> NODE_SETTINGS_CHECKS = Collections.unmodifiableList(Arrays.asList( - // STUB + NodeDeprecationChecks::checkProcessors )); static List> INDEX_SETTINGS_CHECKS = diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java new file mode 100644 index 00000000000..835026183f0 --- /dev/null +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -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); + } + +} diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java new file mode 100644 index 00000000000..9c5b67ee1d0 --- /dev/null +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -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 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 issues = + DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings, pluginsAndModules)); + assertThat(issues, empty()); + } + +}