Skip to content

Commit 0ccb1db

Browse files
authored
Deprecation check for : in Cluster/Index name (#36185)
Adds a deprecation check for cluster and index names that contain `:`, which is illegal in 7.0.
1 parent 6d8954d commit 0ccb1db

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static DeprecationIssue checkShardLimit(ClusterState state) {
1818
int maxShardsInCluster = shardsPerNode * nodeCount;
1919
int currentOpenShards = state.getMetaData().getTotalOpenIndexShards();
2020

21-
if (currentOpenShards >= maxShardsInCluster) {
21+
if (nodeCount > 0 && currentOpenShards >= maxShardsInCluster) {
2222
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
2323
"Number of open shards exceeds cluster soft limit",
2424
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_70_cluster_changes.html",
@@ -27,4 +27,16 @@ static DeprecationIssue checkShardLimit(ClusterState state) {
2727
}
2828
return null;
2929
}
30+
31+
static DeprecationIssue checkClusterName(ClusterState state) {
32+
String clusterName = state.getClusterName().value();
33+
if (clusterName.contains(":")) {
34+
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
35+
"Cluster name cannot contain ':'",
36+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
37+
"#_literal_literal_is_no_longer_allowed_in_cluster_name",
38+
"This cluster is named [" + clusterName + "], which contains the illegal character ':'.");
39+
}
40+
return null;
41+
}
3042
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ private DeprecationChecks() {
3232

3333
static List<Function<ClusterState, DeprecationIssue>> CLUSTER_SETTINGS_CHECKS =
3434
Collections.unmodifiableList(Arrays.asList(
35-
ClusterDeprecationChecks::checkShardLimit
35+
ClusterDeprecationChecks::checkShardLimit,
36+
ClusterDeprecationChecks::checkClusterName
3637
));
3738

3839
static List<BiFunction<List<NodeInfo>, List<NodeStats>, DeprecationIssue>> NODE_SETTINGS_CHECKS =
@@ -44,7 +45,9 @@ private DeprecationChecks() {
4445
static List<Function<IndexMetaData, DeprecationIssue>> INDEX_SETTINGS_CHECKS =
4546
Collections.unmodifiableList(Arrays.asList(
4647
IndexDeprecationChecks::oldIndicesCheck,
47-
IndexDeprecationChecks::delimitedPayloadFilterCheck));
48+
IndexDeprecationChecks::delimitedPayloadFilterCheck,
49+
IndexDeprecationChecks::indexNameCheck
50+
));
4851

4952
/**
5053
* helper utility function to reduce repeat of running a specific {@link Set} of checks.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,16 @@ static DeprecationIssue oldIndicesCheck(IndexMetaData indexMetaData) {
104104
}
105105
return null;
106106
}
107+
108+
static DeprecationIssue indexNameCheck(IndexMetaData indexMetaData) {
109+
String clusterName = indexMetaData.getIndex().getName();
110+
if (clusterName.contains(":")) {
111+
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
112+
"Index name cannot contain ':'",
113+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
114+
"#_literal_literal_is_no_longer_allowed_in_index_name",
115+
"This index is named [" + clusterName + "], which contains the illegal character ':'.");
116+
}
117+
return null;
118+
}
107119
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@
2424

2525
public class ClusterDeprecationChecksTests extends ESTestCase {
2626

27+
public void testCheckClusterName() {
28+
final String badClusterName = randomAlphaOfLengthBetween(0, 10) + ":" + randomAlphaOfLengthBetween(0, 10);
29+
final ClusterState badClusterState = ClusterState.builder(new ClusterName(badClusterName)).build();
30+
31+
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL, "Cluster name cannot contain ':'",
32+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
33+
"#_literal_literal_is_no_longer_allowed_in_cluster_name",
34+
"This cluster is named [" + badClusterName + "], which contains the illegal character ':'.");
35+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(badClusterState));
36+
assertEquals(singletonList(expected), issues);
37+
38+
final String goodClusterName = randomAlphaOfLengthBetween(1,30);
39+
final ClusterState goodClusterState = ClusterState.builder(new ClusterName(goodClusterName)).build();
40+
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(goodClusterState));
41+
assertTrue(noIssues.isEmpty());
42+
}
43+
2744
public void testCheckShardLimit() {
2845
int shardsPerNode = randomIntBetween(2, 10000);
2946
int nodeCount = randomIntBetween(1, 10);

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,29 @@ public void testDelimitedPayloadFilterCheck() {
5151
List<DeprecationIssue> issues = DeprecationInfoAction.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetaData));
5252
assertEquals(singletonList(expected), issues);
5353
}
54+
55+
public void testIndexNameCheck(){
56+
final String badIndexName = randomAlphaOfLengthBetween(0, 10) + ":" + randomAlphaOfLengthBetween(0, 10);
57+
final IndexMetaData badIndex = IndexMetaData.builder(badIndexName)
58+
.settings(settings(Version.CURRENT))
59+
.numberOfShards(randomIntBetween(1,100))
60+
.numberOfReplicas(randomIntBetween(1,15))
61+
.build();
62+
63+
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING, "Index name cannot contain ':'",
64+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
65+
"#_literal_literal_is_no_longer_allowed_in_index_name",
66+
"This index is named [" + badIndexName + "], which contains the illegal character ':'.");
67+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(badIndex));
68+
assertEquals(singletonList(expected), issues);
69+
70+
final String goodIndexName = randomAlphaOfLengthBetween(1,30);
71+
final IndexMetaData goodIndex = IndexMetaData.builder(goodIndexName)
72+
.settings(settings(Version.CURRENT))
73+
.numberOfShards(randomIntBetween(1,100))
74+
.numberOfReplicas(randomIntBetween(1,15))
75+
.build();
76+
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(goodIndex));
77+
assertTrue(noIssues.isEmpty());
78+
}
5479
}

0 commit comments

Comments
 (0)