From 3612bba5d5200f80da0516e039703e357ba837b0 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 30 Oct 2017 16:51:58 +0100 Subject: [PATCH] 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 --- prober/utils.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 { -- 2.25.1