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

resolver: less debug #2475

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions debug_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build debug_log
package libnetwork

import "github.com/sirupsen/logrus"

func debugf(format string, args ...interface{}) {
logrus.Debugf(format, args...)
}
5 changes: 5 additions & 0 deletions no_debug_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build !debug_log
package libnetwork

func debugf(format string, args ...interface{}) {
}
26 changes: 13 additions & 13 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ func (r *resolver) handleIPQuery(name string, query *dns.Msg, ipType int) (*dns.

if addr == nil && ipv6Miss {
// Send a reply without any Answer sections
logrus.Debugf("[resolver] lookup name %s present without IPv6 address", name)
logrus.Warnf("[resolver] lookup name %s present without IPv6 address", name)
resp := createRespMsg(query)
return resp, nil
}
if addr == nil {
return nil, nil
}

logrus.Debugf("[resolver] lookup for %s: IP %v", name, addr)
debugf("[resolver] lookup for %s: IP %v", name, addr)

resp := createRespMsg(query)
if len(addr) > 1 {
Expand Down Expand Up @@ -296,7 +296,7 @@ func (r *resolver) handlePTRQuery(ptr string, query *dns.Msg) (*dns.Msg, error)
return nil, nil
}

logrus.Debugf("[resolver] lookup for IP %s: name %s", parts[0], host)
debugf("[resolver] lookup for IP %s: name %s", parts[0], host)
fqdn := dns.Fqdn(host)

resp := new(dns.Msg)
Expand Down Expand Up @@ -453,7 +453,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
continue
}
queryType := dns.TypeToString[query.Question[0].Qtype]
logrus.Debugf("[resolver] query %s (%s) from %s, forwarding to %s:%s", name, queryType,
debugf("[resolver] query %s (%s) from %s, forwarding to %s:%s", name, queryType,
extConn.LocalAddr().String(), proto, extDNS.IPStr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we still have some debugging about this case (I know this has sometimes been useful when debugging if requests are actually forwarded, and if so, to which DNS)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, tcpdump for the rescue.


// Timeout has to be set for every IO operation.
Expand All @@ -477,7 +477,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
err = co.WriteMsg(query)
if err != nil {
r.forwardQueryEnd()
logrus.Debugf("[resolver] send to DNS server failed, %s", err)
logrus.Warnf("[resolver] send to DNS server failed, %s", err)
continue
}

Expand All @@ -486,24 +486,24 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
// client can retry over TCP
if err != nil && err != dns.ErrTruncated {
r.forwardQueryEnd()
logrus.Debugf("[resolver] read from DNS server failed, %s", err)
logrus.Warnf("[resolver] read from DNS server failed, %s", err)
continue
}
r.forwardQueryEnd()

if resp == nil {
logrus.Debugf("[resolver] external DNS %s:%s returned empty response for %q", proto, extDNS.IPStr, name)
logrus.Warnf("[resolver] external DNS %s:%s returned empty response for %q", proto, extDNS.IPStr, name)
break
}
switch resp.Rcode {
case dns.RcodeServerFailure, dns.RcodeRefused:
// Server returned FAILURE: continue with the next external DNS server
// Server returned REFUSED: this can be a transitional status, so continue with the next external DNS server
logrus.Debugf("[resolver] external DNS %s:%s responded with %s for %q", proto, extDNS.IPStr, statusString(resp.Rcode), name)
logrus.Warnf("[resolver] external DNS %s:%s responded with %s for %q", proto, extDNS.IPStr, statusString(resp.Rcode), name)
continue
case dns.RcodeNameError:
// Server returned NXDOMAIN. Stop resolution if it's an authoritative answer (see RFC 8020: https://tools.ietf.org/html/rfc8020#section-2)
logrus.Debugf("[resolver] external DNS %s:%s responded with %s for %q", proto, extDNS.IPStr, statusString(resp.Rcode), name)
logrus.Warnf("[resolver] external DNS %s:%s responded with %s for %q", proto, extDNS.IPStr, statusString(resp.Rcode), name)
if resp.Authoritative {
break
}
Expand All @@ -512,7 +512,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
// All is well
default:
// Server gave some error. Log the error, and continue with the next external DNS server
logrus.Debugf("[resolver] external DNS %s:%s responded with %s (code %d) for %q", proto, extDNS.IPStr, statusString(resp.Rcode), resp.Rcode, name)
logrus.Warnf("[resolver] external DNS %s:%s responded with %s (code %d) for %q", proto, extDNS.IPStr, statusString(resp.Rcode), resp.Rcode, name)
continue
}
answers := 0
Expand All @@ -522,17 +522,17 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
case dns.TypeA:
answers++
ip := rr.(*dns.A).A
logrus.Debugf("[resolver] received A record %q for %q from %s:%s", ip, h.Name, proto, extDNS.IPStr)
debugf("[resolver] received A record %q for %q from %s:%s", ip, h.Name, proto, extDNS.IPStr)
r.backend.HandleQueryResp(h.Name, ip)
case dns.TypeAAAA:
answers++
ip := rr.(*dns.AAAA).AAAA
logrus.Debugf("[resolver] received AAAA record %q for %q from %s:%s", ip, h.Name, proto, extDNS.IPStr)
debugf("[resolver] received AAAA record %q for %q from %s:%s", ip, h.Name, proto, extDNS.IPStr)
r.backend.HandleQueryResp(h.Name, ip)
}
}
if resp.Answer == nil || answers == 0 {
logrus.Debugf("[resolver] external DNS %s:%s did not return any %s records for %q", proto, extDNS.IPStr, queryType, name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

debugf("[resolver] external DNS %s:%s did not return any %s records for %q", proto, extDNS.IPStr, queryType, name)
}
resp.Compress = true
break
Expand Down
22 changes: 11 additions & 11 deletions sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (sb *sandbox) HandleQueryResp(name string, ip net.IP) {

func (sb *sandbox) ResolveIP(ip string) string {
var svc string
logrus.Debugf("IP To resolve %v", ip)
debugf("IP to resolve %v", ip)

for _, ep := range sb.getConnectedEndpoints() {
n := ep.getNetwork()
Expand All @@ -466,7 +466,7 @@ func (sb *sandbox) ResolveService(name string) ([]*net.SRV, []net.IP) {
srv := []*net.SRV{}
ip := []net.IP{}

logrus.Debugf("Service name To resolve: %v", name)
debugf("Service name to resolve: %v", name)

// There are DNS implementations that allow SRV queries for names not in
// the format defined by RFC 2782. Hence specific validations checks are
Expand Down Expand Up @@ -529,7 +529,7 @@ func (sb *sandbox) ResolveName(name string, ipType int) ([]net.IP, bool) {
// {a.b in network c.d},
// {a in network b.c.d},

logrus.Debugf("Name To resolve: %v", name)
debugf("Name to resolve: %v", name)
name = strings.TrimSuffix(name, ".")
reqName := []string{name}
networkName := []string{""}
Expand Down Expand Up @@ -637,7 +637,7 @@ func (sb *sandbox) resolveName(req string, networkName string, epList []*endpoin
func (sb *sandbox) SetKey(basePath string) error {
start := time.Now()
defer func() {
logrus.Debugf("sandbox set key processing took %s for container %s", time.Since(start), sb.ContainerID())
debugf("sandbox set key processing took %s for container %s", time.Since(start), sb.ContainerID())
}()

if basePath == "" {
Expand Down Expand Up @@ -691,7 +691,7 @@ func (sb *sandbox) SetKey(basePath string) error {
}

func (sb *sandbox) EnableService() (err error) {
logrus.Debugf("EnableService %s START", sb.containerID)
debugf("EnableService %s START", sb.containerID)
defer func() {
if err != nil {
sb.DisableService()
Expand All @@ -705,12 +705,12 @@ func (sb *sandbox) EnableService() (err error) {
ep.enableService()
}
}
logrus.Debugf("EnableService %s DONE", sb.containerID)
debugf("EnableService %s DONE", sb.containerID)
return nil
}

func (sb *sandbox) DisableService() (err error) {
logrus.Debugf("DisableService %s START", sb.containerID)
debugf("DisableService %s START", sb.containerID)
failedEps := []string{}
defer func() {
if len(failedEps) > 0 {
Expand All @@ -726,7 +726,7 @@ func (sb *sandbox) DisableService() (err error) {
ep.disableService()
}
}
logrus.Debugf("DisableService %s DONE", sb.containerID)
debugf("DisableService %s DONE", sb.containerID)
return nil
}

Expand All @@ -735,7 +735,7 @@ func releaseOSSboxResources(osSbox osl.Sandbox, ep *endpoint) {
// Only remove the interfaces owned by this endpoint from the sandbox.
if ep.hasInterface(i.SrcName()) {
if err := i.Remove(); err != nil {
logrus.Debugf("Remove interface %s failed: %v", i.SrcName(), err)
logrus.WithError(err).Warnf("Remove interface %s failed", i.SrcName())
}
}
}
Expand All @@ -749,7 +749,7 @@ func releaseOSSboxResources(osSbox osl.Sandbox, ep *endpoint) {
if len(vip) > 0 && lbModeIsDSR {
ipNet := &net.IPNet{IP: vip, Mask: net.CIDRMask(32, 32)}
if err := osSbox.RemoveAliasIP(osSbox.GetLoopbackIfaceName(), ipNet); err != nil {
logrus.WithError(err).Debugf("failed to remove virtual ip %v to loopback", ipNet)
logrus.WithError(err).Warnf("Failed to remove virtual ip %v to loopback", ipNet)
}
}

Expand All @@ -760,7 +760,7 @@ func releaseOSSboxResources(osSbox osl.Sandbox, ep *endpoint) {
// Remove non-interface routes.
for _, r := range joinInfo.StaticRoutes {
if err := osSbox.RemoveStaticRoute(r); err != nil {
logrus.Debugf("Remove route failed: %v", err)
logrus.WithError(err).Warnf("Remove route failed")
}
}
}
Expand Down