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

move ToClientWithHost to ToClient #5737

Merged
merged 5 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

### 🛑 Breaking changes 🛑

- Change`confighttp.ToClient` to accept a `component.Host` (#5737)

### 🚩 Deprecations 🚩

### 💡 Enhancements 💡

- `ocb` now exits with an error if it fails to load the build configuration. (#5731)
- Deprecate `HTTPClientSettings.ToClientWithHost` (#5737)

### 🧰 Bug fixes 🧰

Expand Down
9 changes: 4 additions & 5 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"golang.org/x/net/http2"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configauth"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/configtls"
Expand Down Expand Up @@ -99,8 +98,7 @@ func NewDefaultHTTPClientSettings() HTTPClientSettings {
}

// ToClient creates an HTTP client.
// Deprecated: [v0.55.0] Use ToClientWithHost instead.
func (hcs *HTTPClientSettings) ToClient(ext map[config.ComponentID]component.Extension, settings component.TelemetrySettings) (*http.Client, error) {
func (hcs *HTTPClientSettings) ToClient(host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
tlsCfg, err := hcs.TLSSetting.LoadTLSConfig()
if err != nil {
return nil, err
Expand Down Expand Up @@ -156,6 +154,7 @@ func (hcs *HTTPClientSettings) ToClient(ext map[config.ComponentID]component.Ext
}

if hcs.Auth != nil {
ext := host.GetExtensions()
if ext == nil {
return nil, errors.New("extensions configuration not found")
}
Expand Down Expand Up @@ -184,9 +183,9 @@ func (hcs *HTTPClientSettings) ToClient(ext map[config.ComponentID]component.Ext
}, nil
}

// ToClientWithHost creates an HTTP client.
fatsheep9146 marked this conversation as resolved.
Show resolved Hide resolved
// Deprecated: [v0.57.0] use ToClient.
func (hcs *HTTPClientSettings) ToClientWithHost(host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
return hcs.ToClient(host.GetExtensions(), settings)
return hcs.ToClient(host, settings)
}

// Custom RoundTripper that adds headers.
Expand Down
16 changes: 8 additions & 8 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestAllHTTPClientSettings(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
tt := componenttest.NewNopTelemetrySettings()
tt.TracerProvider = nil
client, err := test.settings.ToClientWithHost(host, tt)
client, err := test.settings.ToClient(host, tt)
if test.shouldError {
assert.Error(t, err)
return
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestPartialHTTPClientSettings(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
tt := componenttest.NewNopTelemetrySettings()
tt.TracerProvider = nil
client, err := test.settings.ToClientWithHost(host, tt)
client, err := test.settings.ToClient(host, tt)
assert.NoError(t, err)
transport := client.Transport.(*http.Transport)
assert.EqualValues(t, 1024, transport.ReadBufferSize)
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestHTTPClientSettingsError(t *testing.T) {
}
for _, test := range tests {
t.Run(test.err, func(t *testing.T) {
_, err := test.settings.ToClientWithHost(host, componenttest.NewNopTelemetrySettings())
_, err := test.settings.ToClient(host, componenttest.NewNopTelemetrySettings())
assert.Regexp(t, test.err, err)
})
}
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client, err := test.settings.ToClientWithHost(test.host, componenttest.NewNopTelemetrySettings())
client, err := test.settings.ToClient(test.host, componenttest.NewNopTelemetrySettings())
if test.shouldErr {
assert.Error(t, err)
return
Expand Down Expand Up @@ -558,7 +558,7 @@ func TestHttpReception(t *testing.T) {
return rt, nil
}
}
client, errClient := hcs.ToClientWithHost(componenttest.NewNopHost(), component.TelemetrySettings{})
client, errClient := hcs.ToClient(componenttest.NewNopHost(), component.TelemetrySettings{})
require.NoError(t, errClient)

resp, errResp := client.Get(hcs.Endpoint)
Expand Down Expand Up @@ -810,7 +810,7 @@ func TestHttpHeaders(t *testing.T) {
"header1": "value1",
},
}
client, _ := setting.ToClientWithHost(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings())
client, _ := setting.ToClient(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings())
req, err := http.NewRequest("GET", setting.Endpoint, nil)
assert.NoError(t, err)
_, err = client.Do(req)
Expand Down Expand Up @@ -1048,12 +1048,12 @@ func BenchmarkHttpRequest(b *testing.B) {
b.Run(bb.name, func(b *testing.B) {
var c *http.Client
if !bb.clientPerThread {
c, err = hcs.ToClientWithHost(componenttest.NewNopHost(), component.TelemetrySettings{})
c, err = hcs.ToClient(componenttest.NewNopHost(), component.TelemetrySettings{})
require.NoError(b, err)
}
b.RunParallel(func(pb *testing.PB) {
if c == nil {
c, err = hcs.ToClientWithHost(componenttest.NewNopHost(), component.TelemetrySettings{})
c, err = hcs.ToClient(componenttest.NewNopHost(), component.TelemetrySettings{})
require.NoError(b, err)
}
for pb.Next() {
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func newExporter(cfg config.Exporter, set component.ExporterCreateSettings) (*ex
// start actually creates the HTTP client. The client construction is deferred till this point as this
// is the only place we get hold of Extensions which are required to construct auth round tripper.
func (e *exporter) start(_ context.Context, host component.Host) error {
client, err := e.config.HTTPClientSettings.ToClient(host.GetExtensions(), e.settings)
client, err := e.config.HTTPClientSettings.ToClient(host, e.settings)
if err != nil {
return err
}
Expand Down