Skip to content

Commit

Permalink
Merge #2528 into 2.0.0-M2
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Oct 6, 2022
2 parents 845badb + e7f547e commit 3f212bf
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 33 deletions.
Expand Up @@ -54,7 +54,9 @@ public void channelActive(ChannelHandlerContext ctx) {
recorder().recordServerConnectionOpened(ctx.channel().localAddress());
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
}
Expand All @@ -68,7 +70,9 @@ public void channelInactive(ChannelHandlerContext ctx) {
recorder().recordServerConnectionClosed(ctx.channel().localAddress());
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
}
Expand Down Expand Up @@ -109,7 +113,9 @@ else if (msg instanceof DatagramPacket p) {
}
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}

Expand All @@ -132,7 +138,9 @@ else if (msg instanceof DatagramPacket p) {
}
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}

Expand All @@ -145,7 +153,9 @@ public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
recordException(ctx, remoteAddress != null ? remoteAddress : ctx.channel().remoteAddress());
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}

Expand Down
Expand Up @@ -346,8 +346,10 @@ protected static final class PoolFactory<T extends Connection> {
Double.parseDouble(System.getProperty(ReactorNetty.POOL_GET_PERMITS_SAMPLING_RATE, "0"));
if (getPermitsSamplingRate > 1d) {
DEFAULT_POOL_GET_PERMITS_SAMPLING_RATE = 0;
log.warn("Invalid configuration [" + ReactorNetty.POOL_GET_PERMITS_SAMPLING_RATE + "=" + getPermitsSamplingRate +
"], the value must be between 0d and 1d (percentage). SamplingAllocationStrategy in not enabled.");
if (log.isWarnEnabled()) {
log.warn("Invalid configuration [" + ReactorNetty.POOL_GET_PERMITS_SAMPLING_RATE + "=" + getPermitsSamplingRate +
"], the value must be between 0d and 1d (percentage). SamplingAllocationStrategy in not enabled.");
}
}
else {
DEFAULT_POOL_GET_PERMITS_SAMPLING_RATE = getPermitsSamplingRate;
Expand All @@ -360,8 +362,10 @@ protected static final class PoolFactory<T extends Connection> {
Double.parseDouble(System.getProperty(ReactorNetty.POOL_RETURN_PERMITS_SAMPLING_RATE, "0"));
if (returnPermitsSamplingRate > 1d) {
DEFAULT_POOL_RETURN_PERMITS_SAMPLING_RATE = 0;
log.warn("Invalid configuration [" + ReactorNetty.POOL_RETURN_PERMITS_SAMPLING_RATE + "=" + returnPermitsSamplingRate +
"], the value must be between 0d and 1d (percentage). SamplingAllocationStrategy is enabled.");
if (log.isWarnEnabled()) {
log.warn("Invalid configuration [" + ReactorNetty.POOL_RETURN_PERMITS_SAMPLING_RATE + "=" + returnPermitsSamplingRate +
"], the value must be between 0d and 1d (percentage). SamplingAllocationStrategy is enabled.");
}
}
else {
DEFAULT_POOL_RETURN_PERMITS_SAMPLING_RATE = returnPermitsSamplingRate;
Expand Down
Expand Up @@ -136,7 +136,9 @@ void record(long resolveTimeStart, String status, SocketAddress remoteAddress) {
status);
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
}
Expand Down
Expand Up @@ -60,7 +60,9 @@ void registerMetrics(EventLoop eventLoop) {
});
}
catch (InterruptedException e) {
log.warn("Thread interrupted while registering metrics", e);
if (log.isWarnEnabled()) {
log.warn("Thread interrupted while registering metrics", e);
}
}
}
}
Expand Down
Expand Up @@ -396,7 +396,7 @@ public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
.executor()
.schedule(enableAutoReadTask, 1, TimeUnit.SECONDS)
.addListener(future -> {
if (!future.isSuccess()) {
if (!future.isSuccess() && log.isDebugEnabled()) {
log.debug(format(ctx.channel(), "Cannot enable auto-read"), future.cause());
}
});
Expand Down Expand Up @@ -433,7 +433,9 @@ void initChild(final Channel child) {

static void forceClose(Channel child, Throwable t) {
child.close();
log.warn(format(child, "Failed to register an accepted channel: {}"), child, t);
if (log.isWarnEnabled()) {
log.warn(format(child, "Failed to register an accepted channel: {}"), child, t);
}
}
}

Expand Down
Expand Up @@ -419,7 +419,9 @@ protected void initChannel(Channel channel) {
MicrometerEventLoopMeterRegistrar.INSTANCE.registerMetrics(channel.executor());
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
}
Expand Down
Expand Up @@ -210,15 +210,19 @@ static void setChannelOptions(Channel channel, Map<ChannelOption<?>, ?> options,
}
try {
if (!channel.isOptionSupported(e.getKey())) {
log.warn(format(channel, "Unknown channel option '{}' for channel '{}'"), e.getKey(), channel);
if (log.isWarnEnabled()) {
log.warn(format(channel, "Unknown channel option '{}' for channel '{}'"), e.getKey(), channel);
}
}
else {
channel.setOption((ChannelOption<Object>) e.getKey(), e.getValue());
}
}
catch (Throwable t) {
log.warn(format(channel, "Failed to set channel option '{}' with value '{}' for channel '{}'"),
e.getKey(), e.getValue(), channel, t);
if (log.isWarnEnabled()) {
log.warn(format(channel, "Failed to set channel option '{}' with value '{}' for channel '{}'"),
e.getKey(), e.getValue(), channel, t);
}
}
}
}
Expand Down
Expand Up @@ -128,8 +128,10 @@ public NettyOutbound send(Publisher<? extends Buffer> source) {
return Mono.error(e);
}
if (HttpUtil.getContentLength(outboundHttpMessage(), -1) == 0) {
log.debug(format(channel(), "Dropped HTTP content, " +
"since response has Content-Length: 0 {}"), toPrettyHexDump(msg));
if (log.isDebugEnabled()) {
log.debug(format(channel(), "Dropped HTTP content, " +
"since response has Content-Length: 0 {}"), toPrettyHexDump(msg));
}
msg.close();
return Mono.fromCompletionStage(
channel().writeAndFlush(newFullBodyMessage(channel().bufferAllocator().allocate(0))).asStage());
Expand Down Expand Up @@ -162,8 +164,10 @@ public NettyOutbound sendObject(Object message) {
throw e;
}
if (HttpUtil.getContentLength(outboundHttpMessage(), -1) == 0) {
log.debug(format(channel(), "Dropped HTTP content, " +
"since response has Content-Length: 0 {}"), toPrettyHexDump(b));
if (log.isDebugEnabled()) {
log.debug(format(channel(), "Dropped HTTP content, " +
"since response has Content-Length: 0 {}"), toPrettyHexDump(b));
}
b.close();
return channel().writeAndFlush(newFullBodyMessage(channel().bufferAllocator().allocate(0))).asStage();
}
Expand Down
Expand Up @@ -95,14 +95,18 @@ public Future<Void> write(ChannelHandlerContext ctx, Object msg) {
recordWrite(address);
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
});
}
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}

