diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index be1f07a2314..87b06031f56 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -431,6 +431,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 @@ -461,6 +462,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 b602a49054c..b1983775bf9 100644 --- a/modules/caddyhttp/reverseproxy/upstreams.go +++ b/modules/caddyhttp/reverseproxy/upstreams.go @@ -100,6 +100,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 := net.DefaultResolver.LookupSRV(r.Context(), service, proto, name) if err != nil { // From LookupSRV docs: "If the response contains invalid names, those records are filtered @@ -113,8 +118,14 @@ func (su SRVUpstreams) GetUpstreams(r *http.Request) ([]*Upstream, error) { upstreams := make([]*Upstream, len(records)) for i, rec := range records { + 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: net.JoinHostPort(rec.Target, strconv.Itoa(int(rec.Port))), + Dial: net.JoinHostPort(rec.Target, addr), } }