Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http probe: skip DNS lookup if using proxy #338

Closed
wants to merge 11 commits into from
34 changes: 19 additions & 15 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,31 @@ 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
}
durationGaugeVec.WithLabelValues("resolve").Add(lookupTime)

httpClientConfig := module.HTTP.HTTPClientConfig
if len(httpClientConfig.TLSConfig.ServerName) == 0 {
// If there is no `server_name` in tls_config, use
// the hostname of the target.
httpClientConfig.TLSConfig.ServerName = targetHost
}

origHost := targetURL.Host
if httpClientConfig.ProxyURL.URL == nil {
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)
if targetPort == "" {
targetURL.Host = "[" + ip.String() + "]"
} else {
targetURL.Host = net.JoinHostPort(ip.String(), targetPort)
}
} else {
level.Info(logger).Log("msg", "Using proxy", "proxy", httpClientConfig.ProxyURL.URL)
}

// client, err := pconfig.NewHTTPClientFromConfig(&httpClientConfig)
client, err := pconfig.NewClientFromConfig(httpClientConfig, "http_probe", true)
if err != nil {
level.Error(logger).Log("msg", "Error generating HTTP client", "err", err)
Expand Down Expand Up @@ -315,14 +327,6 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
httpConfig.Method = "GET"
}

// Replace the host field in the URL with the IP we resolved.
origHost := targetURL.Host
if targetPort == "" {
targetURL.Host = "[" + ip.String() + "]"
} else {
targetURL.Host = net.JoinHostPort(ip.String(), targetPort)
}

var body io.Reader

// If a body is configured, add it to the request.
Expand Down