Skip to content

Commit

Permalink
More logging for apache clients
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdanfox committed Apr 15, 2020
1 parent 7267602 commit 4087a5d
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.apache.http.impl.client.ProxyAuthenticationStrategy;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
import org.apache.http.pool.PoolStats;
import org.apache.http.protocol.HttpContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -145,21 +146,37 @@ private static MetricName clientPoolSizeMetricName(String clientName, String sta

/** Intentionally opaque wrapper type - we don't want people using the inner Apache client directly. */
public static final class CloseableClient implements Closeable {
private final String name;
private final CloseableHttpClient client;
private final PoolingHttpClientConnectionManager pool;
private final ResponseLeakDetector leakDetector;

@Nullable
private final ExecutorService executor;

CloseableClient(
CloseableHttpClient client, ResponseLeakDetector leakDetector, @Nullable ExecutorService executor) {
String name,
CloseableHttpClient client,
PoolingHttpClientConnectionManager pool,
ResponseLeakDetector leakDetector,
@Nullable ExecutorService executor) {
log.debug("Apache client created", SafeArg.of("name", name));
this.name = name;
this.client = client;
this.pool = pool;
this.leakDetector = leakDetector;
this.executor = executor;
}

@Override
public void close() throws IOException {
PoolStats poolStats = pool.getTotalStats();
log.debug(
"Closing Apache client",
SafeArg.of("name", name),
SafeArg.of("idle", poolStats.getAvailable()),
SafeArg.of("leased", poolStats.getLeased()),
SafeArg.of("pending", poolStats.getPending()));
client.close();
}

Expand Down Expand Up @@ -301,7 +318,11 @@ public CloseableClient build() {
});

return new CloseableClient(
builder.build(), ResponseLeakDetector.of(name, conf.taggedMetricRegistry()), executor);
name,
builder.build(),
connectionManager,
ResponseLeakDetector.of(name, conf.taggedMetricRegistry()),
executor);
}
}

Expand Down

0 comments on commit 4087a5d

Please sign in to comment.