diff --git a/CHANGELOG.md b/CHANGELOG.md index b176e4096cf..da10bc4d7b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ #### Bugs #### Improvements +* Fix #4254: adding debug logging for exec stream messages * Fix #4041: adding Quantity.getNumericalAmount with an explanation about bytes and cores. * Fix #4241: added more context to informer logs with the endpoint path diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java index 7e0d3bdd856..fb127ac8c7f 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/ExecWebSocketListener.java @@ -100,17 +100,29 @@ public interface MessageHandler { private final class ListenerStream { private MessageHandler handler; private ExecWatchInputStream inputStream; + private String name; + + public ListenerStream(String name) { + this.name = name; + } private void handle(ByteBuffer byteString, WebSocket webSocket) throws IOException { if (handler != null) { handler.handle(byteString); } else { + if (LOGGER.isDebugEnabled()) { + String message = ExecWebSocketListener.toString(byteString); + if (message.length() > 200) { + message = message.substring(0, 197) + "..."; + } + LOGGER.debug("exec message received on channel {}: {}", name, message); + } webSocket.request(); } } } - private static final Logger LOGGER = LoggerFactory.getLogger(ExecWebSocketListener.class); + static final Logger LOGGER = LoggerFactory.getLogger(ExecWebSocketListener.class); private static final String HEIGHT = "Height"; private static final String WIDTH = "Width"; @@ -152,14 +164,14 @@ public ExecWebSocketListener(PodOperationContext context, Executor executor) { } this.terminateOnError = context.isTerminateOnError(); - this.out = createStream(context.getOutput()); - this.error = createStream(context.getError()); - this.errorChannel = createStream(context.getErrorChannel()); + this.out = createStream("stdOut", context.getOutput()); + this.error = createStream("stdErr", context.getError()); + this.errorChannel = createStream("errorChannel", context.getErrorChannel()); this.serialExecutor = new SerialExecutor(executor); } - private ListenerStream createStream(StreamContext streamContext) { - ListenerStream stream = new ListenerStream(); + private ListenerStream createStream(String name, StreamContext streamContext) { + ListenerStream stream = new ListenerStream(name); if (streamContext == null) { return stream; } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationContext.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationContext.java index 7ec951b78cf..bc4ccfbf08c 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationContext.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationContext.java @@ -164,10 +164,11 @@ public void addQueryParameters(URLBuilder httpUrlBuilder) { if (in != null || redirectingIn) { httpUrlBuilder.addQueryParameter("stdin", "true"); } - if (output != null) { + boolean debug = ExecWebSocketListener.LOGGER.isDebugEnabled(); + if (output != null || debug) { httpUrlBuilder.addQueryParameter("stdout", "true"); } - if (error != null || terminateOnError) { + if (error != null || terminateOnError || debug) { httpUrlBuilder.addQueryParameter("stderr", "true"); } } diff --git a/kubernetes-itests/pom.xml b/kubernetes-itests/pom.xml index 1f02f289a04..a7bb2a45d5d 100644 --- a/kubernetes-itests/pom.xml +++ b/kubernetes-itests/pom.xml @@ -58,6 +58,11 @@ org.awaitility awaitility + + org.slf4j + slf4j-simple + test +