From f9e5db17256995b5f3a5a5eb9cd13c392a27f1a7 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 21 Mar 2017 17:19:32 -0700 Subject: [PATCH 1/2] Test: Add dump of integ test cluster logs on failure This commit adds a build listener to the integ test runner which will print out an excerpt of the logs from the integ test cluster if the test run fails. There are future improvements that can be made (for example, to dump excerpts from dependent clusters like in tribe node tests), but this is a start, and would help with simple rest tests failures that we currently don't know what actually happened on the node. --- .../gradle/test/RestIntegTestTask.groovy | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy index 075e8129e6fa8..6469605839317 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy @@ -21,11 +21,18 @@ package org.elasticsearch.gradle.test import com.carrotsearch.gradle.junit4.RandomizedTestingTask import org.elasticsearch.gradle.BuildPlugin import org.gradle.api.DefaultTask +import org.gradle.api.GradleException import org.gradle.api.Task +import org.gradle.api.execution.TaskExecutionAdapter import org.gradle.api.internal.tasks.options.Option import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.tasks.Input -import org.gradle.util.ConfigureUtil +import org.gradle.api.tasks.TaskState + +import java.nio.charset.StandardCharsets +import java.nio.file.Files +import java.nio.file.Paths +import java.util.stream.Stream /** * A wrapper task around setting up a cluster and running rest tests. @@ -71,6 +78,24 @@ public class RestIntegTestTask extends DefaultTask { // both as separate sysprops runner.systemProperty('tests.cluster', "${-> nodes[0].transportUri()}") + // dump errors and warnings from cluster log on failure + TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter() { + @Override + void afterExecute(Task task, TaskState state) { + if (state.failure != null) { + for (NodeInfo nodeInfo : nodes) { + printLogExcerpt(nodeInfo) + } + } + } + } + runner.doFirst { + project.gradle.addListener(logDumpListener) + } + runner.doLast { + project.gradle.removeListener(logDumpListener) + } + // copy the rest spec/tests into the test resources RestSpecHack.configureDependencies(project) project.afterEvaluate { @@ -126,4 +151,42 @@ public class RestIntegTestTask extends DefaultTask { public Task mustRunAfter(Object... tasks) { clusterInit.mustRunAfter(tasks) } + + /** Print out an excerpt of the log from the given node. */ + protected static void printLogExcerpt(NodeInfo nodeInfo) { + File logFile = new File(nodeInfo.homeDir, "logs/${nodeInfo.clusterName}.log") + println("\nCluster ${nodeInfo.clusterName} - node ${nodeInfo.nodeNum} log excerpt:") + println("(full log at ${logFile})") + println('-----------------------------------------') + Stream stream = Files.lines(logFile.toPath(), StandardCharsets.UTF_8) + try { + boolean inStartup = true + boolean inExcerpt = false + int linesSkipped = 0 + for (String line : stream) { + if (line.startsWith("[")) { + inExcerpt = false // clear with the next log message + } + if (line =~ /(\[WARN\])|(\[ERROR\])/) { + inExcerpt = true // show warnings and errors + } + if (inStartup || inExcerpt) { + if (linesSkipped != 0) { + println("... SKIPPED ${linesSkipped} LINES ...") + } + println(line) + linesSkipped = 0 + } else { + ++linesSkipped + } + if (line =~ /recovered \[\d+\] indices into cluster_state/) { + inStartup = false + } + } + } finally { + stream.close() + } + println('=========================================') + + } } From e50096e64f1c9be77c0685ec53ca8d303c7ec9d6 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 21 Mar 2017 17:24:08 -0700 Subject: [PATCH 2/2] cleanup imports --- .../org/elasticsearch/gradle/test/RestIntegTestTask.groovy | 2 -- 1 file changed, 2 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy index 6469605839317..98ee91e37a8ab 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy @@ -21,7 +21,6 @@ package org.elasticsearch.gradle.test import com.carrotsearch.gradle.junit4.RandomizedTestingTask import org.elasticsearch.gradle.BuildPlugin import org.gradle.api.DefaultTask -import org.gradle.api.GradleException import org.gradle.api.Task import org.gradle.api.execution.TaskExecutionAdapter import org.gradle.api.internal.tasks.options.Option @@ -31,7 +30,6 @@ import org.gradle.api.tasks.TaskState import java.nio.charset.StandardCharsets import java.nio.file.Files -import java.nio.file.Paths import java.util.stream.Stream /**