Skip to content

Commit 0c1dc3a

Browse files
authored
Improve ESRestTestCase when running with different node versions. (#70364)
Backporting #70361 to 7.11 branch. Backport of the testing related changes from #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 (#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 #70314. Relates to #69973
1 parent 3e20584 commit 0c1dc3a

File tree

2 files changed

+40
-38
lines changed

2 files changed

+40
-38
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
@@ -1203,10 +1203,6 @@ private void createConfiguration() {
12031203
// 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
12041204
baseConfig.put("discovery.initial_state_timeout", "0s");
12051205

1206-
// TODO: Remove these once https://github.com/elastic/elasticsearch/issues/46091 is fixed
1207-
baseConfig.put("logger.org.elasticsearch.action.support.master", "DEBUG");
1208-
baseConfig.put("logger.org.elasticsearch.cluster.coordination", "DEBUG");
1209-
12101206
HashSet<String> overriden = new HashSet<>(baseConfig.keySet());
12111207
overriden.retainAll(settings.keySet());
12121208
overriden.removeAll(OVERRIDABLE_SETTINGS);

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

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -600,50 +600,55 @@ private void wipeCluster() throws Exception {
600600
* slows down the test because xpack will just recreate
601601
* them.
602602
*/
603-
try {
604-
Request getTemplatesRequest = new Request("GET", "_index_template");
605-
getTemplatesRequest.setOptions(allowTypesRemovalWarnings());
606-
Map<String, Object> composableIndexTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent,
607-
EntityUtils.toString(adminClient().performRequest(getTemplatesRequest).getEntity()), false);
608-
List<String> names = ((List<?>) composableIndexTemplates.get("index_templates")).stream()
609-
.map(ct -> (String) ((Map<?, ?>) ct).get("name"))
610-
.collect(Collectors.toList());
611-
for (String name : names) {
612-
if (isXPackTemplate(name)) {
603+
// In case of bwc testing, if all nodes are before 7.7.0 then no need to attempt to delete component and composable
604+
// index templates, because these were introduced in 7.7.0:
605+
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_7_0))) {
606+
try {
607+
Request getTemplatesRequest = new Request("GET", "_index_template");
608+
getTemplatesRequest.setOptions(allowTypesRemovalWarnings());
609+
Map<String, Object> composableIndexTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent,
610+
EntityUtils.toString(adminClient().performRequest(getTemplatesRequest).getEntity()), false);
611+
List<String> names = ((List<?>) composableIndexTemplates.get("index_templates")).stream()
612+
.map(ct -> (String) ((Map<?, ?>) ct).get("name"))
613+
.collect(Collectors.toList());
614+
for (String name : names) {
615+
if (isXPackTemplate(name)) {
613616
continue;
614-
}
617+
}
615618
try {
616619
adminClient().performRequest(new Request("DELETE", "_index_template/" + name));
617620
} catch (ResponseException e) {
618621
logger.debug(new ParameterizedMessage("unable to remove index template {}", name), e);
622+
}
619623
}
624+
} catch (Exception e) {
625+
logger.debug("ignoring exception removing all composable index templates", e);
626+
// We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
620627
}
621-
} catch (Exception e) {
622-
logger.debug("ignoring exception removing all composable index templates", e);
623-
// We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
624-
}
625-
try {
626-
Request compReq = new Request("GET", "_component_template");
627-
compReq.setOptions(allowTypesRemovalWarnings());
628-
String componentTemplates = EntityUtils.toString(adminClient().performRequest(compReq).getEntity());
629-
Map<String, Object> cTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent, componentTemplates, false);
630-
List<String> names = ((List<?>) cTemplates.get("component_templates")).stream()
631-
.map(ct -> (String) ((Map<?, ?>) ct).get("name"))
632-
.collect(Collectors.toList());
633-
for (String componentTemplate : names) {
634-
try {
635-
if (isXPackTemplate(componentTemplate)) {
636-
continue;
628+
try {
629+
Request compReq = new Request("GET", "_component_template");
630+
compReq.setOptions(allowTypesRemovalWarnings());
631+
String componentTemplates = EntityUtils.toString(adminClient().performRequest(compReq).getEntity());
632+
Map<String, Object> cTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent, componentTemplates, false);
633+
List<String> names = ((List<?>) cTemplates.get("component_templates")).stream()
634+
.map(ct -> (String) ((Map<?, ?>) ct).get("name"))
635+
.collect(Collectors.toList());
636+
for (String componentTemplate : names) {
637+
try {
638+
if (isXPackTemplate(componentTemplate)) {
639+
continue;
640+
}
641+
adminClient().performRequest(new Request("DELETE", "_component_template/" + componentTemplate));
642+
} catch (ResponseException e) {
643+
logger.debug(new ParameterizedMessage("unable to remove component template {}", componentTemplate), e);
637644
}
638-
adminClient().performRequest(new Request("DELETE", "_component_template/" + componentTemplate));
639-
} catch (ResponseException e) {
640-
logger.debug(new ParameterizedMessage("unable to remove component template {}", componentTemplate), e);
641645
}
646+
} catch (Exception e) {
647+
logger.debug("ignoring exception removing all component templates", e);
648+
// We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
642649
}
643-
} catch (Exception e) {
644-
logger.debug("ignoring exception removing all component templates", e);
645-
// We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
646650
}
651+
// Always check for legacy templates:
647652
Request getLegacyTemplatesRequest = new Request("GET", "_template");
648653
getLegacyTemplatesRequest.setOptions(allowTypesRemovalWarnings());
649654
Map<String, Object> legacyTemplates = XContentHelper.convertToMap(JsonXContent.jsonXContent,
@@ -720,7 +725,7 @@ protected static void wipeAllIndices() throws IOException {
720725

721726
protected static void wipeDataStreams() throws IOException {
722727
try {
723-
if (hasXPack()) {
728+
if (hasXPack() && nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_9_0))) {
724729
adminClient().performRequest(new Request("DELETE", "_data_stream/*?expand_wildcards=all"));
725730
}
726731
} catch (ResponseException e) {
@@ -1412,6 +1417,7 @@ protected static boolean isXPackTemplate(String name) {
14121417
case "synthetics-mappings":
14131418
case ".snapshot-blob-cache":
14141419
case ".deprecation-indexing-template":
1420+
case "security-index-template":
14151421
return true;
14161422
default:
14171423
return false;

0 commit comments

Comments
 (0)