22
22
import org .elasticsearch .gradle .VersionProperties ;
23
23
import org .elasticsearch .gradle .http .WaitForHttpResource ;
24
24
import org .elasticsearch .gradle .info .BuildParams ;
25
+ import org .elasticsearch .gradle .util .Pair ;
25
26
import org .gradle .api .Action ;
26
27
import org .gradle .api .Named ;
27
28
import org .gradle .api .NamedDomainObjectContainer ;
83
84
import java .util .stream .Stream ;
84
85
85
86
import static java .util .Objects .requireNonNull ;
87
+ import static java .util .Optional .ofNullable ;
86
88
87
89
public class ElasticsearchNode implements TestClusterConfiguration {
88
90
@@ -948,7 +950,7 @@ private void logProcessInfo(String prefix, ProcessHandle.Info info) {
948
950
}
949
951
950
952
private void logFileContents (String description , Path from , boolean tailLogs ) {
951
- final Map <String , Integer > errorsAndWarnings = new LinkedHashMap <>();
953
+ final Map <String , Pair < String , Integer > > errorsAndWarnings = new LinkedHashMap <>();
952
954
LinkedList <String > ring = new LinkedList <>();
953
955
try (LineNumberReader reader = new LineNumberReader (Files .newBufferedReader (from ))) {
954
956
for (String line = reader .readLine (); line != null ; line = reader .readLine ()) {
@@ -960,10 +962,18 @@ private void logFileContents(String description, Path from, boolean tailLogs) {
960
962
lineToAdd = line ;
961
963
// check to see if the previous message (possibly combined from multiple lines) was an error or
962
964
// warning as we want to show all of them
963
- String previousMessage = normalizeLogLine (ring .getLast ());
964
- if (MESSAGES_WE_DONT_CARE_ABOUT .stream ().noneMatch (previousMessage ::contains )
965
- && (previousMessage .contains ("ERROR" ) || previousMessage .contains ("WARN" ))) {
966
- errorsAndWarnings .put (ring .getLast (), errorsAndWarnings .getOrDefault (previousMessage , 0 ) + 1 );
965
+ String normalizedMessage = normalizeLogLine (ring .getLast ());
966
+ if (MESSAGES_WE_DONT_CARE_ABOUT .stream ().noneMatch (normalizedMessage ::contains )
967
+ && (normalizedMessage .contains ("ERROR" ) || normalizedMessage .contains ("WARN" ))) {
968
+
969
+ // De-duplicate repeated errors
970
+ errorsAndWarnings .put (
971
+ normalizedMessage ,
972
+ Pair .of (
973
+ ring .getLast (), // Original, non-normalized message (so we keep the first timestamp)
974
+ ofNullable (errorsAndWarnings .get (normalizedMessage )).map (p -> p .right () + 1 ).orElse (1 )
975
+ )
976
+ );
967
977
}
968
978
} else {
969
979
// We combine multi line log messages to make sure we never break exceptions apart
@@ -996,10 +1006,10 @@ private void logFileContents(String description, Path from, boolean tailLogs) {
996
1006
}
997
1007
if (errorsAndWarnings .isEmpty () == false ) {
998
1008
LOGGER .lifecycle ("\n » ↓ errors and warnings from " + from + " ↓" );
999
- errorsAndWarnings .forEach ((message , count ) -> {
1000
- LOGGER .lifecycle ("» " + message .replace ("\n " , "\n » " ));
1001
- if (count > 1 ) {
1002
- LOGGER .lifecycle ("» ↑ repeated " + count + " times ↑" );
1009
+ errorsAndWarnings .forEach ((key , pair ) -> {
1010
+ LOGGER .lifecycle ("» " + pair . left () .replace ("\n " , "\n » " ));
1011
+ if (pair . right () > 1 ) {
1012
+ LOGGER .lifecycle ("» ↑ repeated " + pair . right () + " times ↑" );
1003
1013
}
1004
1014
});
1005
1015
}
0 commit comments