Skip to content

Commit

Permalink
Deprecation check for discovery configuration (#36666)
Browse files Browse the repository at this point in the history
Adds a check for missing discovery configuration, which is now
required.
  • Loading branch information
gwbrown authored Dec 18, 2018
1 parent 4f9196a commit 4329058
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private DeprecationChecks() {
NodeDeprecationChecks::indexThreadPoolCheck,
NodeDeprecationChecks::tribeNodeCheck,
NodeDeprecationChecks::httpPipeliningCheck,
NodeDeprecationChecks::discoveryConfigurationCheck,
NodeDeprecationChecks::azureRepositoryChanges,
NodeDeprecationChecks::gcsRepositoryChanges,
NodeDeprecationChecks::fileDiscoveryPluginRemoved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING;
import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_TYPE_SETTING;
import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING;

/**
* Node-specific deprecation checks
*/
Expand Down Expand Up @@ -95,6 +99,27 @@ static DeprecationIssue httpPipeliningCheck(List<NodeInfo> nodeInfos, List<NodeS
return null;
}

static DeprecationIssue discoveryConfigurationCheck(List<NodeInfo> nodeInfos, List<NodeStats> nodeStats) {

List<String> nodesFound = nodeInfos.stream()
// These checks only apply in Zen2, which is the new default in 7.0 and can't be used in 6.x, so only apply the checks if this
// node does not have a discovery type explicitly set
.filter(nodeInfo -> nodeInfo.getSettings().hasValue(DISCOVERY_TYPE_SETTING.getKey()) == false)
// This only checks for `ping.unicast.hosts` and `hosts_provider` because `cluster.initial_master_nodes` does not exist in 6.x
.filter(nodeInfo -> nodeInfo.getSettings().hasValue(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()) == false)
.filter(nodeInfo -> nodeInfo.getSettings().hasValue(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()) == false)
.map(nodeInfo -> nodeInfo.getNode().getName())
.collect(Collectors.toList());
if (nodesFound.size() > 0) {
return new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Discovery configuration is required in production mode",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_70_cluster_changes.html" +
"#_discovery_configuration_is_required_in_production",
"nodes which do not have discovery configured: " + nodesFound);
}
return null;
}

static DeprecationIssue azureRepositoryChanges(List<NodeInfo> nodeInfos, List<NodeStats> nodeStats) {
List<String> nodesFound = nodeInfos.stream()
.filter(nodeInfo ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import java.util.List;

import static java.util.Collections.singletonList;
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING;
import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING;
import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_TYPE_SETTING;
import static org.elasticsearch.node.Node.NODE_NAME_SETTING;
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.NODE_SETTINGS_CHECKS;

public class NodeDeprecationChecksTests extends ESTestCase {
Expand All @@ -45,8 +49,9 @@ public void setupDefaults() {

private void assertSettingsAndIssue(String key, String value, DeprecationIssue expected) {
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch")
.put("node.name", "node_check")
.put(CLUSTER_NAME_SETTING.getKey(), "elasticsearch")
.put(NODE_NAME_SETTING.getKey(), "node_check")
.put(DISCOVERY_TYPE_SETTING.getKey(), "single-node") // Needed due to NodeDeprecationChecks#discoveryConfigurationCheck
.put(key, value)
.build();
List<NodeInfo> nodeInfos = Collections.singletonList(new NodeInfo(Version.CURRENT, Build.CURRENT,
Expand Down Expand Up @@ -108,6 +113,57 @@ public void testHttpPipeliningCheck() {
assertSettingsAndIssue("http.pipelining", Boolean.toString(randomBoolean()), expected);
}

public void testDiscoveryConfigurationCheck() {
List<NodeStats> nodeStats = Collections.singletonList(new NodeStats(discoveryNode, 0L, null,
null, null, null, null, new FsInfo(0L, null, paths), null, null, null,
null, null, null, null));
Settings baseSettings = Settings.builder()
.put(CLUSTER_NAME_SETTING.getKey(), "elasticsearch")
.put(NODE_NAME_SETTING.getKey(), "node_check")
.build();

{
Settings hostsProviderSettings = Settings.builder().put(baseSettings)
.put(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey(), "file")
.build();
List<NodeInfo> nodeInfos = Collections.singletonList(new NodeInfo(Version.CURRENT, Build.CURRENT,
discoveryNode, hostsProviderSettings, osInfo, null, null,
null, null, null, pluginsAndModules, null, null));

List<DeprecationIssue> issues = DeprecationChecks.filterChecks(NODE_SETTINGS_CHECKS, c -> c.apply(nodeInfos, nodeStats));
assertTrue(issues.isEmpty());
}

{
Settings hostsProviderSettings = Settings.builder().put(baseSettings)
.put("discovery.zen.ping.unicast.hosts", "[1.2.3.4, 4.5.6.7]")
.build();
List<NodeInfo> nodeInfos = Collections.singletonList(new NodeInfo(Version.CURRENT, Build.CURRENT,
discoveryNode, hostsProviderSettings, osInfo, null, null,
null, null, null, pluginsAndModules, null, null));

List<DeprecationIssue> issues = DeprecationChecks.filterChecks(NODE_SETTINGS_CHECKS, c -> c.apply(nodeInfos, nodeStats));
assertTrue(issues.isEmpty());
}

{
Settings hostsProviderSettings = Settings.builder().put(baseSettings)
.build();
List<NodeInfo> nodeInfos = Collections.singletonList(new NodeInfo(Version.CURRENT, Build.CURRENT,
discoveryNode, hostsProviderSettings, osInfo, null, null,
null, null, null, pluginsAndModules, null, null));

DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL,
"Discovery configuration is required in production mode",
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_70_cluster_changes.html" +
"#_discovery_configuration_is_required_in_production",
"nodes which do not have discovery configured: [node_check]");
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(NODE_SETTINGS_CHECKS, c -> c.apply(nodeInfos, nodeStats));
assertEquals(singletonList(expected), issues);
}

}

public void testAzurePluginCheck() {
Version esVersion = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT);
PluginInfo deprecatedPlugin = new PluginInfo(
Expand Down

0 comments on commit 4329058

Please sign in to comment.