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

Deprecation check for : in Cluster/Index name #36185

Merged
merged 3 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(1, 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());
}
}