Skip to content

Commit c998213

Browse files
authored
Add entry to Deprecation API for CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING (#73552)
Relates #47717
1 parent db3ae4d commit c998213

File tree

5 files changed

+118
-17
lines changed

5 files changed

+118
-17
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import org.elasticsearch.common.Strings;
1515
import org.elasticsearch.common.collect.ImmutableOpenMap;
1616
import org.elasticsearch.common.compress.CompressedXContent;
17-
import org.elasticsearch.core.TimeValue;
1817
import org.elasticsearch.common.xcontent.XContentHelper;
18+
import org.elasticsearch.core.TimeValue;
1919
import org.elasticsearch.index.IndexSettings;
2020
import org.elasticsearch.index.mapper.FieldNamesFieldMapper;
2121
import org.elasticsearch.ingest.IngestService;
@@ -30,8 +30,10 @@
3030
import java.util.concurrent.atomic.AtomicInteger;
3131
import java.util.stream.Collectors;
3232

33+
import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING;
3334
import static org.elasticsearch.search.SearchModule.INDICES_MAX_CLAUSE_COUNT_SETTING;
3435
import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING;
36+
import static org.elasticsearch.xpack.deprecation.NodeDeprecationChecks.checkRemovedSetting;
3537

3638
public class ClusterDeprecationChecks {
3739
private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecks.class);
@@ -189,4 +191,12 @@ static DeprecationIssue checkTemplatesWithMultipleTypes(ClusterState state) {
189191
+ " define multiple types and so will cause errors when used in index creation",
190192
null);
191193
}
194+
195+
static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(final ClusterState clusterState) {
196+
return checkRemovedSetting(clusterState.metadata().settings(),
197+
CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING,
198+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_allocation_changes",
199+
DeprecationIssue.Level.WARNING
200+
);
201+
}
192202
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ private DeprecationChecks() {
3737
ClusterDeprecationChecks::checkTemplatesWithTooManyFields,
3838
ClusterDeprecationChecks::checkPollIntervalTooLow,
3939
ClusterDeprecationChecks::checkTemplatesWithFieldNamesDisabled,
40-
ClusterDeprecationChecks::checkTemplatesWithMultipleTypes
40+
ClusterDeprecationChecks::checkTemplatesWithMultipleTypes,
41+
ClusterDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting
4142
));
4243

4344
static final List<TriFunction<Settings, PluginsAndModules, ClusterState, DeprecationIssue>> NODE_SETTINGS_CHECKS;
@@ -88,7 +89,8 @@ private DeprecationChecks() {
8889
NodeDeprecationChecks::checkBootstrapSystemCallFilterSetting,
8990
NodeDeprecationChecks::checkSharedDataPathSetting,
9091
NodeDeprecationChecks::checkSingleDataNodeWatermarkSetting,
91-
NodeDeprecationChecks::checkMonitoringExporterPassword
92+
NodeDeprecationChecks::checkMonitoringExporterPassword,
93+
NodeDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting
9294
)
9395
).collect(Collectors.toList());
9496
}

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
package org.elasticsearch.xpack.deprecation;
99

1010
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
11-
import org.elasticsearch.jdk.JavaVersion;
11+
import org.elasticsearch.bootstrap.BootstrapSettings;
1212
import org.elasticsearch.cluster.ClusterState;
1313
import org.elasticsearch.cluster.node.DiscoveryNode;
1414
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
1515
import org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings;
16-
import org.elasticsearch.common.Strings;
17-
import org.elasticsearch.bootstrap.BootstrapSettings;
1816
import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider;
17+
import org.elasticsearch.common.Strings;
1918
import org.elasticsearch.common.settings.Setting;
2019
import org.elasticsearch.common.settings.Setting.Property;
2120
import org.elasticsearch.common.settings.Settings;
2221
import org.elasticsearch.common.util.concurrent.EsExecutors;
2322
import org.elasticsearch.common.util.set.Sets;
2423
import org.elasticsearch.env.Environment;
24+
import org.elasticsearch.jdk.JavaVersion;
2525
import org.elasticsearch.node.Node;
2626
import org.elasticsearch.node.NodeRoleSettings;
2727
import org.elasticsearch.script.ScriptService;
@@ -43,6 +43,7 @@
4343
import java.util.function.BiFunction;
4444
import java.util.stream.Collectors;
4545

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

