mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Restrict testing of legacy discovery to tests (#61178)
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
This commit is contained in:
parent
8b7a0a1f64
commit
f3e0c60896
@ -739,6 +739,11 @@ final class BootstrapChecks {
|
||||
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();
|
||||
}
|
||||
|
@ -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;
|
||||
@ -67,7 +68,7 @@ import static org.elasticsearch.node.Node.NODE_NAME_SETTING;
|
||||
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";
|
||||
@ -155,7 +156,7 @@ public class DiscoveryModule {
|
||||
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 {
|
||||
|
@ -723,6 +723,9 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase {
|
||||
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);
|
||||
|
||||
@ -731,7 +734,11 @@ public class BootstrapChecksTests extends AbstractBootstrapCheckTestCase {
|
||||
|
||||
// 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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user