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

[exporter/otlphttpexporter] Remove unnecessary nil assignment in default client config #11299

Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 13 additions & 4 deletions exporter/otlphttpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func TestUnmarshalDefaultConfig(t *testing.T) {
assert.Error(t, component.ValidateConfig(cfg))
}

var defaultMaxIdleConns = 100
var defaultMaxIdleConnsPerHost = 0
var defaultMaxConnsPerHost = 0
var defaultIdleConnTimeout = 90 * time.Second
mackjmr marked this conversation as resolved.
Show resolved Hide resolved

func TestUnmarshalConfig(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)
Expand Down Expand Up @@ -67,10 +72,14 @@ func TestUnmarshalConfig(t *testing.T) {
},
Insecure: true,
},
ReadBufferSize: 123,
WriteBufferSize: 345,
Timeout: time.Second * 10,
Compression: "gzip",
ReadBufferSize: 123,
WriteBufferSize: 345,
Timeout: time.Second * 10,
Compression: "gzip",
MaxIdleConns: &defaultMaxIdleConns,
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &defaultIdleConnTimeout,
},
}, cfg)
}
Expand Down
4 changes: 0 additions & 4 deletions exporter/otlphttpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ func createDefaultConfig() component.Config {
clientConfig.Compression = configcompression.TypeGzip
// We almost read 0 bytes, so no need to tune ReadBufferSize.
clientConfig.WriteBufferSize = 512 * 1024
clientConfig.MaxIdleConns = nil
clientConfig.MaxIdleConnsPerHost = nil
clientConfig.MaxConnsPerHost = nil
clientConfig.IdleConnTimeout = nil

return &Config{
RetryConfig: configretry.NewDefaultBackOffConfig(),
Expand Down
83 changes: 36 additions & 47 deletions exporter/otlphttpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@ func TestCreateMetricsExporter(t *testing.T) {
require.NotNil(t, oexp)
}

func clientConfig(endpoint string, headers map[string]configopaque.String, tlsSetting configtls.ClientConfig, compression configcompression.Type) confighttp.ClientConfig {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.TLSSetting = tlsSetting
clientConfig.Compression = compression
if endpoint != "" {
clientConfig.Endpoint = endpoint
}
if headers != nil {
clientConfig.Headers = headers
}
return clientConfig
}

func TestCreateTracesExporter(t *testing.T) {
var configCompression configcompression.Type
endpoint := "http://" + testutil.GetAvailableLocalAddress(t)

tests := []struct {
Expand All @@ -62,111 +76,86 @@ func TestCreateTracesExporter(t *testing.T) {
{
name: "NoEndpoint",
config: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: "",
},
ClientConfig: clientConfig("", nil, configtls.ClientConfig{}, configCompression),
},
mustFailOnCreate: true,
},
{
name: "UseSecure",
config: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: endpoint,
TLSSetting: configtls.ClientConfig{
Insecure: false,
},
},
ClientConfig: clientConfig(endpoint, nil, configtls.ClientConfig{
Insecure: false,
}, configCompression),
},
},
{
name: "Headers",
config: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: endpoint,
Headers: map[string]configopaque.String{
"hdr1": "val1",
"hdr2": "val2",
},
},
ClientConfig: clientConfig(endpoint, map[string]configopaque.String{
"hdr1": "val1",
"hdr2": "val2",
}, configtls.ClientConfig{}, configCompression),
},
},
{
name: "CaCert",
config: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: endpoint,
TLSSetting: configtls.ClientConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "test_cert.pem"),
},
ClientConfig: clientConfig(endpoint, nil, configtls.ClientConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "test_cert.pem"),
},
},
}, configCompression),
},
},
{
name: "CertPemFileError",
config: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: endpoint,
TLSSetting: configtls.ClientConfig{
Config: configtls.Config{
CAFile: "nosuchfile",
},
ClientConfig: clientConfig(endpoint, nil, configtls.ClientConfig{
Config: configtls.Config{
CAFile: "nosuchfile",
},
},
configCompression),
},
mustFailOnCreate: false,
mustFailOnStart: true,
},
{
name: "NoneCompression",
config: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: endpoint,
Compression: "none",
},
ClientConfig: clientConfig(endpoint, nil, configtls.ClientConfig{}, "none"),
},
},
{
name: "GzipCompression",
config: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: endpoint,
Compression: configcompression.TypeGzip,
},
ClientConfig: clientConfig(endpoint, nil, configtls.ClientConfig{}, configcompression.TypeGzip),
},
},
{
name: "SnappyCompression",
config: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: endpoint,
Compression: configcompression.TypeSnappy,
},
ClientConfig: clientConfig(endpoint, nil, configtls.ClientConfig{}, configcompression.TypeSnappy),
},
},
{
name: "ZstdCompression",
config: &Config{
ClientConfig: confighttp.ClientConfig{
Endpoint: endpoint,
Compression: configcompression.TypeZstd,
},
ClientConfig: clientConfig(endpoint, nil, configtls.ClientConfig{}, configcompression.TypeZstd),
},
},
{
name: "ProtoEncoding",
config: &Config{
Encoding: EncodingProto,
ClientConfig: confighttp.ClientConfig{Endpoint: endpoint},
ClientConfig: clientConfig(endpoint, nil, configtls.ClientConfig{}, configCompression),
},
},
{
name: "JSONEncoding",
config: &Config{
Encoding: EncodingJSON,
ClientConfig: confighttp.ClientConfig{Endpoint: endpoint},
ClientConfig: clientConfig(endpoint, nil, configtls.ClientConfig{}, configCompression),
},
},
}
Expand Down
Loading