4849
class NodeDeprecationChecks {
@@ -414,6 +415,13 @@ private static DeprecationIssue checkDeprecatedSetting(
414415
}
415416

416417
static DeprecationIssue checkRemovedSetting(final Settings settings, final Setting<?> removedSetting, final String url) {
418+
return checkRemovedSetting(settings, removedSetting, url, DeprecationIssue.Level.CRITICAL);
419+
}
420+
421+
static DeprecationIssue checkRemovedSetting(final Settings settings,
422+
final Setting<?> removedSetting,
423+
final String url,
424+
DeprecationIssue.Level deprecationLevel) {
417425
if (removedSetting.exists(settings) == false) {
418426
return null;
419427
}
@@ -423,7 +431,7 @@ static DeprecationIssue checkRemovedSetting(final Settings settings, final Setti
423431
String.format(Locale.ROOT, "setting [%s] is deprecated and will be removed in the next major version", removedSettingKey);
424432
final String details =
425433
String.format(Locale.ROOT, "the setting [%s] is currently set to [%s], remove this setting", removedSettingKey, value);
426-
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details, null);
434+
return new DeprecationIssue(deprecationLevel, message, url, details, null);
427435
}
428436

429437
static DeprecationIssue javaVersionCheck(Settings nodeSettings, PluginsAndModules plugins, final ClusterState clusterState) {
@@ -542,4 +550,14 @@ static DeprecationIssue checkMonitoringExporterPassword(
542550
final String url = "https://www.elastic.co/guide/en/elasticsearch/reference/7.7/monitoring-settings.html#http-exporter-settings";
543551
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details, null);
544552
}
553+
554+
static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(final Settings settings,
555+
final PluginsAndModules pluginsAndModules,
556+
final ClusterState clusterState) {
557+
return checkRemovedSetting(settings,
558+
CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING,
559+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_allocation_changes",
560+
DeprecationIssue.Level.CRITICAL
561+
);
562+
}
545563
}

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import java.io.IOException;
2626
import java.util.Collections;
2727
import java.util.List;
28+
import java.util.Locale;
2829

2930
import static java.util.Collections.singletonList;
31+
import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING;
3032
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
3133
import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING;
3234
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.CLUSTER_SETTINGS_CHECKS;
@@ -312,4 +314,44 @@ public void testIndexTemplatesWithMultipleTypes() throws IOException {
312314
hasSize(0)
313315
);
314316
}
317+
318+
public void testClusterRoutingAllocationIncludeRelocationsSetting() {
319+
boolean settingValue = randomBoolean();
320+
String settingKey = CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING.getKey();
321+
final Settings deprecatedSetting = Settings.builder().put(settingKey, settingValue).build();
322+
323+
Metadata.Builder metadataBuilder = Metadata.builder();
324+
if (randomBoolean()) {
325+
metadataBuilder.transientSettings(deprecatedSetting);
326+
} else {
327+
metadataBuilder.persistentSettings(deprecatedSetting);
328+
}
329+
ClusterState clusterState = ClusterState.builder(new ClusterName("test"))
330+
.metadata(metadataBuilder.transientSettings(deprecatedSetting).build())
331+
.build();
332+
333+
334+
final DeprecationIssue expectedIssue = new DeprecationIssue(DeprecationIssue.Level.WARNING,
335+
String.format(Locale.ROOT,
336+
"setting [%s] is deprecated and will be removed in the next major version",
337+
settingKey),
338+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_allocation_changes",
339+
String.format(Locale.ROOT,
340+
"the setting [%s] is currently set to [%b], remove this setting",
341+
settingKey,
342+
settingValue),
343+
null
344+
);
345+
346+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(clusterState));
347+
assertThat(issues, hasSize(1));
348+
assertThat(issues.get(0), equalTo(expectedIssue));
349+
350+
final String expectedWarning = String.format(Locale.ROOT,
351+
"[%s] setting was deprecated in Elasticsearch and will be removed in a future release! " +
352+
"See the breaking changes documentation for the next major version.",
353+
settingKey);
354+
355+
assertWarnings(expectedWarning);
356+
}
315357
}

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@
1111
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
1212
import org.elasticsearch.action.support.replication.ClusterStateCreationUtils;
1313
import org.elasticsearch.bootstrap.BootstrapSettings;
14-
import org.elasticsearch.core.Set;
15-
import org.elasticsearch.jdk.JavaVersion;
1614
import org.elasticsearch.cluster.ClusterState;
1715
import org.elasticsearch.cluster.node.DiscoveryNode;
1816
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
17+
import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider;
1918
import org.elasticsearch.common.Strings;
2019
import org.elasticsearch.common.settings.Setting;
2120
import org.elasticsearch.common.settings.Settings;
2221
import org.elasticsearch.common.util.concurrent.EsExecutors;
22+
import org.elasticsearch.core.Set;
2323
import org.elasticsearch.env.Environment;
24+
import org.elasticsearch.jdk.JavaVersion;
2425
import org.elasticsearch.node.Node;
2526
import org.elasticsearch.script.ScriptService;
2627
import org.elasticsearch.test.ESTestCase;
28+
import org.elasticsearch.transport.RemoteClusterService;
29+
import org.elasticsearch.xpack.core.XPackSettings;
30+
import org.elasticsearch.xpack.core.security.authc.RealmConfig;
31+
import org.elasticsearch.xpack.core.security.authc.RealmSettings;
2732

