From 9a2842055f141dc1b84c14b4793e749807b61348 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 11 Feb 2022 12:31:27 -0700 Subject: [PATCH] Add debug logs --- modules/caddyhttp/reverseproxy/reverseproxy.go | 5 +++++ modules/caddyhttp/reverseproxy/upstreams.go | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index 6d75edd8b62..46d15ed23d7 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -438,6 +438,7 @@ func (h *Handler) proxyLoopIteration(r *http.Request, w http.ResponseWriter, pro for _, dUp := range dUpstreams { h.provisionUpstream(dUp) } + h.logger.Debug("provisioned dynamic upstreams", zap.Int("count", len(dUpstreams))) defer func() { // these upstreams are dynamic, so they are only used for this iteration // of the proxy loop; be sure to let them go away when we're done with them @@ -468,6 +469,10 @@ func (h *Handler) proxyLoopIteration(r *http.Request, w http.ResponseWriter, pro return true, fmt.Errorf("making dial info: %v", err) } + h.logger.Debug("selected upstream", + zap.String("dial", dialInfo.Address), + zap.Int("total_upstreams", len(upstreams))) + // attach to the request information about how to dial the upstream; // this is necessary because the information cannot be sufficiently // or satisfactorily represented in a URL diff --git a/modules/caddyhttp/reverseproxy/upstreams.go b/modules/caddyhttp/reverseproxy/upstreams.go index 56fd3b946da..eb5845fc7b2 100644 --- a/modules/caddyhttp/reverseproxy/upstreams.go +++ b/modules/caddyhttp/reverseproxy/upstreams.go @@ -137,6 +137,11 @@ func (su SRVUpstreams) GetUpstreams(r *http.Request) ([]*Upstream, error) { proto := repl.ReplaceAll(su.Proto, "") name := repl.ReplaceAll(su.Name, "") + su.logger.Debug("refreshing SRV upstreams", + zap.String("service", service), + zap.String("proto", proto), + zap.String("name", name)) + _, records, err := su.resolver.LookupSRV(r.Context(), service, proto, name) if err != nil { // From LookupSRV docs: "If the response contains invalid names, those records are filtered @@ -150,9 +155,13 @@ func (su SRVUpstreams) GetUpstreams(r *http.Request) ([]*Upstream, error) { upstreams := make([]*Upstream, len(records)) for i, rec := range records { - upstreams[i] = &Upstream{ - Dial: net.JoinHostPort(rec.Target, strconv.Itoa(int(rec.Port))), - } + su.logger.Debug("discovered SRV record", + zap.String("target", rec.Target), + zap.Uint16("port", rec.Port), + zap.Uint16("priority", rec.Priority), + zap.Uint16("weight", rec.Weight)) + addr := net.JoinHostPort(rec.Target, strconv.Itoa(int(rec.Port))) + upstreams[i] = &Upstream{Dial: addr} } // before adding a new one to the cache (as opposed to replacing stale one), make room if cache is full