Skip to content

Commit

Permalink
fix fabric8io#4254: adding debug logging for exec stream messages
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jul 21, 2022
1 parent 11d20aa commit 0b60822
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
5 changes: 5 additions & 0 deletions kubernetes-itests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down

0 comments on commit 0b60822

Please sign in to comment.