From 9b4eacbcceba0cbbac38bd7ebfc30af35ffe8e6d Mon Sep 17 00:00:00 2001 From: Gavin Bunney Date: Fri, 6 Oct 2023 12:04:45 -0700 Subject: [PATCH] Refactor server stats updating on connection lifecycle hooks --- .../DefaultClientChannelManager.java | 9 +++++-- .../PerServerConnectionPool.java | 24 ++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/zuul-core/src/main/java/com/netflix/zuul/netty/connectionpool/DefaultClientChannelManager.java b/zuul-core/src/main/java/com/netflix/zuul/netty/connectionpool/DefaultClientChannelManager.java index 0dbbea6e8f..9dd96a0577 100644 --- a/zuul-core/src/main/java/com/netflix/zuul/netty/connectionpool/DefaultClientChannelManager.java +++ b/zuul-core/src/main/java/com/netflix/zuul/netty/connectionpool/DefaultClientChannelManager.java @@ -214,8 +214,7 @@ public boolean release(final PooledConnection conn) { connsInUse.decrementAndGet(); final DiscoveryResult discoveryResult = conn.getServer(); - discoveryResult.decrementActiveRequestsCount(); - discoveryResult.incrementNumRequests(); + updateServerStatsOnRelease(conn); boolean released = false; @@ -274,6 +273,12 @@ public boolean release(final PooledConnection conn) { return released; } + protected void updateServerStatsOnRelease(final PooledConnection conn) { + final DiscoveryResult discoveryResult = conn.getServer(); + discoveryResult.decrementActiveRequestsCount(); + discoveryResult.incrementNumRequests(); + } + protected void releaseHandlers(PooledConnection conn) { final ChannelPipeline pipeline = conn.getChannel().pipeline(); removeHandlerFromPipeline(OriginResponseReceiver.CHANNEL_HANDLER_NAME, pipeline); diff --git a/zuul-core/src/main/java/com/netflix/zuul/netty/connectionpool/PerServerConnectionPool.java b/zuul-core/src/main/java/com/netflix/zuul/netty/connectionpool/PerServerConnectionPool.java index 0397978803..3c21447bfd 100644 --- a/zuul-core/src/main/java/com/netflix/zuul/netty/connectionpool/PerServerConnectionPool.java +++ b/zuul-core/src/main/java/com/netflix/zuul/netty/connectionpool/PerServerConnectionPool.java @@ -158,7 +158,7 @@ public Promise acquire( } requestConnCounter.increment(); - server.incrementActiveRequestsCount(); + updateServerStatsOnAcquire(); Promise promise = eventLoop.newPromise(); @@ -180,6 +180,10 @@ public Promise acquire( return promise; } + protected void updateServerStatsOnAcquire() { + server.incrementActiveRequestsCount(); + } + public PooledConnection tryGettingFromConnectionPool(EventLoop eventLoop) { PooledConnection conn; Deque connections = getPoolForEventLoop(eventLoop); @@ -284,25 +288,29 @@ protected ChannelFuture connectToServer(EventLoop eventLoop, CurrentPassport pas protected void handleConnectCompletion( ChannelFuture cf, Promise callerPromise, CurrentPassport passport) { connCreationsInProgress.decrementAndGet(); - + updateServerStatsOnConnectCompletion(cf); if (cf.isSuccess()) { - passport.add(PassportState.ORIGIN_CH_CONNECTED); - server.incrementOpenConnectionsCount(); createConnSucceededCounter.increment(); connsInUse.incrementAndGet(); - createConnection(cf, callerPromise, passport); } else { - server.incrementSuccessiveConnectionFailureCount(); - server.addToFailureCount(); - server.decrementActiveRequestsCount(); createConnFailedCounter.increment(); callerPromise.setFailure( new OriginConnectException(cf.cause().getMessage(), cf.cause(), OutboundErrorType.CONNECT_ERROR)); } } + protected void updateServerStatsOnConnectCompletion(ChannelFuture cf) { + if (cf.isSuccess()) { + server.incrementOpenConnectionsCount(); + } else { + server.incrementSuccessiveConnectionFailureCount(); + server.addToFailureCount(); + server.decrementActiveRequestsCount(); + } + } + protected void createConnection( ChannelFuture cf, Promise callerPromise, CurrentPassport passport) { final PooledConnection conn = pooledConnectionFactory.create(cf.channel());