Skip to content

Commit

Permalink
Generate log message in advance (#3571)
Browse files Browse the repository at this point in the history
Add separate handling for Throwable when available.

Fixes: #3561

Co-authored-by: Violeta Georgieva <[email protected]>
  • Loading branch information
raccoonback and violetagg committed Jan 2, 2025
1 parent 72198ef commit 2bca537
Showing 1 changed file with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2024 VMware, Inc. or its affiliates, All Rights Reserved.
* Copyright (c) 2018-2025 VMware, Inc. or its affiliates, All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,6 +55,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -365,13 +366,29 @@ protected static void logPoolState(Channel channel, InstrumentedPool<? extends C
}

protected static void logPoolState(Channel channel, InstrumentedPool<? extends Connection> pool, String msg, @Nullable Throwable t) {
String logMsg = msg + ", " + stringifyPoolMetrics(pool);
if (t == null) {
log.debug(format(channel, logMsg));
return;
}

log.debug(
format(channel, logMsg),
t
);
}

private static String stringifyPoolMetrics(InstrumentedPool<? extends Connection> pool) {
InstrumentedPool.PoolMetrics metrics = pool.metrics();
log.debug(format(channel, "{}, now: {} active connections, {} inactive connections and {} pending acquire requests."),
msg,
metrics.acquiredSize(),
metrics.idleSize(),
metrics.pendingAcquireSize(),
t == null ? "" : t);
return new StringJoiner(" ")
.add("now:")
.add(String.valueOf(metrics.acquiredSize()))
.add("active connections,")
.add(String.valueOf(metrics.idleSize()))
.add("inactive connections")
.add(String.valueOf(metrics.pendingAcquireSize()))
.add("pending acquire requests.")
.toString();
}

final void scheduleInactivePoolsDisposal() {
Expand Down

0 comments on commit 2bca537

Please sign in to comment.