Skip to content

Commit

Permalink
Fix log noise for web sockets in the Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-traverse committed Dec 8, 2024
1 parent 1c67040 commit 66b5f9e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,16 @@ public static Logger threadLocalLogger(Object obj, ThreadLocal<Logger> logMap) {

return log;
}

public static Logger threadLocalLogger(Class<?> clazz, ThreadLocal<Logger> logMap) {

var log = logMap.get();

if (log == null) {
log = LoggerFactory.getLogger(clazz);
logMap.set(log);
}

return log;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class CoreRouter extends ChannelDuplexHandler {


private static final ThreadLocal<Logger> logMap = new ThreadLocal<>();
private final Logger log = LoggingHelpers.threadLocalLogger(this, logMap);
private final Logger log = LoggingHelpers.threadLocalLogger(CoreRouter.class, logMap);

protected final List<Route> routes;
protected final List<Redirect> redirects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
upgradeHeaders = handshake.requestHeaders();
upgradeComplete = true;

log.info("conn = {}, websockets handshake complete, sub-protocol = [{}]", connId, handshake.selectedSubprotocol());
if (log.isDebugEnabled())
log.debug("conn = {}, websockets handshake complete, sub-protocol = [{}]", connId, handshake.selectedSubprotocol());

if (log.isTraceEnabled()) {
log.trace("conn = {}, handshake headers: {}", connId, handshake.requestHeaders().toString());
Expand Down Expand Up @@ -339,23 +340,23 @@ private void processInboundCloseFrame(ChannelHandlerContext ctx, CloseWebSocketF
// If both sides have sent a close frame already, then ok to close immediately
if (closeFrameSent) {

log.info("conn = {}, received close response, code = [{}]: {}",
connId, frame.statusCode(), frame.reasonText());
if (log.isDebugEnabled())
log.debug("conn = {}, received close response, code = [{}]: {}", connId, frame.statusCode(), frame.reasonText());

ctx.close();
}

// Otherwise this is a new request, send the response frame before closing the channel
else {

log.info("conn = {}, received close request, code = [{}]: {}",
connId, frame.statusCode(), frame.reasonText());
if (log.isDebugEnabled())
log.debug("conn = {}, received close request, code = [{}]: {}", connId, frame.statusCode(), frame.reasonText());

var closeResponse = new CloseWebSocketFrame(frame.statusCode(), frame.reasonText());
var closePromise = ctx.newPromise();

log.info("conn = {}, sending close response, code = [{}]: {}",
connId, frame.statusCode(), frame.reasonText());
if (log.isDebugEnabled())
log.debug("conn = {}, sending close response, code = [{}]: {}", connId, frame.statusCode(), frame.reasonText());

closeFrameSent = true;

Expand All @@ -379,14 +380,13 @@ private void processOutboundCloseFrame(ChannelHandlerContext ctx, CloseWebSocket

if (closeFrameSent) {

log.warn("conn = {}, ignoring duplicate outbound close request [{}]: {}",
connId, frame.statusCode(), frame.reasonText());
log.warn("conn = {}, ignoring duplicate outbound close request [{}]: {}", connId, frame.statusCode(), frame.reasonText());
}

else {

log.info("conn = {}, sending close request, code = [{}]: {}",
connId, frame.statusCode(), frame.reasonText());
if (log.isDebugEnabled())
log.debug("conn = {}, sending close request, code = [{}]: {}", connId, frame.statusCode(), frame.reasonText());

ReferenceCountUtil.retain(frame);
closeFrameSent = true;
Expand Down

0 comments on commit 66b5f9e

Please sign in to comment.