Skip to content

Commit

Permalink
[FLINK-8070][yarn][tests] Print errors found in log files
Browse files Browse the repository at this point in the history
This closes apache#5012.
  • Loading branch information
zentol committed Nov 22, 2017
1 parent c6879cd commit 7a434c3
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -307,6 +308,7 @@ public static void ensureNoProhibitedStringInLogFiles(final String[] prohibited,
Assert.assertTrue("Expecting directory " + cwd.getAbsolutePath() + " to exist", cwd.exists());
Assert.assertTrue("Expecting directory " + cwd.getAbsolutePath() + " to be a directory", cwd.isDirectory());

List<String> prohibitedExcerpts = new ArrayList<>();
File foundFile = findFile(cwd.getAbsolutePath(), new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
Expand All @@ -331,6 +333,24 @@ public boolean accept(File dir, String name) {
// logging in FATAL to see the actual message in TRAVIS tests.
Marker fatal = MarkerFactory.getMarker("FATAL");
LOG.error(fatal, "Prohibited String '{}' in line '{}'", aProhibited, lineFromFile);

StringBuilder logExcerpt = new StringBuilder();

logExcerpt.append(System.lineSeparator());
logExcerpt.append(lineFromFile);
logExcerpt.append(System.lineSeparator());
// extract potential stack trace from log
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (!line.isEmpty() && (Character.isWhitespace(line.charAt(0)) || line.startsWith("Caused by"))) {
logExcerpt.append(line);
logExcerpt.append(System.lineSeparator());
} else {
break;
}
}
prohibitedExcerpts.add(logExcerpt.toString());

return true;
}
}
Expand All @@ -355,7 +375,9 @@ public boolean accept(File dir, String name) {
while (scanner.hasNextLine()) {
LOG.warn("LINE: " + scanner.nextLine());
}
Assert.fail("Found a file " + foundFile + " with a prohibited string: " + Arrays.toString(prohibited));
Assert.fail(
"Found a file " + foundFile + " with a prohibited string (one of " + Arrays.toString(prohibited) + "). " +
"Excerpts:" + System.lineSeparator() + prohibitedExcerpts);
}
}

Expand Down

0 comments on commit 7a434c3

Please sign in to comment.