[Build] Extract logsdb rolling-upgrade tests (#129673)

- introduce separate subproject for testing logsdb rolling-upgrade tests
- should reduce :qa:rolling-upgrade test task durations
This commit is contained in:
Rene Groeschke 2025-06-19 22:04:36 +02:00 committed by GitHub
parent 2b8d9df0ef
commit 29db3f3464
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 95 additions and 5 deletions

View file

@ -12,19 +12,24 @@ package org.elasticsearch.upgrades;
import com.carrotsearch.randomizedtesting.annotations.Name;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.network.NetworkAddress;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.xcontent.XContentType;
import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import static org.elasticsearch.upgrades.LogsIndexModeRollingUpgradeIT.getWriteBackingIndex;
import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.createTemplate;
import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.getIndexSettingsWithDefaults;
import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.startTrial;
import static org.elasticsearch.upgrades.TsdbIT.TEMPLATE;
import static org.elasticsearch.upgrades.TsdbIT.formatInstant;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@ -194,4 +199,51 @@ public class TsdbIndexingRollingUpgradeIT extends AbstractRollingUpgradeWithSecu
assertThat(maxTx, notNullValue());
}
protected static void startTrial() throws IOException {
Request startTrial = new Request("POST", "/_license/start_trial");
startTrial.addParameter("acknowledge", "true");
try {
assertOK(client().performRequest(startTrial));
} catch (ResponseException e) {
var responseBody = entityAsMap(e.getResponse());
String error = ObjectPath.evaluate(responseBody, "error_message");
assertThat(error, containsString("Trial was already activated."));
}
}
static Map<String, Object> getIndexSettingsWithDefaults(String index) throws IOException {
Request request = new Request("GET", "/" + index + "/_settings");
request.addParameter("flat_settings", "true");
request.addParameter("include_defaults", "true");
Response response = client().performRequest(request);
try (InputStream is = response.getEntity().getContent()) {
return XContentHelper.convertToMap(
XContentType.fromMediaType(response.getEntity().getContentType().getValue()).xContent(),
is,
true
);
}
}
static void createTemplate(String dataStreamName, String id, String template) throws IOException {
final String INDEX_TEMPLATE = """
{
"index_patterns": ["$DATASTREAM"],
"template": $TEMPLATE,
"data_stream": {
}
}""";
var putIndexTemplateRequest = new Request("POST", "/_index_template/" + id);
putIndexTemplateRequest.setJsonEntity(INDEX_TEMPLATE.replace("$TEMPLATE", template).replace("$DATASTREAM", dataStreamName));
assertOK(client().performRequest(putIndexTemplateRequest));
}
@SuppressWarnings("unchecked")
static String getWriteBackingIndex(final RestClient client, final String dataStreamName, int backingIndex) throws IOException {
final Request request = new Request("GET", "_data_stream/" + dataStreamName);
final List<Object> dataStreams = (List<Object>) entityAsMap(client.performRequest(request)).get("data_streams");
final Map<String, Object> dataStream = (Map<String, Object>) dataStreams.get(0);
final List<Map<String, String>> backingIndices = (List<Map<String, String>>) dataStream.get("indices");
return backingIndices.get(backingIndex).get("index_name");
}
}

View file

@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-test-artifact-base'
apply plugin: 'elasticsearch.bwc-test'
apply plugin: 'elasticsearch.fwc-test'
apply plugin: 'elasticsearch.bc-upgrade-test'
dependencies {
javaRestTestImplementation project(xpackModule('logsdb'))
javaRestTestImplementation project(':test:test-clusters')
javaRestTestImplementation testArtifact(project(':qa:rolling-upgrade'), 'javaRestTest')
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
javaRestTestImplementation(testArtifact(project(xpackModule('security'))))
}
buildParams.bwcVersions.withWireCompatible { bwcVersion, baseName ->
tasks.register(bwcTaskName(bwcVersion), StandaloneRestIntegTestTask) {
usesBwcDistribution(bwcVersion)
systemProperty("tests.old_cluster_version", bwcVersion)
}
}
tasks.withType(Test).configureEach {
// CI doesn't like it when there's multiple clusters running at once
maxParallelForks = 1
}

View file

@ -15,6 +15,8 @@ import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.network.NetworkAddress;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.time.FormatNames;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.xcontent.XContentType;
@ -28,7 +30,6 @@ import java.util.Map;
import static org.elasticsearch.upgrades.LogsIndexModeRollingUpgradeIT.enableLogsdbByDefault;
import static org.elasticsearch.upgrades.LogsIndexModeRollingUpgradeIT.getWriteBackingIndex;
import static org.elasticsearch.upgrades.TsdbIT.formatInstant;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
@ -265,4 +266,8 @@ public class LogsdbIndexingRollingUpgradeIT extends AbstractRollingUpgradeWithSe
}
}
static String formatInstant(Instant instant) {
return DateFormatter.forPattern(FormatNames.STRICT_DATE_OPTIONAL_TIME.getName()).format(instant);
}
}