Expand All @@ -126,7 +130,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}

Expand All @@ -139,7 +145,9 @@ public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
recordException(ctx);
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}

Expand Down
Expand Up @@ -73,7 +73,9 @@ public void channelActive(ChannelHandlerContext ctx) {
recorder().recordServerConnectionOpened(ctx.channel().localAddress());
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
}
Expand All @@ -87,7 +89,9 @@ public void channelInactive(ChannelHandlerContext ctx) {
recorder().recordServerConnectionClosed(ctx.channel().localAddress());
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
}
Expand Down Expand Up @@ -124,7 +128,9 @@ public Future<Void> write(ChannelHandlerContext ctx, Object msg) {
ops.method().name(), ops.status().codeAsText().toString());
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
// ops.hostAddress() == null when request decoding failed, in this case
Expand All @@ -139,7 +145,9 @@ public Future<Void> write(ChannelHandlerContext ctx, Object msg) {
}
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
}
Expand All @@ -150,7 +158,9 @@ public Future<Void> write(ChannelHandlerContext ctx, Object msg) {
}
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}
return ctx.write(msg);
Expand Down Expand Up @@ -184,7 +194,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}

Expand All @@ -201,7 +213,9 @@ public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
}
}
catch (RuntimeException e) {
log.warn("Exception caught while recording metrics.", e);
if (log.isWarnEnabled()) {
log.warn("Exception caught while recording metrics.", e);
}
// Allow request-response exchange to continue, unaffected by metrics problem
}

Expand Down
Expand Up @@ -121,7 +121,7 @@ final class WebsocketServerOperations extends HttpServerOperations
// This change is needed after the Netty change https://github.com/netty/netty/pull/11966
channel.read();
}
else {
else if (log.isDebugEnabled()) {
log.debug(format(channel, "Cannot bind WebsocketServerOperations after the handshake."));
}
});
Expand Down

0 comments on commit 3f212bf

Please sign in to comment.