@marcel91200 / caddy Mirror · read-only / commits / a8586b05
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 22:00 UTC

reverseproxy: Add logging for dynamic A upstreams (#5857)

Francis Lavoie committed Oct 11, 2023 at 11:50 UTC a8586b05aac81435f2a3d929a762fc994accbfdd
1 file changed +11 -1
modules/caddyhttp/reverseproxy/upstreams.go
+11 -1
@@ -251,6 +251,8 @@ type AUpstreams struct {
251 Versions *IPVersions `json:"versions,omitempty"`
252
253 resolver *net.Resolver
254 +
255 + logger *zap.Logger
256 }
257
258 // CaddyModule returns the Caddy module information.
@@ -261,7 +263,8 @@ func (AUpstreams) CaddyModule() caddy.ModuleInfo {
263 }
264 }
265
264 -func (au *AUpstreams) Provision(_ caddy.Context) error {
266 +func (au *AUpstreams) Provision(ctx caddy.Context) error {
267 + au.logger = ctx.Logger()
268 if au.Refresh == 0 {
269 au.Refresh = caddy.Duration(time.Minute)
270 }
@@ -343,6 +346,11 @@ func (au AUpstreams) GetUpstreams(r *http.Request) ([]*Upstream, error) {
346 name := repl.ReplaceAll(au.Name, "")
347 port := repl.ReplaceAll(au.Port, "")
348
349 + au.logger.Debug("refreshing A upstreams",
350 + zap.String("version", ipVersion),
351 + zap.String("name", name),
352 + zap.String("port", port))
353 +
354 ips, err := au.resolver.LookupIP(r.Context(), ipVersion, name)
355 if err != nil {
356 return nil, err
@@ -350,6 +358,8 @@ func (au AUpstreams) GetUpstreams(r *http.Request) ([]*Upstream, error) {
358
359 upstreams := make([]Upstream, len(ips))
360 for i, ip := range ips {
361 + au.logger.Debug("discovered A record",
362 + zap.String("ip", ip.String()))
363 upstreams[i] = Upstream{
364 Dial: net.JoinHostPort(ip.String(), port),
365 }