diff --git a/config.go b/config.go index 315874d..5e64c51 100644 --- a/config.go +++ b/config.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "io/ioutil" + "net/http" "time" "github.com/golang/glog" @@ -58,8 +59,9 @@ type httpConfig struct { Address string `yaml:"address"` // 127.0.0.1 XXX map[string]interface{} `yaml:",inline"` - tlsConfig *tls.Config - mcfg *moduleConfig + tlsConfig *tls.Config + httpClient *http.Client + mcfg *moduleConfig } type execConfig struct { @@ -136,11 +138,16 @@ func checkModuleConfig(name string, cfg *moduleConfig) error { cfg.HTTP.Address = "localhost" } - var err error - cfg.HTTP.tlsConfig, err = cfg.HTTP.getTLSConfig() + tlsConfig, err := cfg.HTTP.getTLSConfig() if err != nil { return errors.Wrap(err, "could not create tls config") } + cfg.HTTP.tlsConfig = tlsConfig + cfg.HTTP.httpClient = &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: tlsConfig, + }, + } case "exec": if len(cfg.Exec.XXX) != 0 { return fmt.Errorf("Unknown exec module configuration fields: %v", cfg.Exec.XXX) diff --git a/http.go b/http.go index 6409111..427647b 100644 --- a/http.go +++ b/http.go @@ -42,12 +42,7 @@ func (c httpConfig) GatherWithContext(ctx context.Context, r *http.Request) prom Path: c.Path, RawQuery: vs.Encode(), } - client := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: c.tlsConfig, - }, - } - resp, err := ctxhttp.Get(ctx, client, url.String()) + resp, err := ctxhttp.Get(ctx, c.httpClient, url.String()) if err != nil { if glog.V(1) { glog.Errorf("http proxy for module %v failed %+v", c.mcfg.name, err)