3232
3333package org .opensearch .http .netty4 ;
3434
35+ import org .apache .logging .log4j .Level ;
36+ import org .apache .logging .log4j .Logger ;
3537import org .opensearch .common .TriFunction ;
3638import org .opensearch .common .collect .Tuple ;
3739import org .opensearch .common .settings .Settings ;
117119 * Tiny helper to send http requests over netty.
118120 */
119121public class Netty4HttpClient implements Closeable {
120-
121122 static Collection <String > returnHttpResponseBodies (Collection <FullHttpResponse > responses ) {
122123 List <String > list = new ArrayList <>(responses .size ());
123124 for (FullHttpResponse response : responses ) {
@@ -137,6 +138,7 @@ static Collection<String> returnOpaqueIds(Collection<FullHttpResponse> responses
137138 private final Bootstrap clientBootstrap ;
138139 private final TriFunction <CountDownLatch , Collection <FullHttpResponse >, Boolean , AwaitableChannelInitializer <?>> handlerFactory ;
139140 private final boolean secure ;
141+ private Logger logger ;
140142
141143 Netty4HttpClient (
142144 Bootstrap clientBootstrap ,
@@ -188,6 +190,11 @@ public static Netty4HttpClient http3() {
188190 );
189191 }
190192
193+ public Netty4HttpClient withLogger (Logger logger ) {
194+ this .logger = logger ;
195+ return this ;
196+ }
197+
191198 public List <FullHttpResponse > get (SocketAddress remoteAddress , String ... uris ) throws InterruptedException {
192199 List <HttpRequest > requests = new ArrayList <>(uris .length );
193200 for (int i = 0 ; i < uris .length ; i ++) {
@@ -244,6 +251,7 @@ private synchronized List<FullHttpResponse> sendRequests(final SocketAddress rem
244251 final List <FullHttpResponse > content = Collections .synchronizedList (new ArrayList <>(requests .size ()));
245252
246253 final AwaitableChannelInitializer <?> handler = handlerFactory .apply (latch , content , secure );
254+ handler .logger = logger ;
247255 clientBootstrap .handler (handler );
248256
249257 ChannelFuture channelFuture = null ;
@@ -341,6 +349,14 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
341349 *
342350 */
343351 private static abstract class AwaitableChannelInitializer <C extends Channel > extends ChannelInitializer <C > {
352+ private Logger logger ;
353+
354+ void log (Level level , String message , Object ... params ) {
355+ if (logger != null ) {
356+ logger .log (level , message , params );
357+ }
358+ }
359+
344360 void await () {
345361 // do nothing
346362 }
@@ -518,6 +534,8 @@ protected void initChannel(DatagramChannel ch) {
518534
519535 @ Override
520536 Channel prepare (Bootstrap clientBootstrap , Channel channel ) throws InterruptedException {
537+ log (Level .INFO , "[QuicChannel] Connecting to: {}" , channel .remoteAddress ());
538+
521539 final QuicChannel quicChannel = QuicChannel .newBootstrap (channel )
522540 .option (ChannelOption .CONNECT_TIMEOUT_MILLIS , 30000 ) // 30 seconds
523541 .handler (new Http3ClientConnectionHandler ())
0 commit comments