Skip to content

Commit

Permalink
Tweak LogsdbIndexingRollingUpgradeIT and TsdbIndexingRollingUpgradeIT
Browse files Browse the repository at this point in the history
to fix following test bugs:
* Deal with trail already started error.
* Ensure k8s.pod.name field is mapped as keyword

Closes elastic#115755, elastic#115756, elastic#115757, elastic#115758, elastic#115758
  • Loading branch information
martijnvg committed Oct 28, 2024
1 parent ddad156 commit fb29905
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

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.xcontent.XContentHelper;
import org.elasticsearch.test.rest.ObjectPath;
Expand All @@ -21,6 +22,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.util.Locale;
import java.util.Map;

import static org.elasticsearch.upgrades.LogsIndexModeRollingUpgradeIT.enableLogsdbByDefault;
Expand Down Expand Up @@ -73,7 +75,7 @@ public void testIndexing() throws Exception {
if (isOldCluster()) {
startTrial();
enableLogsdbByDefault();
createTemplate(dataStreamName, "3", TEMPLATE);
createTemplate(dataStreamName, getClass().getSimpleName().toLowerCase(Locale.ROOT), TEMPLATE);

Instant startTime = Instant.now().minusSeconds(60 * 60);
bulkIndex(dataStreamName, 4, 1024, startTime);
Expand Down Expand Up @@ -233,7 +235,13 @@ void query(String dataStreamName) throws Exception {
protected static void startTrial() throws IOException {
Request startTrial = new Request("POST", "/_license/start_trial");
startTrial.addParameter("acknowledge", "true");
assertOK(client().performRequest(startTrial));
try {
assertOK(client().performRequest(startTrial));
} catch (ResponseException e) {
var responseBody = entityAsMap(e.getResponse());
String error = ObjectPath.evaluate(responseBody, "error_message");
assertThat(error, equalTo("Trial was already activated."));
}
}

static Map<String, Object> getIndexSettingsWithDefaults(String index) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
import org.elasticsearch.test.rest.ObjectPath;

import java.time.Instant;
import java.util.Locale;
import java.util.Map;

import static org.elasticsearch.upgrades.LogsIndexModeRollingUpgradeIT.getWriteBackingIndex;
import static org.elasticsearch.upgrades.LogsdbIndexingRollingUpgradeIT.*;
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.equalTo;
Expand All @@ -42,7 +45,7 @@ public void testIndexing() throws Exception {
String dataStreamName = "k9s";
if (isOldCluster()) {
startTrial();
createTemplate(dataStreamName, "2", TEMPLATE);
createTemplate(dataStreamName, getClass().getSimpleName().toLowerCase(Locale.ROOT), TEMPLATE);

Instant startTime = Instant.now().minusSeconds(60 * 60);
bulkIndex(dataStreamName, 4, 1024, startTime);
Expand All @@ -52,6 +55,13 @@ public void testIndexing() throws Exception {
assertThat(((Map<?, ?>) settings.get("settings")).get("index.mode"), equalTo("time_series"));
assertThat(((Map<?, ?>) settings.get("defaults")).get("index.mapping.source.mode"), equalTo("SYNTHETIC"));

var mapping = getIndexMappingAsMap(firstBackingIndex);
assertThat(
"incorrect k8s.pod.name field in mapping:" + mapping,
"keyword",
equalTo(ObjectPath.evaluate(mapping, "properties.k8s.properties.pod.properties.name.type"))
);

ensureGreen(dataStreamName);
search(dataStreamName);
query(dataStreamName);
Expand Down

0 comments on commit fb29905

Please sign in to comment.