Skip to content

Commit

Permalink
InstrumentedDnsResolver debug logging includes the client name (#1583)
Browse files Browse the repository at this point in the history
InstrumentedDnsResolver debug logging includes the client name
  • Loading branch information
carterkozak authored Feb 11, 2022
1 parent 085f21c commit 6c4a431
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1583.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: InstrumentedDnsResolver debug logging includes the client name
links:
- https://github.com/palantir/dialogue/pull/1583
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public Socket createSocket(final HttpContext context) throws IOException {
// No maximum time to live
TimeValue.NEG_ONE_MILLISECOND,
null,
new InstrumentedDnsResolver(SystemDefaultDnsResolver.INSTANCE),
new InstrumentedDnsResolver(SystemDefaultDnsResolver.INSTANCE, name),
new InstrumentedManagedHttpConnectionFactory(
ManagedHttpClientConnectionFactory.INSTANCE, conf.taggedMetricRegistry(), name));
connectionManager.setDefaultSocketConfig(SocketConfig.custom()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ final class InstrumentedDnsResolver implements DnsResolver {

private static final SafeLogger log = SafeLoggerFactory.get(InstrumentedDnsResolver.class);
private final DnsResolver delegate;
private final String clientName;

InstrumentedDnsResolver(DnsResolver delegate) {
InstrumentedDnsResolver(DnsResolver delegate, String clientName) {
this.delegate = delegate;
this.clientName = clientName;
}

@Override
Expand All @@ -46,8 +48,9 @@ public InetAddress[] resolve(String host) throws UnknownHostException {
if (debugLoggingEnabled) {
long durationNanos = System.nanoTime() - startNanos;
log.debug(
"DnsResolver.resolve({}) produced '{}' ({} results) after {} ns",
"DnsResolver.resolve({}) on client {} produced '{}' ({} results) after {} ns",
UnsafeArg.of("host", host),
SafeArg.of("client", clientName),
resolved == null ? SafeArg.of("resolved", "null") : UnsafeArg.of("resolved", resolved),
SafeArg.of("numResolved", resolved == null ? 0 : resolved.length),
SafeArg.of("durationNanos", durationNanos));
Expand All @@ -57,8 +60,9 @@ public InetAddress[] resolve(String host) throws UnknownHostException {
if (debugLoggingEnabled) {
long durationNanos = System.nanoTime() - startNanos;
log.debug(
"DnsResolver.resolve({}) failed after {} ns",
"DnsResolver.resolve({}) on client {} failed after {} ns",
UnsafeArg.of("host", host),
SafeArg.of("client", clientName),
SafeArg.of("durationNanos", durationNanos),
t);
}
Expand All @@ -77,8 +81,9 @@ public String resolveCanonicalHostname(String host) throws UnknownHostException
if (debugLoggingEnabled) {
long durationNanos = System.nanoTime() - startNanos;
log.debug(
"DnsResolver.resolveCanonicalHostname({}) produced '{}' after {} ns",
"DnsResolver.resolveCanonicalHostname({}) on client {} produced '{}' after {} ns",
UnsafeArg.of("host", host),
SafeArg.of("client", clientName),
UnsafeArg.of("resolved", resolved),
SafeArg.of("durationNanos", durationNanos));
}
Expand All @@ -87,8 +92,9 @@ public String resolveCanonicalHostname(String host) throws UnknownHostException
if (debugLoggingEnabled) {
long durationNanos = System.nanoTime() - startNanos;
log.debug(
"DnsResolver.resolveCanonicalHostname({}) failed after {} ns",
"DnsResolver.resolveCanonicalHostname({}) on client {} failed after {} ns",
UnsafeArg.of("host", host),
SafeArg.of("client", clientName),
SafeArg.of("durationNanos", durationNanos),
t);
}
Expand Down

0 comments on commit 6c4a431

Please sign in to comment.