Skip to content

Commit

Permalink
Add jvm option to enable test features (#113108) (#113700)
Browse files Browse the repository at this point in the history
The option is only enabled for test clusters, and turns on features that are only present in tests

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
thecoop and elasticmachine committed Sep 30, 2024
1 parent 982122a commit 5ba445e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ if (providers.systemProperty('idea.active').getOrNull() == 'true') {
'-ea',
'-Djava.security.manager=allow',
'-Djava.locale.providers=CLDR',
'-Dtests.testfeatures.enabled=true',
'-Des.nativelibs.path="' + testLibraryPath + '"',
// TODO: only open these for mockito when it is modularized
'--add-opens=java.base/java.security.cert=ALL-UNNAMED',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void execute(Task t) {
"-Xmx" + System.getProperty("tests.heap.size", "512m"),
"-Xms" + System.getProperty("tests.heap.size", "512m"),
"-Djava.security.manager=allow",
"-Dtests.testfeatures.enabled=true",
"--add-opens=java.base/java.util=ALL-UNNAMED",
// TODO: only open these for mockito when it is modularized
"--add-opens=java.base/java.security.cert=ALL-UNNAMED",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void testClusterHasFeatures() {
FeatureService service = internalCluster().getCurrentMasterNodeInstance(FeatureService.class);

assertThat(service.getNodeFeatures(), hasKey(FeatureService.FEATURES_SUPPORTED.id()));
assertThat(service.getNodeFeatures(), hasKey(FeatureService.TEST_FEATURES_ENABLED.id()));

// check the nodes all have a feature in their cluster state (there should always be features_supported)
var response = clusterAdmin().state(new ClusterStateRequest(TEST_REQUEST_TIMEOUT).clear().nodes(true)).actionGet();
Expand Down
18 changes: 17 additions & 1 deletion server/src/main/java/org/elasticsearch/features/FeatureData.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.logging.LogManager;
import org.elasticsearch.logging.Logger;

import java.util.Collections;
import java.util.HashMap;
Expand All @@ -28,6 +30,16 @@
* features for the consumption of {@link FeatureService}
*/
public class FeatureData {

private static final Logger Log = LogManager.getLogger(FeatureData.class);
private static final boolean INCLUDE_TEST_FEATURES = System.getProperty("tests.testfeatures.enabled", "").equals("true");

static {
if (INCLUDE_TEST_FEATURES) {
Log.warn("WARNING: Test features are enabled. This should ONLY be used in automated tests.");
}
}

private final NavigableMap<Version, Set<String>> historicalFeatures;
private final Map<String, NodeFeature> nodeFeatures;

Expand All @@ -43,7 +55,11 @@ public static FeatureData createFromSpecifications(List<? extends FeatureSpecifi
NavigableMap<Version, Set<String>> historicalFeatures = new TreeMap<>(Map.of(Version.V_EMPTY, Set.of()));
Map<String, NodeFeature> nodeFeatures = new HashMap<>();
for (FeatureSpecification spec : specs) {
var specFeatures = spec.getFeatures();
Set<NodeFeature> specFeatures = spec.getFeatures();
if (INCLUDE_TEST_FEATURES) {
specFeatures = new HashSet<>(specFeatures);
specFeatures.addAll(spec.getTestFeatures());
}

for (var hfe : spec.getHistoricalFeatures().entrySet()) {
FeatureSpecification existing = allFeatures.putIfAbsent(hfe.getKey().id(), spec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public class FeatureInfrastructureFeatures implements FeatureSpecification {
public Set<NodeFeature> getFeatures() {
return Set.of(FeatureService.FEATURES_SUPPORTED);
}

@Override
public Set<NodeFeature> getTestFeatures() {
return Set.of(FeatureService.TEST_FEATURES_ENABLED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class FeatureService {
* A feature indicating that node features are supported.
*/
public static final NodeFeature FEATURES_SUPPORTED = new NodeFeature("features_supported");
public static final NodeFeature TEST_FEATURES_ENABLED = new NodeFeature("test_features_enabled");

private static final Logger logger = LogManager.getLogger(FeatureService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ default Set<NodeFeature> getFeatures() {
return Set.of();
}

/**
* Returns a set of test features that this node supports.
* <p>
* These features will only be exposed if the {@code tests.testfeatures.enabled} system property is set.
* This should only be used when deploying test clusters.
*/
default Set<NodeFeature> getTestFeatures() {
return Set.of();
}

/**
* Returns information on historical features that should be deemed to be present on all nodes
* on or above the {@link Version} specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public final class DefaultLocalClusterSpecBuilder extends AbstractLocalClusterSp

public DefaultLocalClusterSpecBuilder() {
super();
this.apply(c -> c.systemProperty("ingest.geoip.downloader.enabled.default", "false"));
this.apply(
c -> c.systemProperty("ingest.geoip.downloader.enabled.default", "false").systemProperty("tests.testfeatures.enabled", "true")
);
this.apply(new FipsEnabledClusterConfigProvider());
this.settings(new DefaultSettingsProvider());
this.environment(new DefaultEnvironmentProvider());
Expand Down

0 comments on commit 5ba445e

Please sign in to comment.