Skip to content

Commit 29db3f3

Browse files
authored
[Build] Extract logsdb rolling-upgrade tests (#129673)
- introduce separate subproject for testing logsdb rolling-upgrade tests - should reduce :qa:rolling-upgrade test task durations
1 parent 2b8d9df commit 29db3f3

File tree

6 files changed

+95
-5
lines changed

6 files changed

+95
-5
lines changed

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/TsdbIndexingRollingUpgradeIT.java

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@
1212
import com.carrotsearch.randomizedtesting.annotations.Name;
1313

1414
import org.elasticsearch.client.Request;
15+
import org.elasticsearch.client.Response;
16+
import org.elasticsearch.client.ResponseException;
17+
import org.elasticsearch.client.RestClient;
1518
import org.elasticsearch.common.network.NetworkAddress;
19+
import org.elasticsearch.common.xcontent.XContentHelper;
1620
import org.elasticsearch.test.rest.ObjectPath;
21+
import org.elasticsearch.xcontent.XContentType;
1722

23+
import java.io.IOException;
24+
import java.io.InputStream;
1825
import java.time.Instant;
26+
import java.util.List;
1927
import java.util.Locale;
2028
import java.util.Map;
2129

22-
import static org.elasticsearch.upgrades.LogsIndexModeRollingUpgradeIT.getWriteBackingIndex;
23-
import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.createTemplate;
24-
import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.getIndexSettingsWithDefaults;
25-
import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.startTrial;
2630
import static org.elasticsearch.upgrades.TsdbIT.TEMPLATE;
2731
import static org.elasticsearch.upgrades.TsdbIT.formatInstant;
32+
import static org.hamcrest.Matchers.containsString;
2833
import static org.hamcrest.Matchers.equalTo;
2934
import static org.hamcrest.Matchers.greaterThan;
3035
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -194,4 +199,51 @@ void query(String dataStreamName) throws Exception {
194199
assertThat(maxTx, notNullValue());
195200
}
196201

202+
protected static void startTrial() throws IOException {
203+
Request startTrial = new Request("POST", "/_license/start_trial");
204+
startTrial.addParameter("acknowledge", "true");
205+
try {
206+
assertOK(client().performRequest(startTrial));
207+
} catch (ResponseException e) {
208+
var responseBody = entityAsMap(e.getResponse());
209+
String error = ObjectPath.evaluate(responseBody, "error_message");
210+
assertThat(error, containsString("Trial was already activated."));
211+
}
212+
}
213+
214+
static Map<String, Object> getIndexSettingsWithDefaults(String index) throws IOException {
215+
Request request = new Request("GET", "/" + index + "/_settings");
216+
request.addParameter("flat_settings", "true");
217+
request.addParameter("include_defaults", "true");
218+
Response response = client().performRequest(request);
219+
try (InputStream is = response.getEntity().getContent()) {
220+
return XContentHelper.convertToMap(
221+
XContentType.fromMediaType(response.getEntity().getContentType().getValue()).xContent(),
222+
is,
223+
true
224+
);
225+
}
226+
}
227+
228+
static void createTemplate(String dataStreamName, String id, String template) throws IOException {
229+
final String INDEX_TEMPLATE = """
230+
{
231+
"index_patterns": ["$DATASTREAM"],
232+
"template": $TEMPLATE,
233+
"data_stream": {
234+
}
235+
}""";
236+
var putIndexTemplateRequest = new Request("POST", "/_index_template/" + id);
237+
putIndexTemplateRequest.setJsonEntity(INDEX_TEMPLATE.replace("$TEMPLATE", template).replace("$DATASTREAM", dataStreamName));
238+
assertOK(client().performRequest(putIndexTemplateRequest));
239+
}
240+
241+
@SuppressWarnings("unchecked")
242+
static String getWriteBackingIndex(final RestClient client, final String dataStreamName, int backingIndex) throws IOException {
243+
final Request request = new Request("GET", "_data_stream/" + dataStreamName);
244+
final List<Object> dataStreams = (List<Object>) entityAsMap(client.performRequest(request)).get("data_streams");
245+
final Map<String, Object> dataStream = (Map<String, Object>) dataStreams.get(0);
246+
final List<Map<String, String>> backingIndices = (List<Map<String, String>>) dataStream.get("indices");
247+
return backingIndices.get(backingIndex).get("index_name");
248+
}
197249
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
8+
9+
apply plugin: 'elasticsearch.internal-java-rest-test'
10+
apply plugin: 'elasticsearch.internal-test-artifact-base'
11+
apply plugin: 'elasticsearch.bwc-test'
12+
apply plugin: 'elasticsearch.fwc-test'
13+
apply plugin: 'elasticsearch.bc-upgrade-test'
14+
15+
dependencies {
16+
javaRestTestImplementation project(xpackModule('logsdb'))
17+
javaRestTestImplementation project(':test:test-clusters')
18+
javaRestTestImplementation testArtifact(project(':qa:rolling-upgrade'), 'javaRestTest')
19+
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
20+
javaRestTestImplementation(testArtifact(project(xpackModule('security'))))
21+
}
22+
23+
buildParams.bwcVersions.withWireCompatible { bwcVersion, baseName ->
24+
tasks.register(bwcTaskName(bwcVersion), StandaloneRestIntegTestTask) {
25+
usesBwcDistribution(bwcVersion)
26+
systemProperty("tests.old_cluster_version", bwcVersion)
27+
}
28+
}
29+
30+
tasks.withType(Test).configureEach {
31+
// CI doesn't like it when there's multiple clusters running at once
32+
maxParallelForks = 1
33+
}

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/LogsdbIndexingRollingUpgradeIT.java renamed to x-pack/plugin/logsdb/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/LogsdbIndexingRollingUpgradeIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import org.elasticsearch.client.Response;
1616
import org.elasticsearch.client.ResponseException;
1717
import org.elasticsearch.common.network.NetworkAddress;
18+
import org.elasticsearch.common.time.DateFormatter;
19+
import org.elasticsearch.common.time.FormatNames;
1820
import org.elasticsearch.common.xcontent.XContentHelper;
1921
import org.elasticsearch.test.rest.ObjectPath;
2022
import org.elasticsearch.xcontent.XContentType;
@@ -28,7 +30,6 @@
2830

2931
import static org.elasticsearch.upgrades.LogsIndexModeRollingUpgradeIT.enableLogsdbByDefault;
3032
import static org.elasticsearch.upgrades.LogsIndexModeRollingUpgradeIT.getWriteBackingIndex;
31-
import static org.elasticsearch.upgrades.TsdbIT.formatInstant;
3233
import static org.hamcrest.Matchers.containsString;
3334
import static org.hamcrest.Matchers.equalTo;
3435
import static org.hamcrest.Matchers.greaterThan;
@@ -265,4 +266,8 @@ static Map<String, Object> getIndexSettingsWithDefaults(String index) throws IOE
265266
}
266267
}
267268

269+
static String formatInstant(Instant instant) {
270+
return DateFormatter.forPattern(FormatNames.STRICT_DATE_OPTIONAL_TIME.getName()).format(instant);
271+
}
272+
268273
}

0 commit comments

Comments
 (0)