Skip to content

Commit

Permalink
Add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Feb 11, 2022
1 parent 6ddccfd commit a35ed69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions modules/caddyhttp/reverseproxy/reverseproxy.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion modules/caddyhttp/reverseproxy/upstreams.go
Expand Up @@ -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
Expand All @@ -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),
}
}

Expand Down

0 comments on commit a35ed69

Please sign in to comment.