Wrap the DNS lookup time `defer` in an anonymous function to avoid
arguments being evaluated early.
Closes: https://github.com/prometheus/blackbox_exporter/issues/253
level.Info(logger).Log("msg", "Resolving target address", "preferred_ip_protocol", preferredIPProtocol)
resolveStart := time.Now()
- defer probeDNSLookupTimeSeconds.Add(time.Since(resolveStart).Seconds())
+ defer func() {
+ probeDNSLookupTimeSeconds.Add(time.Since(resolveStart).Seconds())
+ }()
ip, err := net.ResolveIPAddr(preferredIPProtocol, target)
if err != nil {