Skip to content

Commit

Permalink
Restrict testing of legacy discovery to tests (#61178)
Browse files Browse the repository at this point in the history
The 7.x branch preserves the legacy discovery mechanism from 6.x purely
for running internal cluster tests; this mechanism is otherwise
completely untested and unsupported. However it is still technically
possible to use it outside of the test suite if you dig through the
source code to work out what settings need to be set. With this change
we make it impossible to use this mechanism in production.

Closes #61177
  • Loading branch information
DaveCTurner committed Aug 17, 2020
1 parent c673f2b commit 5d8fad2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,11 @@ boolean isAllPermissionGranted() {
static class DiscoveryConfiguredCheck implements BootstrapCheck {
@Override
public BootstrapCheckResult check(BootstrapContext context) {
if (DiscoveryModule.ZEN_DISCOVERY_TYPE.equals(DiscoveryModule.DISCOVERY_TYPE_SETTING.get(context.settings()))) {
return BootstrapCheckResult.failure(String.format(Locale.ROOT,
"discovery type [%s] is unsuitable for production use", DiscoveryModule.ZEN_DISCOVERY_TYPE));
}

if (DiscoveryModule.ZEN2_DISCOVERY_TYPE.equals(DiscoveryModule.DISCOVERY_TYPE_SETTING.get(context.settings())) == false) {
return BootstrapCheckResult.success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

package org.elasticsearch.discovery;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Assertions;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.coordination.Coordinator;
import org.elasticsearch.cluster.coordination.ElectionStrategy;
Expand Down Expand Up @@ -67,7 +68,7 @@
public class DiscoveryModule {
private static final Logger logger = LogManager.getLogger(DiscoveryModule.class);

public static final String ZEN_DISCOVERY_TYPE = "legacy-zen";
public static final String ZEN_DISCOVERY_TYPE = "legacy-zen-for-testing-only-do-not-use";
public static final String ZEN2_DISCOVERY_TYPE = "zen";

public static final String SINGLE_NODE_DISCOVERY_TYPE = "single-node";
Expand Down Expand Up @@ -155,7 +156,7 @@ public DiscoveryModule(Settings settings, ThreadPool threadPool, TransportServic
transportService, namedWriteableRegistry, allocationService, masterService, gatewayMetaState::getPersistedState,
seedHostsProvider, clusterApplier, joinValidators, new Random(Randomness.get().nextLong()), rerouteService,
electionStrategy, nodeHealthService);
} else if (ZEN_DISCOVERY_TYPE.equals(discoveryType)) {
} else if (Assertions.ENABLED && ZEN_DISCOVERY_TYPE.equals(discoveryType)) {
discovery = new ZenDiscovery(settings, threadPool, transportService, namedWriteableRegistry, masterService, clusterApplier,
clusterSettings, seedHostsProvider, allocationService, joinValidators, rerouteService);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ public boolean alwaysEnforce() {
public void testDiscoveryConfiguredCheck() throws NodeValidationException {
final List<BootstrapCheck> checks = Collections.singletonList(new BootstrapChecks.DiscoveryConfiguredCheck());

final BootstrapContext zen1Context = createTestContext(Settings.builder()
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), ZEN_DISCOVERY_TYPE).build(), Metadata.EMPTY_METADATA);

final BootstrapContext zen2Context = createTestContext(Settings.builder()
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), ZEN2_DISCOVERY_TYPE).build(), Metadata.EMPTY_METADATA);

Expand All @@ -731,7 +734,11 @@ public void testDiscoveryConfiguredCheck() throws NodeValidationException {

// not enforced for non-zen2 discovery
BootstrapChecks.check(createTestContext(Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(),
randomFrom(ZEN_DISCOVERY_TYPE, "single-node", randomAlphaOfLength(5))).build(), Metadata.EMPTY_METADATA), true, checks);
randomFrom("single-node", randomAlphaOfLength(5))).build(), Metadata.EMPTY_METADATA), true, checks);

assertThat(expectThrows(NodeValidationException.class,
() -> BootstrapChecks.check(zen1Context, true, checks)),
hasToString(containsString("discovery type [legacy-zen-for-testing-only-do-not-use] is unsuitable for production use")));

final NodeValidationException e = expectThrows(NodeValidationException.class,
() -> BootstrapChecks.check(zen2Context, true, checks));
Expand Down

0 comments on commit 5d8fad2

Please sign in to comment.