diff --git a/retrieval/scrape.go b/retrieval/scrape.go index 74010fae8..cd91b1ba0 100644 --- a/retrieval/scrape.go +++ b/retrieval/scrape.go @@ -115,7 +115,7 @@ type scrapePool struct { } func newScrapePool(cfg *config.ScrapeConfig, app storage.SampleAppender) *scrapePool { - client, err := newHTTPClient(cfg) + client, err := NewHTTPClient(cfg) if err != nil { // Any errors that could occur here should be caught during config validation. log.Errorf("Error creating HTTP client for job %q: %s", cfg.JobName, err) @@ -167,7 +167,7 @@ func (sp *scrapePool) reload(cfg *config.ScrapeConfig) { sp.mtx.Lock() defer sp.mtx.Unlock() - client, err := newHTTPClient(cfg) + client, err := NewHTTPClient(cfg) if err != nil { // Any errors that could occur here should be caught during config validation. log.Errorf("Error creating HTTP client for job %q: %s", cfg.JobName, err) diff --git a/retrieval/target.go b/retrieval/target.go index 17cdcc3c9..10c04193f 100644 --- a/retrieval/target.go +++ b/retrieval/target.go @@ -66,7 +66,8 @@ func NewTarget(labels, metaLabels model.LabelSet, params url.Values) *Target { } } -func newHTTPClient(cfg *config.ScrapeConfig) (*http.Client, error) { +// NewHTTPClient returns a new HTTP client configured for the given scrape configuration. +func NewHTTPClient(cfg *config.ScrapeConfig) (*http.Client, error) { tlsOpts := httputil.TLSOptions{ InsecureSkipVerify: cfg.TLSConfig.InsecureSkipVerify, CAFile: cfg.TLSConfig.CAFile, diff --git a/retrieval/target_test.go b/retrieval/target_test.go index 0e01c1c53..d0d7018d6 100644 --- a/retrieval/target_test.go +++ b/retrieval/target_test.go @@ -155,7 +155,7 @@ func TestNewHTTPBearerToken(t *testing.T) { ScrapeTimeout: model.Duration(1 * time.Second), BearerToken: "1234", } - c, err := newHTTPClient(cfg) + c, err := NewHTTPClient(cfg) if err != nil { t.Fatal(err) } @@ -183,7 +183,7 @@ func TestNewHTTPBearerTokenFile(t *testing.T) { ScrapeTimeout: model.Duration(1 * time.Second), BearerTokenFile: "testdata/bearertoken.txt", } - c, err := newHTTPClient(cfg) + c, err := NewHTTPClient(cfg) if err != nil { t.Fatal(err) } @@ -213,7 +213,7 @@ func TestNewHTTPBasicAuth(t *testing.T) { Password: "password123", }, } - c, err := newHTTPClient(cfg) + c, err := NewHTTPClient(cfg) if err != nil { t.Fatal(err) } @@ -242,7 +242,7 @@ func TestNewHTTPCACert(t *testing.T) { CAFile: caCertPath, }, } - c, err := newHTTPClient(cfg) + c, err := NewHTTPClient(cfg) if err != nil { t.Fatal(err) } @@ -277,7 +277,7 @@ func TestNewHTTPClientCert(t *testing.T) { KeyFile: "testdata/client.key", }, } - c, err := newHTTPClient(cfg) + c, err := NewHTTPClient(cfg) if err != nil { t.Fatal(err) } @@ -307,7 +307,7 @@ func TestNewHTTPWithServerName(t *testing.T) { ServerName: "prometheus.rocks", }, } - c, err := newHTTPClient(cfg) + c, err := NewHTTPClient(cfg) if err != nil { t.Fatal(err) } @@ -337,7 +337,7 @@ func TestNewHTTPWithBadServerName(t *testing.T) { ServerName: "badname", }, } - c, err := newHTTPClient(cfg) + c, err := NewHTTPClient(cfg) if err != nil { t.Fatal(err) } @@ -377,7 +377,7 @@ func TestNewClientWithBadTLSConfig(t *testing.T) { KeyFile: "testdata/nonexistent_client.key", }, } - _, err := newHTTPClient(cfg) + _, err := NewHTTPClient(cfg) if err == nil { t.Fatalf("Expected error, got nil.") }