diff --git a/main.go b/main.go index efa666a1..97799688 100644 --- a/main.go +++ b/main.go @@ -128,27 +128,27 @@ func main() { // returns nil if not provided and falls back to simple TCP. tlsConfig := createTLSConfig(*esCA, *esClientCert, *esClientPrivateKey, *esInsecureSkipVerify) - httpTransport := &http.Transport{ + var httpTransport http.RoundTripper + + httpTransport = &http.Transport{ TLSClientConfig: tlsConfig, Proxy: http.ProxyFromEnvironment, } - httpClient := &http.Client{ - Timeout: *esTimeout, - Transport: httpTransport, - } - if *esApiKey != "" { apiKey := *esApiKey - httpClient = &http.Client{ - Timeout: *esTimeout, - Transport: &transportWithApiKey{ - underlyingTransport: httpTransport, - apiKey: apiKey, - }, + + httpTransport = &transportWithApiKey{ + underlyingTransport: httpTransport, + apiKey: apiKey, } } + httpClient := &http.Client{ + Timeout: *esTimeout, + Transport: httpTransport, + } + // version metric versionMetric := version.NewCollector(Name) prometheus.MustRegister(versionMetric)