Skip to content

Commit 32025ad

Browse files
Reduce logspam of exception stacktraces for logs that can't be read
Logs not being able to be read is a common occurence when reading logs: a previous container often doesn't actually exist. There is no easy way to detect this case without trying to read the logs
1 parent 2a08022 commit 32025ad

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

contentgrid-junit-jupiter-k8s/src/main/java/com/contentgrid/junit/jupiter/k8s/wait/resource/PodAwaitableResource.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private Stream<? extends LogLine> readContainer(PodResource resource, String con
5050
.getLogReader()
5151
);
5252
} catch(KubernetesClientException exception) {
53-
log.warn("Failed to read logs from {} container {}", this, containerName, exception);
53+
logReadException(containerName, exception);
5454
}
5555

5656
try {
@@ -62,11 +62,19 @@ private Stream<? extends LogLine> readContainer(PodResource resource, String con
6262
.getLogReader()
6363
);
6464
} catch(KubernetesClientException exception) {
65-
log.warn("Failed to read logs from {} container {}", this, containerName, exception);
65+
logReadException(containerName, exception);
6666
}
6767
return logReaders.stream().flatMap(logReader -> readLogs(containerName, logReader));
6868
}
6969

70+
private void logReadException(String containerName, KubernetesClientException exception) {
71+
if(log.isTraceEnabled()) {
72+
log.warn("Failed to read logs from {} container {}", this, containerName, exception);
73+
} else {
74+
log.warn("Failed to read logs from {} container {}: {}", this, containerName, exception.getStatus().getMessage());
75+
}
76+
}
77+
7078
private Stream<LogLine> readLogs(String containerName, Reader logReader) {
7179
return new BufferedReader(logReader).lines()
7280
.map(line -> createLogLine(line, containerName));

0 commit comments

Comments
 (0)