Skip to content

Commit

Permalink
Dedicated logger for Netty4HttpPipeliningHandler (#104806)
Browse files Browse the repository at this point in the history
Better to use a logger for the class that's doing the logging rather
than deferring back to the owning transport's logger.
  • Loading branch information
DaveCTurner authored Jan 26, 2024
1 parent 8e28ca7 commit 14e9acd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.PromiseCombiner;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.common.bytes.ReleasableBytesReference;
Expand Down Expand Up @@ -52,7 +53,7 @@
*/
public class Netty4HttpPipeliningHandler extends ChannelDuplexHandler {

private final Logger logger;
private static final Logger logger = LogManager.getLogger(Netty4HttpPipeliningHandler.class);

private final int maxEventsHeld;
private final PriorityQueue<Tuple<? extends Netty4HttpResponse, ChannelPromise>> outboundHoldingQueue;
Expand Down Expand Up @@ -86,12 +87,10 @@ private record ChunkedWrite(PromiseCombiner combiner, ChannelPromise onDone, Chu
/**
* Construct a new pipelining handler; this handler should be used downstream of HTTP decoding/aggregation.
*
* @param logger for logging unexpected errors
* @param maxEventsHeld the maximum number of channel events that will be retained prior to aborting the channel connection; this is
* required as events cannot queue up indefinitely
*/
public Netty4HttpPipeliningHandler(Logger logger, final int maxEventsHeld, final Netty4HttpServerTransport serverTransport) {
this.logger = logger;
public Netty4HttpPipeliningHandler(final int maxEventsHeld, final Netty4HttpServerTransport serverTransport) {
this.maxEventsHeld = maxEventsHeld;
this.outboundHoldingQueue = new PriorityQueue<>(1, Comparator.comparingInt(t -> t.v1().getSequence()));
this.serverTransport = serverTransport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ protected boolean isContentAlwaysEmpty(HttpResponse msg) {
if (handlingSettings.compression()) {
ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(handlingSettings.compressionLevel()));
}
ch.pipeline().addLast("pipelining", new Netty4HttpPipeliningHandler(logger, transport.pipeliningMaxEvents, transport));
ch.pipeline().addLast("pipelining", new Netty4HttpPipeliningHandler(transport.pipeliningMaxEvents, transport));
transport.serverAcceptedChannel(nettyHttpChannel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void testThatPipeliningWorksWithFastSerializedRequests() throws Interrupt
}

private EmbeddedChannel makeEmbeddedChannelWithSimulatedWork(int numberOfRequests) {
return new EmbeddedChannel(new Netty4HttpPipeliningHandler(logger, numberOfRequests, null) {
return new EmbeddedChannel(new Netty4HttpPipeliningHandler(numberOfRequests, null) {
@Override
protected void handlePipelinedRequest(ChannelHandlerContext ctx, Netty4HttpRequest pipelinedRequest) {
ctx.fireChannelRead(pipelinedRequest);
Expand Down Expand Up @@ -185,7 +185,7 @@ public void testThatPipeliningClosesConnectionWithTooManyEvents() throws Interru

public void testPipeliningRequestsAreReleased() {
final int numberOfRequests = 10;
final EmbeddedChannel embeddedChannel = new EmbeddedChannel(new Netty4HttpPipeliningHandler(logger, numberOfRequests + 1, null));
final EmbeddedChannel embeddedChannel = new EmbeddedChannel(new Netty4HttpPipeliningHandler(numberOfRequests + 1, null));

for (int i = 0; i < numberOfRequests; i++) {
embeddedChannel.writeInbound(createHttpRequest("/" + i));
Expand Down Expand Up @@ -493,7 +493,7 @@ private static void assertDoneWithClosedChannel(ChannelPromise chunkedWritePromi
}

private Netty4HttpPipeliningHandler getTestHttpHandler() {
return new Netty4HttpPipeliningHandler(logger, Integer.MAX_VALUE, mock(Netty4HttpServerTransport.class)) {
return new Netty4HttpPipeliningHandler(Integer.MAX_VALUE, mock(Netty4HttpServerTransport.class)) {
@Override
protected void handlePipelinedRequest(ChannelHandlerContext ctx, Netty4HttpRequest pipelinedRequest) {
ctx.fireChannelRead(pipelinedRequest);
Expand Down

0 comments on commit 14e9acd

Please sign in to comment.