Skip to content

Commit

Permalink
Update to use the non deprecated ToClientWithHost API (#12741)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Jul 27, 2022
1 parent d4ff1dc commit dc19b91
Show file tree
Hide file tree
Showing 29 changed files with 35 additions and 38 deletions.
6 changes: 3 additions & 3 deletions exporter/awsprometheusremotewriteexporter/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestRequestSignature(t *testing.T) {
return newSigningRoundTripperWithCredentials(authConfig, awsCreds, next, sdkInformation)
},
}
client, _ := setting.ToClient(componenttest.NewNopHost().GetExtensions(), componenttest.NewNopTelemetrySettings())
client, _ := setting.ToClientWithHost(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings())
req, err := http.NewRequest("POST", setting.Endpoint, strings.NewReader("a=1&b=2"))
assert.NoError(t, err)
_, err = client.Do(req)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestRequestSignatureEmptyBody(t *testing.T) {
return newSigningRoundTripperWithCredentials(authConfig, awsCreds, next, sdkInformation)
},
}
client, _ := setting.ToClient(componenttest.NewNopHost().GetExtensions(), componenttest.NewNopTelemetrySettings())
client, _ := setting.ToClientWithHost(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings())
req, err := http.NewRequest("GET", setting.Endpoint, nil)
assert.NoError(t, err)
_, err = client.Do(req)
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestLeakingBody(t *testing.T) {
return newSigningRoundTripperWithCredentials(authConfig, awsCreds, next, sdkInformation)
},
}
client, _ := setting.ToClient(componenttest.NewNopHost().GetExtensions(), componenttest.NewNopTelemetrySettings())
client, _ := setting.ToClientWithHost(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings())
checker := &checkCloser{Reader: strings.NewReader("a=1&b=2")}
req, err := http.NewRequest("POST", setting.Endpoint, checker)
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion exporter/dynatraceexporter/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (e *exporter) sendBatch(ctx context.Context, lines []string) error {

// start starts the exporter
func (e *exporter) start(_ context.Context, host component.Host) (err error) {
client, err := e.cfg.HTTPClientSettings.ToClient(host.GetExtensions(), e.settings)
client, err := e.cfg.HTTPClientSettings.ToClientWithHost(host, e.settings)
if err != nil {
e.settings.Logger.Error("Failed to construct HTTP client", zap.Error(err))
return fmt.Errorf("start: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion exporter/humioexporter/humio_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type humioClient struct {

// Constructs a new HTTP client for sending payloads to Humio
func newHumioClient(cfg *Config, settings component.TelemetrySettings, host component.Host) (exporterClient, error) {
client, err := cfg.HTTPClientSettings.ToClient(host.GetExtensions(), settings)
client, err := cfg.HTTPClientSettings.ToClientWithHost(host, settings)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/influxdbexporter/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func newInfluxHTTPWriter(logger common.Logger, config *Config, host component.Ho
config.HTTPClientSettings.Headers["Authorization"] = "Token " + config.Token
}

httpClient, err := config.HTTPClientSettings.ToClient(host.GetExtensions(), settings)
httpClient, err := config.HTTPClientSettings.ToClientWithHost(host, settings)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/jaegerthrifthttpexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type jaegerThriftHTTPSender struct {

// start starts the exporter
func (s *jaegerThriftHTTPSender) start(_ context.Context, host component.Host) (err error) {
s.client, err = s.config.HTTPClientSettings.ToClient(host.GetExtensions(), s.settings)
s.client, err = s.config.HTTPClientSettings.ToClientWithHost(host, s.settings)

if err != nil {
return consumererror.NewPermanent(err)
Expand Down
9 changes: 4 additions & 5 deletions exporter/logzioexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/pkg/cache"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/ptrace"
"google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/protobuf/proto"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger"
)

Expand Down Expand Up @@ -127,7 +126,7 @@ func newLogzioLogsExporter(config *Config, set component.ExporterCreateSettings)
}

func (exporter *logzioExporter) start(_ context.Context, host component.Host) error {
client, err := exporter.config.HTTPClientSettings.ToClient(host.GetExtensions(), exporter.settings)
client, err := exporter.config.HTTPClientSettings.ToClientWithHost(host, exporter.settings)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/lokiexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func encode(pb proto.Message) ([]byte, error) {
}

func (l *lokiExporter) start(_ context.Context, host component.Host) (err error) {
client, err := l.config.HTTPClientSettings.ToClient(host.GetExtensions(), l.settings)
client, err := l.config.HTTPClientSettings.ToClientWithHost(host, l.settings)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/mezmoexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (m *mezmoExporter) pushLogData(ctx context.Context, ld plog.Logs) error {
}

func (m *mezmoExporter) start(_ context.Context, host component.Host) (err error) {
m.client, err = m.config.HTTPClientSettings.ToClient(host.GetExtensions(), m.settings)
m.client, err = m.config.HTTPClientSettings.ToClientWithHost(host, m.settings)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/prometheusremotewriteexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func newPRWExporter(cfg *Config, set component.ExporterCreateSettings) (*prwExpo

// Start creates the prometheus client
func (prwe *prwExporter) Start(ctx context.Context, host component.Host) (err error) {
prwe.client, err = prwe.clientSettings.ToClient(host.GetExtensions(), prwe.settings)
prwe.client, err = prwe.clientSettings.ToClientWithHost(host, prwe.settings)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func newCorrelationClient(cfg *Config, accessToken string, params component.Expo
return nil, fmt.Errorf("failed to parse correlation endpoint URL %q: %w", cfg.Endpoint, err)
}

httpClient, err := cfg.ToClient(host.GetExtensions(), params.TelemetrySettings)
httpClient, err := cfg.ToClientWithHost(host, params.TelemetrySettings)
if err != nil {
return nil, fmt.Errorf("failed to create correlation API client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/sumologicexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func newMetricsExporter(

// start starts the exporter
func (se *sumologicexporter) start(_ context.Context, host component.Host) (err error) {
client, err := se.config.HTTPClientSettings.ToClient(host.GetExtensions(), se.settings)
client, err := se.config.HTTPClientSettings.ToClientWithHost(host, se.settings)
if err != nil {
return fmt.Errorf("failed to create HTTP Client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/zipkinexporter/zipkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func createZipkinExporter(cfg *Config, settings component.TelemetrySettings) (*z

// start creates the http client
func (ze *zipkinExporter) start(_ context.Context, host component.Host) (err error) {
ze.client, err = ze.clientSettings.ToClient(host.GetExtensions(), ze.settings)
ze.client, err = ze.clientSettings.ToClientWithHost(host, ze.settings)
return
}

Expand Down
2 changes: 1 addition & 1 deletion extension/httpforwarder/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (h *httpForwarder) Start(_ context.Context, host component.Host) error {
return fmt.Errorf("failed to bind to address %s: %w", h.config.Ingress.Endpoint, err)
}

httpClient, err := h.config.Egress.ToClient(host.GetExtensions(), h.settings)
httpClient, err := h.config.Egress.ToClientWithHost(host, h.settings)
if err != nil {
return fmt.Errorf("failed to create HTTP Client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/oauth2clientauthextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func TestFailContactingOAuth(t *testing.T) {
},
}

client, _ := setting.ToClient(componenttest.NewNopHost().GetExtensions(), componenttest.NewNopTelemetrySettings())
client, _ := setting.ToClientWithHost(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings())
req, err := http.NewRequest("POST", setting.Endpoint, nil)
assert.NoError(t, err)
_, err = client.Do(req)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type resourceDetectionProcessor struct {

// Start is invoked during service startup.
func (rdp *resourceDetectionProcessor) Start(ctx context.Context, host component.Host) error {
client, _ := rdp.httpClientSettings.ToClient(host.GetExtensions(), rdp.telemetrySettings)
client, _ := rdp.httpClientSettings.ToClientWithHost(host, rdp.telemetrySettings)
ctx = internal.ContextWithClient(ctx, client)
var err error
rdp.resource, rdp.schemaURL, err = rdp.provider.Get(ctx, client)
Expand Down
2 changes: 1 addition & 1 deletion receiver/apachereceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newApacheScraper(
}

func (r *apacheScraper) start(_ context.Context, host component.Host) error {
httpClient, err := r.cfg.ToClient(host.GetExtensions(), r.settings)
httpClient, err := r.cfg.ToClientWithHost(host, r.settings)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confighttp"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -91,13 +90,12 @@ func (e *EcsInfo) GetClusterName() string {
type ecsInfoOption func(*EcsInfo)

// New creates a k8sApiServer which can generate cluster-level metrics
func NewECSInfo(refreshInterval time.Duration, hostIPProvider hostIPProvider, settings component.TelemetrySettings, options ...ecsInfoOption) (*EcsInfo, error) {

func NewECSInfo(refreshInterval time.Duration, hostIPProvider hostIPProvider, host component.Host, settings component.TelemetrySettings, options ...ecsInfoOption) (*EcsInfo, error) {
setting := confighttp.HTTPClientSettings{
Timeout: defaultTimeout,
}

client, err := setting.ToClient(map[config.ComponentID]component.Extension{}, settings)
client, err := setting.ToClientWithHost(host, settings)

if err != nil {
settings.Logger.Warn("Failed to create a http client for ECS info!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestNewECSInfo(t *testing.T) {
}
hostIPProvider := &FakehostInfo{}

ecsinfo, _ := NewECSInfo(time.Minute, hostIPProvider, componenttest.NewNopTelemetrySettings(), containerInstanceInfoCreatorOpt, taskinfoCreatorOpt, cgroupScannerCreatorOpt)
ecsinfo, _ := NewECSInfo(time.Minute, hostIPProvider, componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings(), containerInstanceInfoCreatorOpt, taskinfoCreatorOpt, cgroupScannerCreatorOpt)
assert.NotNil(t, ecsinfo)

<-ecsinfo.taskInfoTestReadyC
Expand Down
2 changes: 1 addition & 1 deletion receiver/awscontainerinsightreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (acir *awsContainerInsightReceiver) Start(ctx context.Context, host compone
}
if acir.config.ContainerOrchestrator == ci.ECS {

ecsInfo, err := ecsinfo.NewECSInfo(acir.config.CollectionInterval, hostinfo, acir.settings)
ecsInfo, err := ecsinfo.NewECSInfo(acir.config.CollectionInterval, hostinfo, host, acir.settings)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/bigipreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var _ client = (*bigipClient)(nil)

// newClient creates an initialized client (but with no token)
func newClient(cfg *Config, host component.Host, settings component.TelemetrySettings, logger *zap.Logger) (client, error) {
httpClient, err := cfg.ToClient(host.GetExtensions(), settings)
httpClient, err := cfg.ToClientWithHost(host, settings)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP Client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/cloudfoundryreceiver/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newEnvelopeStreamFactory(
httpConfig confighttp.HTTPClientSettings,
host component.Host) (*EnvelopeStreamFactory, error) {

httpClient, err := httpConfig.ToClient(host.GetExtensions(), settings)
httpClient, err := httpConfig.ToClientWithHost(host, settings)
if err != nil {
return nil, fmt.Errorf("creating HTTP client for Cloud Foundry RLP Gateway: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/couchdbreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type couchDBClient struct {

// newCouchDBClient creates a new client to make requests for the CouchDB receiver.
func newCouchDBClient(cfg *Config, host component.Host, settings component.TelemetrySettings) (client, error) {
client, err := cfg.ToClient(host.GetExtensions(), settings)
client, err := cfg.ToClientWithHost(host, settings)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP Client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/elasticsearchreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type defaultElasticsearchClient struct {
var _ elasticsearchClient = (*defaultElasticsearchClient)(nil)

func newElasticsearchClient(settings component.TelemetrySettings, c Config, h component.Host) (*defaultElasticsearchClient, error) {
client, err := c.HTTPClientSettings.ToClient(h.GetExtensions(), settings)
client, err := c.HTTPClientSettings.ToClientWithHost(h, settings)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/expvarreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newExpVarScraper(cfg *Config, set component.ReceiverCreateSettings) *expVar
}

func (e *expVarScraper) start(_ context.Context, host component.Host) error {
client, err := e.cfg.HTTPClientSettings.ToClient(host.GetExtensions(), e.set.TelemetrySettings)
client, err := e.cfg.HTTPClientSettings.ToClientWithHost(host, e.set.TelemetrySettings)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/flinkmetricsreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type flinkClient struct {
}

func newClient(cfg *Config, host component.Host, settings component.TelemetrySettings, logger *zap.Logger) (client, error) {
httpClient, err := cfg.ToClient(host.GetExtensions(), settings)
httpClient, err := cfg.ToClientWithHost(host, settings)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP Client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/nginxreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func newNginxScraper(
}

func (r *nginxScraper) start(_ context.Context, host component.Host) error {
httpClient, err := r.cfg.ToClient(host.GetExtensions(), r.settings)
httpClient, err := r.cfg.ToClientWithHost(host, r.settings)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/nsxtreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var (
)

func newClient(c *Config, settings component.TelemetrySettings, host component.Host, logger *zap.Logger) (*nsxClient, error) {
client, err := c.HTTPClientSettings.ToClient(host.GetExtensions(), settings)
client, err := c.HTTPClientSettings.ToClientWithHost(host, settings)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/rabbitmqreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type rabbitmqCredentials struct {
}

func newClient(cfg *Config, host component.Host, settings component.TelemetrySettings, logger *zap.Logger) (client, error) {
httpClient, err := cfg.ToClient(host.GetExtensions(), settings)
httpClient, err := cfg.ToClientWithHost(host, settings)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP Client: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/riakreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type riakCredentials struct {
}

func newClient(cfg *Config, host component.Host, settings component.TelemetrySettings, logger *zap.Logger) (client, error) {
httpClient, err := cfg.ToClient(host.GetExtensions(), settings)
httpClient, err := cfg.ToClientWithHost(host, settings)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP Client: %w", err)
}
Expand Down

0 comments on commit dc19b91

Please sign in to comment.