Skip to content

Commit

Permalink
[TEST] Run tsdb tests with both base and trial licenses (elastic#115653
Browse files Browse the repository at this point in the history
…) (elastic#115851)

* Run tsdb tests with both base and trial licenses.

* ignore license error in serverless

* update

* update

* update

(cherry picked from commit b97b663)
  • Loading branch information
kkrik-es authored Oct 29, 2024
1 parent a988c03 commit 003bea2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public abstract class DisabledSecurityDataStreamTestCase extends ESRestTestCase
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.feature(FeatureFlag.FAILURE_STORE_ENABLED)
.setting("xpack.license.self_generated.type", "trial")
.setting("xpack.security.enabled", "false")
.setting("xpack.watcher.enabled", "false")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Set;

import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.backingIndexEqualTo;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
Expand Down Expand Up @@ -54,6 +53,7 @@ public class TsdbDataStreamRestIT extends DisabledSecurityDataStreamTestCase {
"number_of_replicas": 1,
"number_of_shards": 2,
"mode": "time_series"
SOURCEMODE
}
},
"mappings":{
Expand Down Expand Up @@ -201,15 +201,35 @@ public class TsdbDataStreamRestIT extends DisabledSecurityDataStreamTestCase {
{"@timestamp": "$now", "metricset": "pod", "k8s": {"pod": {"name": "elephant", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876eb4", "ip": "10.10.55.3", "network": {"tx": 1434595272, "rx": 530605511}}}}
""";

private static String getTemplate() {
return TEMPLATE.replace("SOURCEMODE", randomFrom("", """
, "mapping": { "source": { "mode": "stored" } }""", """
, "mapping": { "source": { "mode": "synthetic" } }"""));
}

private static boolean trialStarted = false;

@Before
public void setup() throws IOException {
if (trialStarted == false) {
// Start trial to support synthetic source.
Request startTrial = new Request("POST", "/_license/start_trial");
startTrial.addParameter("acknowledge", "true");
try {
client().performRequest(startTrial);
} catch (Exception e) {
// Ignore failures, the API is not present in Serverless.
}
trialStarted = true;
}

// Add component template:
var request = new Request("POST", "/_component_template/custom_template");
request.setJsonEntity(COMPONENT_TEMPLATE);
assertOK(client().performRequest(request));
// Add composable index template
request = new Request("POST", "/_index_template/1");
request.setJsonEntity(TEMPLATE);
request.setJsonEntity(getTemplate());
assertOK(client().performRequest(request));
}

Expand All @@ -220,7 +240,7 @@ public void testTsdbDataStreams() throws Exception {
public void testTsdbDataStreamsNanos() throws Exception {
// Overwrite template to use date_nanos field type:
var putComposableIndexTemplateRequest = new Request("POST", "/_index_template/1");
putComposableIndexTemplateRequest.setJsonEntity(TEMPLATE.replace("date", "date_nanos"));
putComposableIndexTemplateRequest.setJsonEntity(getTemplate().replace("date", "date_nanos"));
assertOK(client().performRequest(putComposableIndexTemplateRequest));

assertTsdbDataStream();
Expand Down Expand Up @@ -407,7 +427,6 @@ public void testSimulateTsdbDataStreamTemplate() throws Exception {
var response = client().performRequest(simulateIndexTemplateRequest);
assertOK(response);
var responseBody = entityAsMap(response);
assertThat(ObjectPath.evaluate(responseBody, "template.settings.index"), aMapWithSize(6));
assertThat(ObjectPath.evaluate(responseBody, "template.settings.index.number_of_shards"), equalTo("2"));
assertThat(ObjectPath.evaluate(responseBody, "template.settings.index.number_of_replicas"), equalTo("1"));
assertThat(ObjectPath.evaluate(responseBody, "template.settings.index.mode"), equalTo("time_series"));
Expand Down Expand Up @@ -493,7 +512,7 @@ public void testMigrateRegularDataStreamToTsdbDataStream() throws Exception {

// Update template
putComposableIndexTemplateRequest = new Request("POST", "/_index_template/1");
putComposableIndexTemplateRequest.setJsonEntity(TEMPLATE);
putComposableIndexTemplateRequest.setJsonEntity(getTemplate());
assertOK(client().performRequest(putComposableIndexTemplateRequest));

var rolloverRequest = new Request("POST", "/k8s/_rollover");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ private static ElasticsearchCluster createCluster() {
.setting("xpack.security.enabled", "true")
.keystore("bootstrap.password", "x-pack-test-password")
.user("x_pack_rest_user", "x-pack-test-password");
if (initTestSeed().nextBoolean()) {
clusterBuilder.setting("xpack.license.self_generated.type", "trial");
}
boolean setNodes = Boolean.parseBoolean(System.getProperty("yaml.rest.tests.set_num_nodes", "true"));
if (setNodes) {
clusterBuilder.nodes(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public void append(LogEvent event) {
JAVA_ZONE_IDS = ZoneId.getAvailableZoneIds().stream().filter(unsupportedZoneIdsPredicate.negate()).sorted().toList();
}

static Random initTestSeed() {
protected static Random initTestSeed() {
String inputSeed = System.getProperty("tests.seed");
long seed;
if (inputSeed == null) {
Expand Down

0 comments on commit 003bea2

Please sign in to comment.