From e88372fc8c7d906a151a9cff096b6f4cf4f879bc Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 26 Sep 2024 15:38:26 +0700 Subject: [PATCH] cmd/cli: log request id when leaking --- cmd/cli/dns_proxy.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/cli/dns_proxy.go b/cmd/cli/dns_proxy.go index 370d8de..242864f 100644 --- a/cmd/cli/dns_proxy.go +++ b/cmd/cli/dns_proxy.go @@ -411,6 +411,7 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse { serveStaleCache := p.cache != nil && p.cfg.Service.CacheServeStale upstreamConfigs := p.upstreamConfigsFromUpstreamNumbers(upstreams) + leaked := false // If ctrld is going to leak query to OS resolver, check remote upstream in background, // so ctrld could be back to normal operation as long as the network is back online. if len(upstreamConfigs) > 0 && p.leakingQuery.Load() { @@ -418,6 +419,8 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse { go p.checkUpstream(upstreams[n], uc) } upstreamConfigs = nil + leaked = true + ctrld.Log(ctx, mainLog.Load().Debug(), "%v is down, leaking query to OS resolver", upstreams) } if len(upstreamConfigs) == 0 { @@ -435,7 +438,11 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *proxyResponse { // 4. Try remote upstream. isLanOrPtrQuery := false if req.ufr.matched { - ctrld.Log(ctx, mainLog.Load().Debug(), "%s, %s, %s -> %v", req.ufr.matchedPolicy, req.ufr.matchedNetwork, req.ufr.matchedRule, upstreams) + if leaked { + ctrld.Log(ctx, mainLog.Load().Debug(), "%s, %s, %s -> %v (leaked)", req.ufr.matchedPolicy, req.ufr.matchedNetwork, req.ufr.matchedRule, upstreams) + } else { + ctrld.Log(ctx, mainLog.Load().Debug(), "%s, %s, %s -> %v", req.ufr.matchedPolicy, req.ufr.matchedNetwork, req.ufr.matchedRule, upstreams) + } } else { switch { case isPrivatePtrLookup(req.msg):