Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entry to Deprecation API for CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING #73552

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.mapper.FieldNamesFieldMapper;
import org.elasticsearch.ingest.IngestService;
Expand All @@ -30,8 +30,10 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING;
import static org.elasticsearch.search.SearchModule.INDICES_MAX_CLAUSE_COUNT_SETTING;
import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING;
import static org.elasticsearch.xpack.deprecation.NodeDeprecationChecks.checkRemovedSetting;

public class ClusterDeprecationChecks {
private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecks.class);
Expand Down Expand Up @@ -189,4 +191,12 @@ static DeprecationIssue checkTemplatesWithMultipleTypes(ClusterState state) {
+ " define multiple types and so will cause errors when used in index creation",
null);
}

static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(final ClusterState clusterState) {
return checkRemovedSetting(clusterState.metadata().settings(),
CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING,
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_allocation_changes",
DeprecationIssue.Level.WARNING
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ private DeprecationChecks() {
ClusterDeprecationChecks::checkTemplatesWithTooManyFields,
ClusterDeprecationChecks::checkPollIntervalTooLow,
ClusterDeprecationChecks::checkTemplatesWithFieldNamesDisabled,
ClusterDeprecationChecks::checkTemplatesWithMultipleTypes
ClusterDeprecationChecks::checkTemplatesWithMultipleTypes,
ClusterDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting
));

static final List<TriFunction<Settings, PluginsAndModules, ClusterState, DeprecationIssue>> NODE_SETTINGS_CHECKS;
Expand Down Expand Up @@ -88,7 +89,8 @@ private DeprecationChecks() {
NodeDeprecationChecks::checkBootstrapSystemCallFilterSetting,
NodeDeprecationChecks::checkSharedDataPathSetting,
NodeDeprecationChecks::checkSingleDataNodeWatermarkSetting,
NodeDeprecationChecks::checkMonitoringExporterPassword
NodeDeprecationChecks::checkMonitoringExporterPassword,
NodeDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting
)
).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
package org.elasticsearch.xpack.deprecation;

import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
import org.elasticsearch.jdk.JavaVersion;
import org.elasticsearch.bootstrap.BootstrapSettings;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings;
import org.elasticsearch.common.Strings;
import org.elasticsearch.bootstrap.BootstrapSettings;
import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.env.Environment;
import org.elasticsearch.jdk.JavaVersion;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeRoleSettings;
import org.elasticsearch.script.ScriptService;
Expand All @@ -43,6 +43,7 @@
import java.util.function.BiFunction;
import java.util.stream.Collectors;

import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING;
import static org.elasticsearch.xpack.core.security.authc.RealmSettings.RESERVED_REALM_NAME_PREFIX;

