From 83118eaeb80df2281d9398ff392d3124c0f0001d Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Sat, 23 Jul 2022 23:59:58 +0800 Subject: [PATCH 1/5] move ToClientWithHost to ToClient Signed-off-by: Ziqi Zhao --- config/confighttp/confighttp.go | 13 +++---------- config/confighttp/confighttp_test.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 04f1d27880d..4a90efa2b9c 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -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" @@ -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 @@ -156,11 +154,11 @@ func (hcs *HTTPClientSettings) ToClient(ext map[config.ComponentID]component.Ext } if hcs.Auth != nil { - if ext == nil { + if host.GetExtensions() == nil { return nil, errors.New("extensions configuration not found") } - httpCustomAuthRoundTripper, aerr := hcs.Auth.GetClientAuthenticator(ext) + httpCustomAuthRoundTripper, aerr := hcs.Auth.GetClientAuthenticator(host.GetExtensions()) if aerr != nil { return nil, aerr } @@ -184,11 +182,6 @@ func (hcs *HTTPClientSettings) ToClient(ext map[config.ComponentID]component.Ext }, nil } -// ToClientWithHost creates an HTTP client. -func (hcs *HTTPClientSettings) ToClientWithHost(host component.Host, settings component.TelemetrySettings) (*http.Client, error) { - return hcs.ToClient(host.GetExtensions(), settings) -} - // Custom RoundTripper that adds headers. type headerRoundTripper struct { transport http.RoundTripper diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 85548a522b8..d37e50d4aba 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -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 @@ -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) @@ -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) }) } @@ -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 @@ -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) @@ -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) @@ -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() { From 4744bb9a3c71c17cf99a24cf786de34fe47ed804 Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Sun, 24 Jul 2022 10:26:27 +0800 Subject: [PATCH 2/5] fix bugs Signed-off-by: Ziqi Zhao --- exporter/otlphttpexporter/otlp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exporter/otlphttpexporter/otlp.go b/exporter/otlphttpexporter/otlp.go index 4498a80e632..e40fc0b3503 100644 --- a/exporter/otlphttpexporter/otlp.go +++ b/exporter/otlphttpexporter/otlp.go @@ -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 } From e21a1a23e1c02f58c8c9919f0a9f54e3d3fb6945 Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Sun, 24 Jul 2022 10:38:01 +0800 Subject: [PATCH 3/5] add change log Signed-off-by: Ziqi Zhao --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d56482c4a4..d82208c592e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### 🛑 Breaking changes 🛑 +- Remove deprecated `confighttp.ToClient` (#5737) + ### 🚩 Deprecations 🚩 ### 💡 Enhancements 💡 From 386de1fb115c0310d7769b75d2e22ed8737542d1 Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Wed, 27 Jul 2022 07:24:46 +0800 Subject: [PATCH 4/5] Update CHANGELOG.md Co-authored-by: Pablo Baeyens --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d82208c592e..dc21a6e8896 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### 🛑 Breaking changes 🛑 -- Remove deprecated `confighttp.ToClient` (#5737) +- Change`confighttp.ToClient` to accept a `component.Host` (#5737) ### 🚩 Deprecations 🚩 From 2242f31545e6ea90ed61081eea1cb871b69c5e8c Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Wed, 27 Jul 2022 07:33:55 +0800 Subject: [PATCH 5/5] fix for comments Signed-off-by: Ziqi Zhao --- CHANGELOG.md | 1 + config/confighttp/confighttp.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc21a6e8896..a3546cc73f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### 💡 Enhancements 💡 - `ocb` now exits with an error if it fails to load the build configuration. (#5731) +- Deprecate `HTTPClientSettings.ToClientWithHost` (#5737) ### 🧰 Bug fixes 🧰 diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 4a90efa2b9c..70e50e1a72e 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -154,11 +154,12 @@ func (hcs *HTTPClientSettings) ToClient(host component.Host, settings component. } if hcs.Auth != nil { - if host.GetExtensions() == nil { + ext := host.GetExtensions() + if ext == nil { return nil, errors.New("extensions configuration not found") } - httpCustomAuthRoundTripper, aerr := hcs.Auth.GetClientAuthenticator(host.GetExtensions()) + httpCustomAuthRoundTripper, aerr := hcs.Auth.GetClientAuthenticator(ext) if aerr != nil { return nil, aerr } @@ -182,6 +183,11 @@ func (hcs *HTTPClientSettings) ToClient(host component.Host, settings component. }, nil } +// Deprecated: [v0.57.0] use ToClient. +func (hcs *HTTPClientSettings) ToClientWithHost(host component.Host, settings component.TelemetrySettings) (*http.Client, error) { + return hcs.ToClient(host, settings) +} + // Custom RoundTripper that adds headers. type headerRoundTripper struct { transport http.RoundTripper