Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProtocolVersionFilteringDialogueDnsResolver logs localhost at debug #2181

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2181.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: ProtocolVersionFilteringDialogueDnsResolver logs localhost at debug
links:
- https://github.com/palantir/dialogue/pull/2181
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.collect.ImmutableSetMultimap;
import com.palantir.dialogue.core.DialogueDnsResolver;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.Unsafe;
import com.palantir.logsafe.UnsafeArg;
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
Expand Down Expand Up @@ -52,7 +53,7 @@ public ImmutableSetMultimap<String, InetAddress> resolve(Iterable<String> hostna
}

// TODO(dns): report metrics here
private static ImmutableSet<InetAddress> filter(ImmutableSet<InetAddress> addresses, String hostname) {
private static ImmutableSet<InetAddress> filter(ImmutableSet<InetAddress> addresses, @Unsafe String hostname) {
// Assume that if resolved addresses contain a mix of ipv4 and ipv6 addresses, then they
// likely point to the same host, just using a different protocol. In that case, we discared the ipv6
// addresses and prefer only ipv4.
Expand All @@ -70,8 +71,9 @@ private static ImmutableSet<InetAddress> filter(ImmutableSet<InetAddress> addres
} else {
++numUnknown;
log.warn(
"name resolution result contains an address that is neither IPv4 nor IPv6",
UnsafeArg.of("address", address));
"name resolution result contains address {} that is neither IPv4 nor IPv6 ({})",
UnsafeArg.of("address", address),
SafeArg.of("type", address.getClass()));
}
}

Expand All @@ -86,14 +88,30 @@ private static ImmutableSet<InetAddress> filter(ImmutableSet<InetAddress> addres
onlyIpv4Addresses.add(address);
}
}
logFilteredAddresses(hostname, numIpv4, numIpv6);
return onlyIpv4Addresses.build();
}

return addresses;
}

private static void logFilteredAddresses(@Unsafe String hostname, int numIpv4, int numIpv6) {
// Localhost is logged at debug because this is most often expected.
// We will likely drop non-localhost filtering to debug as well after this feature has rolled out.
if ("localhost".equals(hostname)) {
if (log.isDebugEnabled()) {
log.debug(
"using only resolved IPv4 addresses for host to avoid double-counting",
SafeArg.of("numIpv4", numIpv4),
SafeArg.of("numIpv6", numIpv6),
SafeArg.of("host", "localhost"));
}
} else {
log.info(
"using only resolved IPv4 addresses for host to avoid double-counting",
SafeArg.of("numIpv4", numIpv4),
SafeArg.of("numIpv6", numIpv6),
UnsafeArg.of("host", hostname));
return onlyIpv4Addresses.build();
}

return addresses;
}
}
Loading