23
23
import org .elasticsearch .gradle .VersionProperties ;
24
24
import org .elasticsearch .gradle .http .WaitForHttpResource ;
25
25
import org .elasticsearch .gradle .info .BuildParams ;
26
+ import org .elasticsearch .gradle .util .Pair ;
26
27
import org .gradle .api .Action ;
27
28
import org .gradle .api .Named ;
28
29
import org .gradle .api .NamedDomainObjectContainer ;
84
85
import java .util .stream .Stream ;
85
86
86
87
import static java .util .Objects .requireNonNull ;
88
+ import static java .util .Optional .ofNullable ;
87
89
88
90
public class ElasticsearchNode implements TestClusterConfiguration {
89
91
@@ -986,7 +988,7 @@ private void logProcessInfo(String prefix, ProcessHandle.Info info) {
986
988
}
987
989
988
990
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 <>();
990
992
LinkedList <String > ring = new LinkedList <>();
991
993
try (LineNumberReader reader = new LineNumberReader (Files .newBufferedReader (from ))) {
992
994
for (String line = reader .readLine (); line != null ; line = reader .readLine ()) {
@@ -998,10 +1000,18 @@ private void logFileContents(String description, Path from, boolean tailLogs) {
998
1000
lineToAdd = line ;
999
1001
// check to see if the previous message (possibly combined from multiple lines) was an error or
1000
1002
// 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
+ );
1005
1015
}
1006
1016
} else {
1007
1017
// 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) {
1034
1044
}
1035
1045
if (errorsAndWarnings .isEmpty () == false ) {
1036
1046
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 ↑" );
1041
1051
}
1042
1052
});
1043
1053
}
0 commit comments