Skip to content

Commit

Permalink
reverse_proxy: Upstream.String() method returns either LookupSRV or Dial
Browse files Browse the repository at this point in the history
Either Dial or LookupSRV will be set, but if we rely on Dial always
being set, we could run into bugs.

Note: Health checks don't support SRV upstreams.
  • Loading branch information
mholt committed Mar 27, 2020
1 parent 397e04e commit e207240
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions modules/caddyhttp/reverseproxy/hosts.go
Expand Up @@ -96,6 +96,13 @@ type Upstream struct {
cb CircuitBreaker
}

func (u Upstream) String() string {
if u.LookupSRV != "" {
return u.LookupSRV
}
return u.Dial
}

// Available returns true if the remote host
// is available to receive requests. This is
// the method that should be used by selection
Expand Down
5 changes: 3 additions & 2 deletions modules/caddyhttp/reverseproxy/reverseproxy.go
Expand Up @@ -172,7 +172,7 @@ func (h *Handler) Provision(ctx caddy.Context) error {
for _, upstream := range h.Upstreams {
// create or get the host representation for this upstream
var host Host = new(upstreamHost)
existingHost, loaded := hosts.LoadOrStore(upstream.Dial, host)
existingHost, loaded := hosts.LoadOrStore(upstream.String(), host)
if loaded {
host = existingHost.(Host)
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func (h *Handler) Cleanup() error {

// remove hosts from our config from the pool
for _, upstream := range h.Upstreams {
hosts.Delete(upstream.Dial)
hosts.Delete(upstream.String())
}

return nil
Expand Down Expand Up @@ -446,6 +446,7 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, di Dia
}

h.logger.Debug("upstream roundtrip",
zap.String("upstream", di.Upstream.String()),
zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: req}),
zap.Object("headers", caddyhttp.LoggableHTTPHeader(res.Header)),
zap.Duration("duration", duration),
Expand Down

0 comments on commit e207240

Please sign in to comment.