Skip to content

Commit

Permalink
[confighttp] Deprecate HTTPClientSettings, use HTTPClientConfig inste…
Browse files Browse the repository at this point in the history
…ad (#9404)

**Description:**
Deprecate HTTPClientSettings, use HTTPClientConfig instead

**Link to tracking Issue:**
#6767
  • Loading branch information
atoulme authored Jan 29, 2024
1 parent 8b95295 commit 1ed45ec
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 61 deletions.
25 changes: 25 additions & 0 deletions .chloggen/httpclientsettings_httpclientconfig-breaking.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: otlphttpexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: otlphttpexporter.Config embeds the struct confighttp.HTTPClientConfig instead of confighttp.HTTPClientSettings

# One or more tracking issues or pull requests related to the change
issues: [6767]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
25 changes: 25 additions & 0 deletions .chloggen/httpclientsettings_httpclientconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: confighttp

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate HTTPClientSettings, use HTTPClientConfig instead

# One or more tracking issues or pull requests related to the change
issues: [6767]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
2 changes: 1 addition & 1 deletion config/confighttp/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestHTTPClientCompression(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, srv.URL, reqBody)
require.NoError(t, err, "failed to create request to test handler")

clientSettings := HTTPClientSettings{
clientSettings := HTTPClientConfig{
Endpoint: srv.URL,
Compression: tt.encoding,
}
Expand Down
21 changes: 17 additions & 4 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import (
const headerContentEncoding = "Content-Encoding"

// HTTPClientSettings defines settings for creating an HTTP client.
type HTTPClientSettings struct {
// Deprecated: [v0.94.0] Use HTTPClientConfig instead
type HTTPClientSettings = HTTPClientConfig

// HTTPClientConfig defines settings for creating an HTTP client.
type HTTPClientConfig struct {
// The target URL to send data to (e.g.: http://some.url:9411/v1/traces).
Endpoint string `mapstructure:"endpoint"`

Expand Down Expand Up @@ -103,19 +107,28 @@ type HTTPClientSettings struct {
// the default values of 'MaxIdleConns' and 'IdleConnTimeout'.
// Other config options are not added as they are initialized with 'zero value' by GoLang as default.
// We encourage to use this function to create an object of HTTPClientSettings.
func NewDefaultHTTPClientSettings() HTTPClientSettings {
// Deprecated: [v0.94.0] Use NewDefaultHTTPClientConfig instead
func NewDefaultHTTPClientSettings() HTTPClientConfig {
return NewDefaultHTTPClientConfig()
}

// NewDefaultHTTPClientConfig returns HTTPClientConfig type object with
// the default values of 'MaxIdleConns' and 'IdleConnTimeout'.
// Other config options are not added as they are initialized with 'zero value' by GoLang as default.
// We encourage to use this function to create an object of HTTPClientConfig.
func NewDefaultHTTPClientConfig() HTTPClientConfig {
// The default values are taken from the values of 'DefaultTransport' of 'http' package.
maxIdleConns := 100
idleConnTimeout := 90 * time.Second

return HTTPClientSettings{
return HTTPClientConfig{
MaxIdleConns: &maxIdleConns,
IdleConnTimeout: &idleConnTimeout,
}
}

// ToClient creates an HTTP client.
func (hcs *HTTPClientSettings) ToClient(host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
func (hcs *HTTPClientConfig) ToClient(host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
tlsCfg, err := hcs.TLSSetting.LoadTLSConfig()
if err != nil {
return nil, err
Expand Down
50 changes: 25 additions & 25 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func TestAllHTTPClientSettings(t *testing.T) {
http2PingTimeout := 5 * time.Second
tests := []struct {
name string
settings HTTPClientSettings
settings HTTPClientConfig
shouldError bool
}{
{
name: "all_valid_settings",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Insecure: false,
Expand All @@ -82,7 +82,7 @@ func TestAllHTTPClientSettings(t *testing.T) {
},
{
name: "all_valid_settings_with_none_compression",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Insecure: false,
Expand All @@ -103,7 +103,7 @@ func TestAllHTTPClientSettings(t *testing.T) {
},
{
name: "all_valid_settings_with_gzip_compression",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Insecure: false,
Expand All @@ -124,7 +124,7 @@ func TestAllHTTPClientSettings(t *testing.T) {
},
{
name: "all_valid_settings_http2_health_check",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Insecure: false,
Expand All @@ -145,7 +145,7 @@ func TestAllHTTPClientSettings(t *testing.T) {
},
{
name: "error_round_tripper_returned",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Insecure: false,
Expand Down Expand Up @@ -193,12 +193,12 @@ func TestPartialHTTPClientSettings(t *testing.T) {

tests := []struct {
name string
settings HTTPClientSettings
settings HTTPClientConfig
shouldError bool
}{
{
name: "valid_partial_settings",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Insecure: false,
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestPartialHTTPClientSettings(t *testing.T) {
}

func TestDefaultHTTPClientSettings(t *testing.T) {
httpClientSettings := NewDefaultHTTPClientSettings()
httpClientSettings := NewDefaultHTTPClientConfig()
assert.EqualValues(t, 100, *httpClientSettings.MaxIdleConns)
assert.EqualValues(t, 90*time.Second, *httpClientSettings.IdleConnTimeout)
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestProxyURL(t *testing.T) {
}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
s := NewDefaultHTTPClientSettings()
s := NewDefaultHTTPClientConfig()
s.ProxyURL = tC.proxyURL

tt := componenttest.NewNopTelemetrySettings()
Expand Down Expand Up @@ -296,12 +296,12 @@ func TestHTTPClientSettingsError(t *testing.T) {
ext: map[component.ID]component.Component{},
}
tests := []struct {
settings HTTPClientSettings
settings HTTPClientConfig
err string
}{
{
err: "^failed to load TLS config: failed to load CA CertPool File: failed to load cert /doesnt/exist:",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "",
TLSSetting: configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
Expand All @@ -314,7 +314,7 @@ func TestHTTPClientSettingsError(t *testing.T) {
},
{
err: "^failed to load TLS config: failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "",
TLSSetting: configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
Expand All @@ -327,7 +327,7 @@ func TestHTTPClientSettingsError(t *testing.T) {
},
{
err: "failed to resolve authenticator \"dummy\": authenticator not found",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "https://localhost:1234/v1/traces",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")},
},
Expand All @@ -345,12 +345,12 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
tests := []struct {
name string
shouldErr bool
settings HTTPClientSettings
settings HTTPClientConfig
host component.Host
}{
{
name: "no_auth_extension_enabled",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
Auth: nil,
},
Expand All @@ -365,7 +365,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
{
name: "with_auth_configuration_and_no_extension",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")},
},
Expand All @@ -378,7 +378,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
{
name: "with_auth_configuration_and_no_extension_map",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("dummy")},
},
Expand All @@ -387,7 +387,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
{
name: "with_auth_configuration_has_extension",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")},
},
Expand All @@ -400,7 +400,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
{
name: "with_auth_configuration_has_extension_and_headers",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")},
Headers: map[string]configopaque.String{"foo": "bar"},
Expand All @@ -414,7 +414,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
{
name: "with_auth_configuration_has_extension_and_compression",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")},
Compression: configcompression.Gzip,
Expand All @@ -428,7 +428,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
},
{
name: "with_auth_configuration_has_err_extension",
settings: HTTPClientSettings{
settings: HTTPClientConfig{
Endpoint: "localhost:1234",
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")},
},
Expand Down Expand Up @@ -713,7 +713,7 @@ func TestHttpReception(t *testing.T) {
expectedProto = "HTTP/1.1"
}

hcs := &HTTPClientSettings{
hcs := &HTTPClientConfig{
Endpoint: prefix + ln.Addr().String(),
TLSSetting: *tt.tlsClientCreds,
}
Expand Down Expand Up @@ -1044,7 +1044,7 @@ func TestHttpClientHeaders(t *testing.T) {
}))
defer server.Close()
serverURL, _ := url.Parse(server.URL)
setting := HTTPClientSettings{
setting := HTTPClientConfig{
Endpoint: serverURL.String(),
TLSSetting: configtls.TLSClientSetting{},
ReadBufferSize: 0,
Expand Down Expand Up @@ -1336,7 +1336,7 @@ func BenchmarkHttpRequest(b *testing.B) {
}()

for _, bb := range tests {
hcs := &HTTPClientSettings{
hcs := &HTTPClientConfig{
Endpoint: "https://" + ln.Addr().String(),
TLSSetting: *tlsClientCreds,
}
Expand Down
6 changes: 3 additions & 3 deletions exporter/otlphttpexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

// Config defines configuration for OTLP/HTTP exporter.
type Config struct {
confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
QueueConfig exporterhelper.QueueSettings `mapstructure:"sending_queue"`
RetryConfig configretry.BackOffConfig `mapstructure:"retry_on_failure"`
confighttp.HTTPClientConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
QueueConfig exporterhelper.QueueSettings `mapstructure:"sending_queue"`
RetryConfig configretry.BackOffConfig `mapstructure:"retry_on_failure"`

// The URL to send traces to. If omitted the Endpoint + "/v1/traces" will be used.
TracesEndpoint string `mapstructure:"traces_endpoint"`
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestUnmarshalConfig(t *testing.T) {
NumConsumers: 2,
QueueSize: 10,
},
HTTPClientSettings: confighttp.HTTPClientSettings{
HTTPClientConfig: confighttp.HTTPClientConfig{
Headers: map[string]configopaque.String{
"can you have a . here?": "F0000000-0000-0000-0000-000000000000",
"header1": "234",
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func createDefaultConfig() component.Config {
return &Config{
RetryConfig: configretry.NewDefaultBackOffConfig(),
QueueConfig: exporterhelper.NewDefaultQueueSettings(),
HTTPClientSettings: confighttp.HTTPClientSettings{
HTTPClientConfig: confighttp.HTTPClientConfig{
Endpoint: "",
Timeout: 30 * time.Second,
Headers: map[string]configopaque.String{},
Expand Down
Loading

0 comments on commit 1ed45ec

Please sign in to comment.