From 35c303227aa0b66983400b6b0c31581000a82372 Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Fri, 5 Jan 2024 10:33:09 -0500 Subject: [PATCH] net/dns/resolver: add ID to verbose logs in forwarder To make it easier to correlate the starting/ending log messages. Updates #cleanup Signed-off-by: Andrew Dunham Change-Id: I2802d53ad98e19bc8914bc58f8c04d4443227b26 --- net/dns/resolver/forwarder.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/dns/resolver/forwarder.go b/net/dns/resolver/forwarder.go index 4a0bbc7fc..16c08a5ca 100644 --- a/net/dns/resolver/forwarder.go +++ b/net/dns/resolver/forwarder.go @@ -460,6 +460,10 @@ func (f *forwarder) sendDoH(ctx context.Context, urlBase string, c *http.Client, var ( verboseDNSForward = envknob.RegisterBool("TS_DEBUG_DNS_FORWARD_SEND") skipTCPRetry = envknob.RegisterBool("TS_DNS_FORWARD_SKIP_TCP_RETRY") + + // For correlating log messages in the send() function; only used when + // verboseDNSForward() is true. + forwarderCount atomic.Uint64 ) // send sends packet to dst. It is best effort. @@ -467,9 +471,10 @@ var ( // send expects the reply to have the same txid as txidOut. func (f *forwarder) send(ctx context.Context, fq *forwardQuery, rr resolverAndDelay) (ret []byte, err error) { if verboseDNSForward() { - f.logf("forwarder.send(%q) ...", rr.name.Addr) + id := forwarderCount.Add(1) + f.logf("forwarder.send(%q) [%d] ...", rr.name.Addr, id) defer func() { - f.logf("forwarder.send(%q) = %v, %v", rr.name.Addr, len(ret), err) + f.logf("forwarder.send(%q) [%d] = %v, %v", rr.name.Addr, id, len(ret), err) }() } if strings.HasPrefix(rr.name.Addr, "http://") {