Skip to content

Commit

Permalink
Deprecation check for : in Cluster/Index name (#36185)
Browse files Browse the repository at this point in the history
Adds a deprecation check for cluster and index names that contain `:`,
which is illegal in 7.0.
  • Loading branch information
gwbrown authored Dec 4, 2018
1 parent 6d8954d commit 0ccb1db
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static DeprecationIssue checkShardLimit(ClusterState state) {
int maxShardsInCluster = shardsPerNode * nodeCount;
int currentOpenShards = state.getMetaData().getTotalOpenIndexShards();

if (currentOpenShards >= maxShardsInCluster) {
if (nodeCount > 0 && currentOpenShards >= maxShardsInCluster) {
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
"Number of open shards exceeds cluster soft limit",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_70_cluster_changes.html",
Expand All @@ -27,4 +27,16 @@ static DeprecationIssue checkShardLimit(ClusterState state) {
}
return null;
}

static DeprecationIssue checkClusterName(ClusterState state) {
String clusterName = state.getClusterName().value();
if (clusterName.contains(":")) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Cluster name cannot contain ':'",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
"#_literal_literal_is_no_longer_allowed_in_cluster_name",
"This cluster is named [" + clusterName + "], which contains the illegal character ':'.");
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ private DeprecationChecks() {

static List<Function<ClusterState, DeprecationIssue>> CLUSTER_SETTINGS_CHECKS =
Collections.unmodifiableList(Arrays.asList(
ClusterDeprecationChecks::checkShardLimit
ClusterDeprecationChecks::checkShardLimit,
ClusterDeprecationChecks::checkClusterName
));

static List<BiFunction<List<NodeInfo>, List<NodeStats>, DeprecationIssue>> NODE_SETTINGS_CHECKS =
Expand All @@ -44,7 +45,9 @@ private DeprecationChecks() {
static List<Function<IndexMetaData, DeprecationIssue>> INDEX_SETTINGS_CHECKS =
Collections.unmodifiableList(Arrays.asList(
IndexDeprecationChecks::oldIndicesCheck,
IndexDeprecationChecks::delimitedPayloadFilterCheck));
IndexDeprecationChecks::delimitedPayloadFilterCheck,
IndexDeprecationChecks::indexNameCheck
));

/**
* helper utility function to reduce repeat of running a specific {@link Set} of checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,16 @@ static DeprecationIssue oldIndicesCheck(IndexMetaData indexMetaData) {
}
return null;
}

static DeprecationIssue indexNameCheck(IndexMetaData indexMetaData) {
String clusterName = indexMetaData.getIndex().getName();
if (clusterName.contains(":")) {
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
"Index name cannot contain ':'",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
"#_literal_literal_is_no_longer_allowed_in_index_name",
"This index is named [" + clusterName + "], which contains the illegal character ':'.");
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@

public class ClusterDeprecationChecksTests extends ESTestCase {

public void testCheckClusterName() {
final String badClusterName = randomAlphaOfLengthBetween(0, 10) + ":" + randomAlphaOfLengthBetween(0, 10);
final ClusterState badClusterState = ClusterState.builder(new ClusterName(badClusterName)).build();

DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL, "Cluster name cannot contain ':'",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
"#_literal_literal_is_no_longer_allowed_in_cluster_name",
"This cluster is named [" + badClusterName + "], which contains the illegal character ':'.");
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(badClusterState));
assertEquals(singletonList(expected), issues);

final String goodClusterName = randomAlphaOfLengthBetween(1,30);
final ClusterState goodClusterState = ClusterState.builder(new ClusterName(goodClusterName)).build();
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(goodClusterState));
assertTrue(noIssues.isEmpty());
}

public void testCheckShardLimit() {
int shardsPerNode = randomIntBetween(2, 10000);
int nodeCount = randomIntBetween(1, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,29 @@ public void testDelimitedPayloadFilterCheck() {
List<DeprecationIssue> issues = DeprecationInfoAction.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetaData));
assertEquals(singletonList(expected), issues);
}

public void testIndexNameCheck(){
final String badIndexName = randomAlphaOfLengthBetween(0, 10) + ":" + randomAlphaOfLengthBetween(0, 10);
final IndexMetaData badIndex = IndexMetaData.builder(badIndexName)
.settings(settings(Version.CURRENT))
.numberOfShards(randomIntBetween(1,100))
.numberOfReplicas(randomIntBetween(1,15))
.build();

DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING, "Index name cannot contain ':'",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
"#_literal_literal_is_no_longer_allowed_in_index_name",
"This index is named [" + badIndexName + "], which contains the illegal character ':'.");
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(badIndex));
assertEquals(singletonList(expected), issues);

final String goodIndexName = randomAlphaOfLengthBetween(1,30);
final IndexMetaData goodIndex = IndexMetaData.builder(goodIndexName)
.settings(settings(Version.CURRENT))
.numberOfShards(randomIntBetween(1,100))
.numberOfReplicas(randomIntBetween(1,15))
.build();
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(goodIndex));
assertTrue(noIssues.isEmpty());
}
}

0 comments on commit 0ccb1db

Please sign in to comment.