class NodeDeprecationChecks {
Expand Down Expand Up @@ -414,6 +415,13 @@ private static DeprecationIssue checkDeprecatedSetting(
}

static DeprecationIssue checkRemovedSetting(final Settings settings, final Setting<?> removedSetting, final String url) {
return checkRemovedSetting(settings, removedSetting, url, DeprecationIssue.Level.CRITICAL);
}

static DeprecationIssue checkRemovedSetting(final Settings settings,
final Setting<?> removedSetting,
final String url,
DeprecationIssue.Level deprecationLevel) {
if (removedSetting.exists(settings) == false) {
return null;
}
Expand All @@ -423,7 +431,7 @@ static DeprecationIssue checkRemovedSetting(final Settings settings, final Setti
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, null);
return new DeprecationIssue(deprecationLevel, message, url, details, null);
}

static DeprecationIssue javaVersionCheck(Settings nodeSettings, PluginsAndModules plugins, final ClusterState clusterState) {
Expand Down Expand Up @@ -542,4 +550,14 @@ static DeprecationIssue checkMonitoringExporterPassword(
final String url = "https://www.elastic.co/guide/en/elasticsearch/reference/7.7/monitoring-settings.html#http-exporter-settings";
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details, null);
}

static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(final Settings settings,
final PluginsAndModules pluginsAndModules,
final ClusterState clusterState) {
return checkRemovedSetting(settings,
CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING,
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_allocation_changes",
DeprecationIssue.Level.CRITICAL
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import static java.util.Collections.singletonList;
import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING;
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.CLUSTER_SETTINGS_CHECKS;
Expand Down Expand Up @@ -312,4 +314,44 @@ public void testIndexTemplatesWithMultipleTypes() throws IOException {
hasSize(0)
);
}

public void testClusterRoutingAllocationIncludeRelocationsSetting() {
boolean settingValue = randomBoolean();
String settingKey = CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING.getKey();
final Settings deprecatedSetting = Settings.builder().put(settingKey, settingValue).build();

Metadata.Builder metadataBuilder = Metadata.builder();
if (randomBoolean()) {
metadataBuilder.transientSettings(deprecatedSetting);
} else {
metadataBuilder.persistentSettings(deprecatedSetting);
}
ClusterState clusterState = ClusterState.builder(new ClusterName("test"))
.metadata(metadataBuilder.transientSettings(deprecatedSetting).build())
.build();


final DeprecationIssue expectedIssue = new DeprecationIssue(DeprecationIssue.Level.WARNING,
String.format(Locale.ROOT,
"setting [%s] is deprecated and will be removed in the next major version",
settingKey),
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_allocation_changes",
String.format(Locale.ROOT,
"the setting [%s] is currently set to [%b], remove this setting",
settingKey,
settingValue),
null
);

List<DeprecationIssue> issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(clusterState));
assertThat(issues, hasSize(1));
assertThat(issues.get(0), equalTo(expectedIssue));

final String expectedWarning = String.format(Locale.ROOT,
"[%s] setting was deprecated in Elasticsearch and will be removed in a future release! " +
"See the breaking changes documentation for the next major version.",
settingKey);

assertWarnings(expectedWarning);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
import org.elasticsearch.action.support.replication.ClusterStateCreationUtils;
import org.elasticsearch.bootstrap.BootstrapSettings;
import org.elasticsearch.core.Set;
import org.elasticsearch.jdk.JavaVersion;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.core.Set;
import org.elasticsearch.env.Environment;
import org.elasticsearch.jdk.JavaVersion;
import org.elasticsearch.node.Node;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.transport.RemoteClusterService;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.security.authc.RealmConfig;
import org.elasticsearch.xpack.core.security.authc.RealmSettings;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -33,6 +38,7 @@
import java.util.Locale;
import java.util.stream.Collectors;

import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
Expand All @@ -41,13 +47,6 @@
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;


import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider;
import org.elasticsearch.transport.RemoteClusterService;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.core.security.authc.RealmConfig;
import org.elasticsearch.xpack.core.security.authc.RealmSettings;

public class NodeDeprecationChecksTests extends ESTestCase {

public void testCheckDefaults() {
Expand Down Expand Up @@ -660,7 +659,7 @@ public void testSingleDataNodeWatermarkSettingExplicit() {
.build();

List<DeprecationIssue> issues = DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings,
null, null));
null, ClusterState.EMPTY_STATE));

final String expectedUrl =
"https://www.elastic.co/guide/en/elasticsearch/reference/7.14/" +
Expand Down Expand Up @@ -756,4 +755,34 @@ public void testMonitoringExporterPassword() {
issue = NodeDeprecationChecks.checkMonitoringExporterPassword(Settings.builder().build(), null, null);
assertThat(issue, nullValue());
}

public void testClusterRoutingAllocationIncludeRelocationsSetting() {
boolean settingValue = randomBoolean();
String settingKey = CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING.getKey();
final Settings nodeSettings = Settings.builder().put(settingKey, settingValue).build();
final ClusterState clusterState = ClusterState.EMPTY_STATE;
final DeprecationIssue expectedIssue = new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
String.format(Locale.ROOT,
"setting [%s] is deprecated and will be removed in the next major version",
settingKey),
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_allocation_changes",
String.format(Locale.ROOT,
"the setting [%s] is currently set to [%b], remove this setting",
settingKey,
settingValue),
null
);

assertThat(
NodeDeprecationChecks.checkClusterRoutingAllocationIncludeRelocationsSetting(nodeSettings, null, clusterState),
equalTo(expectedIssue)
);

final String expectedWarning = String.format(Locale.ROOT,
"[%s] setting was deprecated in Elasticsearch and will be removed in a future release! " +
"See the breaking changes documentation for the next major version.",
settingKey);

assertWarnings(expectedWarning);
}
}