Ensure duration of lookup is set if ip resolution fails (#180)
authorConor Broderick <conor.broderick@robustperception.io>
Tue, 4 Jul 2017 11:53:41 +0000 (12:53 +0100)
committerBrian Brazil <brian.brazil@robustperception.io>
Tue, 4 Jul 2017 11:53:41 +0000 (12:53 +0100)
utils.go

index c885c7f3a2602ddfe953f9c7e582936bddf543eb..1828a4fb4eb3e249c6b4a113fc5686f75a40d1db 100644 (file)
--- a/utils.go
+++ b/utils.go
@@ -39,6 +39,8 @@ func chooseProtocol(preferredIPProtocol string, target string, registry *prometh
 
        resolveStart := time.Now()
 
+       defer probeDNSLookupTimeSeconds.Add(time.Since(resolveStart).Seconds())
+
        ip, err := net.ResolveIPAddr(preferredIPProtocol, target)
        if err != nil {
                ip, err = net.ResolveIPAddr(fallbackProtocol, target)
@@ -47,8 +49,6 @@ func chooseProtocol(preferredIPProtocol string, target string, registry *prometh
                }
        }
 
-       probeDNSLookupTimeSeconds.Add(time.Since(resolveStart).Seconds())
-
        if ip.IP.To4() == nil {
                probeIPProtocolGauge.Set(6)
        } else {