Skip to content

Commit d93aaf3

Browse files
committed
Fix handling of duplicate error messages in test cluster logs (elastic#69494)
1 parent 6d77393 commit d93aaf3

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.gradle.VersionProperties;
2424
import org.elasticsearch.gradle.http.WaitForHttpResource;
2525
import org.elasticsearch.gradle.info.BuildParams;
26+
import org.elasticsearch.gradle.util.Pair;
2627
import org.gradle.api.Action;
2728
import org.gradle.api.Named;
2829
import org.gradle.api.NamedDomainObjectContainer;
@@ -84,6 +85,7 @@
8485
import java.util.stream.Stream;
8586

8687
import static java.util.Objects.requireNonNull;
88+
import static java.util.Optional.ofNullable;
8789

8890
public class ElasticsearchNode implements TestClusterConfiguration {
8991

@@ -986,7 +988,7 @@ private void logProcessInfo(String prefix, ProcessHandle.Info info) {
986988
}
987989

988990
private void logFileContents(String description, Path from, boolean tailLogs) {
989-
final Map<String, Integer> errorsAndWarnings = new LinkedHashMap<>();
991+
final Map<String, Pair<String, Integer>> errorsAndWarnings = new LinkedHashMap<>();
990992
LinkedList<String> ring = new LinkedList<>();
991993
try (LineNumberReader reader = new LineNumberReader(Files.newBufferedReader(from))) {
992994
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
@@ -998,10 +1000,18 @@ private void logFileContents(String description, Path from, boolean tailLogs) {
9981000
lineToAdd = line;
9991001
// check to see if the previous message (possibly combined from multiple lines) was an error or
10001002
// warning as we want to show all of them
1001-
String previousMessage = normalizeLogLine(ring.getLast());
1002-
if (MESSAGES_WE_DONT_CARE_ABOUT.stream().noneMatch(previousMessage::contains)
1003-
&& (previousMessage.contains("ERROR") || previousMessage.contains("WARN"))) {
1004-
errorsAndWarnings.put(ring.getLast(), errorsAndWarnings.getOrDefault(previousMessage, 0) + 1);
1003+
String normalizedMessage = normalizeLogLine(ring.getLast());
1004+
if (MESSAGES_WE_DONT_CARE_ABOUT.stream().noneMatch(normalizedMessage::contains)
1005+
&& (normalizedMessage.contains("ERROR") || normalizedMessage.contains("WARN"))) {
1006+
1007+
// De-duplicate repeated errors
1008+
errorsAndWarnings.put(
1009+
normalizedMessage,
1010+
Pair.of(
1011+
ring.getLast(), // Original, non-normalized message (so we keep the first timestamp)
1012+
ofNullable(errorsAndWarnings.get(normalizedMessage)).map(p -> p.right() + 1).orElse(1)
1013+
)
1014+
);
10051015
}
10061016
} else {
10071017
// We combine multi line log messages to make sure we never break exceptions apart
@@ -1034,10 +1044,10 @@ private void logFileContents(String description, Path from, boolean tailLogs) {
10341044
}
10351045
if (errorsAndWarnings.isEmpty() == false) {
10361046
LOGGER.lifecycle("\n» ↓ errors and warnings from " + from + " ↓");
1037-
errorsAndWarnings.forEach((message, count) -> {
1038-
LOGGER.lifecycle("» " + message.replace("\n", "\n» "));
1039-
if (count > 1) {
1040-
LOGGER.lifecycle("» ↑ repeated " + count + " times ↑");
1047+
errorsAndWarnings.forEach((key, pair) -> {
1048+
LOGGER.lifecycle("» " + pair.left().replace("\n", "\n» "));
1049+
if (pair.right() > 1) {
1050+
LOGGER.lifecycle("» ↑ repeated " + pair.right() + " times ↑");
10411051
}
10421052
});
10431053
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.gradle.util;
10+
11+
public class Pair<L, R> {
12+
private final L left;
13+
private final R right;
14+
15+
private Pair(L left, R right) {
16+
this.left = left;
17+
this.right = right;
18+
}
19+
20+
public static <L, R> Pair<L, R> of(L left, R right) {
21+
return new Pair<>(left, right);
22+
}
23+
24+
public L left() {
25+
return left;
26+
}
27+
28+
public R right() {
29+
return right;
30+
}
31+
}

0 commit comments

Comments
 (0)