2833
import java.util.ArrayList;
2934
import java.util.Arrays;
@@ -33,6 +38,7 @@
3338
import java.util.Locale;
3439
import java.util.stream.Collectors;
3540

41+
import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING;
3642
import static org.hamcrest.Matchers.containsString;
3743
import static org.hamcrest.Matchers.empty;
3844
import static org.hamcrest.Matchers.equalTo;
@@ -41,13 +47,6 @@
4147
import static org.hamcrest.Matchers.nullValue;
4248
import static org.hamcrest.Matchers.startsWith;
4349

44-
45-
import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider;
46-
import org.elasticsearch.transport.RemoteClusterService;
47-
import org.elasticsearch.xpack.core.XPackSettings;
48-
import org.elasticsearch.xpack.core.security.authc.RealmConfig;
49-
import org.elasticsearch.xpack.core.security.authc.RealmSettings;
50-
5150
public class NodeDeprecationChecksTests extends ESTestCase {
5251

5352
public void testCheckDefaults() {
@@ -660,7 +659,7 @@ public void testSingleDataNodeWatermarkSettingExplicit() {
660659
.build();
661660

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

665664
final String expectedUrl =
666665
"https://www.elastic.co/guide/en/elasticsearch/reference/7.14/" +
@@ -756,4 +755,34 @@ public void testMonitoringExporterPassword() {
756755
issue = NodeDeprecationChecks.checkMonitoringExporterPassword(Settings.builder().build(), null, null);
757756
assertThat(issue, nullValue());
758757
}
758+
759+
public void testClusterRoutingAllocationIncludeRelocationsSetting() {
760+
boolean settingValue = randomBoolean();
761+
String settingKey = CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING.getKey();
762+
final Settings nodeSettings = Settings.builder().put(settingKey, settingValue).build();
763+
final ClusterState clusterState = ClusterState.EMPTY_STATE;
764+
final DeprecationIssue expectedIssue = new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
765+
String.format(Locale.ROOT,
766+
"setting [%s] is deprecated and will be removed in the next major version",
767+
settingKey),
768+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_allocation_changes",
769+
String.format(Locale.ROOT,
770+
"the setting [%s] is currently set to [%b], remove this setting",
771+
settingKey,
772+
settingValue),
773+
null
774+
);
775+
776+
assertThat(
777+
NodeDeprecationChecks.checkClusterRoutingAllocationIncludeRelocationsSetting(nodeSettings, null, clusterState),
778+
equalTo(expectedIssue)
779+
);
780+
781+
final String expectedWarning = String.format(Locale.ROOT,
782+
"[%s] setting was deprecated in Elasticsearch and will be removed in a future release! " +
783+
"See the breaking changes documentation for the next major version.",
784+
settingKey);
785+
786+
assertWarnings(expectedWarning);
787+
}
759788
}

0 commit comments

Comments
 (0)