Skip to content

Commit f15c31f

Browse files
authored
Improve ESRestTestCase when running with different node versions. (elastic#70361)
Backport of the testing related changes from elastic#70314: Older versions don't support component / composable index templates and/or data streams. Yet the test base class tries to remove objects after each test, which adds a significant number of lines to the log files (which slows the tests down). The ESRestTestCase will now check whether all nodes have a specific version and then decide whether data streams and component / composable index templates will be deleted. Also ensured that the logstash-index-template and security-index-template aren't deleted between tests, these templates are builtin templates that ES will install if missing. So if tests remove these templates between tests then ES will add these template back almost immediately. These causes many log lines and a lot of cluster state updates, which slow tests down. Also removed old debug log config that was enabled to investigate a build failure (elastic#46091), but has been closed. However the debug logging added many lines log lines to the log files. Note this change wasn't part of elastic#70314. Relates to elastic#69973
1 parent 1e4732e commit f15c31f

File tree

2 files changed

+51
-48
lines changed

2 files changed

+51
-48
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,10 +1213,6 @@ private void createConfiguration() {
12131213
// Don't wait for state, just start up quickly. This will also allow new and old nodes in the BWC case to become the master
12141214
baseConfig.put("discovery.initial_state_timeout", "0s");
12151215

1216-
// TODO: Remove these once https://github.com/elastic/elasticsearch/issues/46091 is fixed
1217-
baseConfig.put("logger.org.elasticsearch.action.support.master", "DEBUG");
1218-
baseConfig.put("logger.org.elasticsearch.cluster.coordination", "DEBUG");
1219-
12201216
HashSet<String> overriden = new HashSet<>(baseConfig.keySet());
12211217
overriden.retainAll(settings.keySet());
12221218
overriden.removeAll(OVERRIDABLE_SETTINGS);

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -602,58 +602,63 @@ private void wipeCluster() throws Exception {
602602
* slows down the test because xpack will just recreate
603603
* them.
604604
*/
605-
try {
606-
Request getTemplatesRequest = new Request("GET", "_index_template");
607-
getTemplatesRequest.setOptions(allowTypesRemovalWarnings());
608-
Map<String, Object> composableIndexTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent,
609-
EntityUtils.toString(adminClient().performRequest(getTemplatesRequest).getEntity()), false);
610-
List<String> names = ((List<?>) composableIndexTemplates.get("index_templates")).stream()
611-
.map(ct -> (String) ((Map<?, ?>) ct).get("name"))
612-
.filter(name -> isXPackTemplate(name) == false)
613-
.collect(Collectors.toList());
614-
// Ideally we would want to check the version of the elected master node and
615-
// send the delete request directly to that node.
616-
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_13_0))) {
617-
try {
618-
adminClient().performRequest(new Request("DELETE", "_index_template/" + String.join(",", names)));
619-
} catch (ResponseException e) {
620-
logger.debug(new ParameterizedMessage("unable to remove multiple composable index template {}", names), e);
621-
}
622-
} else {
623-
for (String name : names) {
605+
// In case of bwc testing, if all nodes are before 7.7.0 then no need to attempt to delete component and composable
606+
// index templates, because these were introduced in 7.7.0:
607+
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_7_0))) {
608+
try {
609+
Request getTemplatesRequest = new Request("GET", "_index_template");
610+
getTemplatesRequest.setOptions(allowTypesRemovalWarnings());
611+
Map<String, Object> composableIndexTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent,
612+
EntityUtils.toString(adminClient().performRequest(getTemplatesRequest).getEntity()), false);
613+
List<String> names = ((List<?>) composableIndexTemplates.get("index_templates")).stream()
614+
.map(ct -> (String) ((Map<?, ?>) ct).get("name"))
615+
.filter(name -> isXPackTemplate(name) == false)
616+
.collect(Collectors.toList());
617+
// Ideally we would want to check the version of the elected master node and
618+
// send the delete request directly to that node.
619+
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_13_0))) {
624620
try {
625-
adminClient().performRequest(new Request("DELETE", "_index_template/" + name));
621+
adminClient().performRequest(new Request("DELETE", "_index_template/" + String.join(",", names)));
626622
} catch (ResponseException e) {
627-
logger.debug(new ParameterizedMessage("unable to remove composable index template {}", name), e);
623+
logger.debug(new ParameterizedMessage("unable to remove multiple composable index template {}", names), e);
624+
}
625+
} else {
626+
for (String name : names) {
627+
try {
628+
adminClient().performRequest(new Request("DELETE", "_index_template/" + name));
629+
} catch (ResponseException e) {
630+
logger.debug(new ParameterizedMessage("unable to remove composable index template {}", name), e);
631+
}
628632
}
629633
}
634+
} catch (Exception e) {
635+
logger.debug("ignoring exception removing all composable index templates", e);
636+
// We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
630637
}
631-
} catch (Exception e) {
632-
logger.debug("ignoring exception removing all composable index templates", e);
633-
// We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
634-
}
635-
try {
636-
Request compReq = new Request("GET", "_component_template");
637-
compReq.setOptions(allowTypesRemovalWarnings());
638-
String componentTemplates = EntityUtils.toString(adminClient().performRequest(compReq).getEntity());
639-
Map<String, Object> cTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent, componentTemplates, false);
640-
List<String> names = ((List<?>) cTemplates.get("component_templates")).stream()
641-
.map(ct -> (String) ((Map<?, ?>) ct).get("name"))
642-
.collect(Collectors.toList());
643-
for (String componentTemplate : names) {
644-
try {
645-
if (isXPackTemplate(componentTemplate)) {
646-
continue;
638+
try {
639+
Request compReq = new Request("GET", "_component_template");
640+
compReq.setOptions(allowTypesRemovalWarnings());
641+
String componentTemplates = EntityUtils.toString(adminClient().performRequest(compReq).getEntity());
642+
Map<String, Object> cTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent, componentTemplates, false);
643+
List<String> names = ((List<?>) cTemplates.get("component_templates")).stream()
644+
.map(ct -> (String) ((Map<?, ?>) ct).get("name"))
645+
.collect(Collectors.toList());
646+
for (String componentTemplate : names) {
647+
try {
648+
if (isXPackTemplate(componentTemplate)) {
649+
continue;
650+
}
651+
adminClient().performRequest(new Request("DELETE", "_component_template/" + componentTemplate));
652+
} catch (ResponseException e) {
653+
logger.debug(new ParameterizedMessage("unable to remove component template {}", componentTemplate), e);
647654
}
648-
adminClient().performRequest(new Request("DELETE", "_component_template/" + componentTemplate));
649-
} catch (ResponseException e) {
650-
logger.debug(new ParameterizedMessage("unable to remove component template {}", componentTemplate), e);
651655
}
656+
} catch (Exception e) {
657+
logger.debug("ignoring exception removing all component templates", e);
658+
// We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
652659
}
653-
} catch (Exception e) {
654-
logger.debug("ignoring exception removing all component templates", e);
655-
// We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
656660
}
661+
// Always check for legacy templates:
657662
Request getLegacyTemplatesRequest = new Request("GET", "_template");
658663
getLegacyTemplatesRequest.setOptions(allowTypesRemovalWarnings());
659664
Map<String, Object> legacyTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent,
@@ -730,7 +735,7 @@ protected static void wipeAllIndices() throws IOException {
730735

731736
protected static void wipeDataStreams() throws IOException {
732737
try {
733-
if (hasXPack()) {
738+
if (hasXPack() && nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_9_0))) {
734739
adminClient().performRequest(new Request("DELETE", "_data_stream/*?expand_wildcards=all"));
735740
}
736741
} catch (ResponseException e) {
@@ -1442,6 +1447,8 @@ protected static boolean isXPackTemplate(String name) {
14421447
case "synthetics-mappings":
14431448
case ".snapshot-blob-cache":
14441449
case ".deprecation-indexing-template":
1450+
case "logstash-index-template":
1451+
case "security-index-template":
14451452
return true;
14461453
default:
14471454
return false;

0 commit comments

Comments
 (0)