Skip to content

Commit

Permalink
Add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt authored and francislavoie committed Feb 21, 2022
1 parent 7bfab12 commit 9a28420
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions modules/caddyhttp/reverseproxy/reverseproxy.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions modules/caddyhttp/reverseproxy/upstreams.go
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9a28420

Please sign in to comment.