From: Ben Kochie Date: Mon, 30 Oct 2017 15:51:58 +0000 (+0100) Subject: Wrap DNS lookup metric time defer X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3612bba5d5200f80da0516e039703e357ba837b0;p=blackbox_exporter.git Wrap DNS lookup metric time defer 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 --- diff --git a/prober/utils.go b/prober/utils.go index 42a93ba..524341d 100644 --- a/prober/utils.go +++ b/prober/utils.go @@ -43,7 +43,9 @@ func chooseProtocol(preferredIPProtocol string, target string, registry *prometh 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 {