Skip to content

Commit

Permalink
fix: remove dns resolution when use_dns_proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Scapal committed Nov 27, 2019
1 parent 6628481 commit 6348550
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,13 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
})
)

for _, lv := range []string{"resolve", "connect", "tls", "processing", "transfer"} {
// Check the option to send the url unresolved to the proxy
skipDNS := module.HTTP.UseProxyDNS && module.HTTP.HTTPClientConfig.ProxyURL.URL != nil

if !skipDNS {
durationGaugeVec.WithLabelValues("resolve")
}
for _, lv := range []string{"connect", "tls", "processing", "transfer"} {
durationGaugeVec.WithLabelValues(lv)
}

Expand Down Expand Up @@ -315,12 +321,17 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
targetHost = targetURL.Host
}

ip, lookupTime, err := chooseProtocol(ctx, module.HTTP.IPProtocol, module.HTTP.IPProtocolFallback, targetHost, registry, logger)
if err != nil {
level.Error(logger).Log("msg", "Error resolving address", "err", err)
return false
// Resolve the host unless letting the proxy do the job.
var ip *net.IPAddr
if !skipDNS {
var lookupTime float64
ip, lookupTime, err = chooseProtocol(ctx, module.HTTP.IPProtocol, module.HTTP.IPProtocolFallback, targetHost, registry, logger)
if err != nil {
level.Error(logger).Log("msg", "Error resolving address", "err", err)
return false
}
durationGaugeVec.WithLabelValues("resolve").Add(lookupTime)
}
durationGaugeVec.WithLabelValues("resolve").Add(lookupTime)

httpClientConfig := module.HTTP.HTTPClientConfig
if len(httpClientConfig.TLSConfig.ServerName) == 0 {
Expand Down Expand Up @@ -369,7 +380,6 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr

// Replace the host field in the URL with the IP we resolved unless letting a proxy server do the name resolution.
origHost := targetURL.Host
skipDNS := module.HTTP.UseProxyDNS && module.HTTP.HTTPClientConfig.ProxyURL.URL != nil

if !skipDNS {
if targetPort == "" {
Expand Down

0 comments on commit 6348550

Please sign in to comment.