Skip to content

Commit

Permalink
[chore] [exporter/mezmo] Use NewDefaultClientConfig instead of manual…
Browse files Browse the repository at this point in the history
…ly creating struct (open-telemetry#35541)

**Description:**
This PR makes usage of `NewDefaultClientConfig` instead of manually
creating the confighttp.ClientConfig struct.

**Link to tracking Issue:** open-telemetry#35457
  • Loading branch information
mackjmr authored and jriguera committed Oct 4, 2024
1 parent 6093eb4 commit b97d683
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions exporter/mezmoexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type Config struct {

// returns default http client settings
func createDefaultClientConfig() confighttp.ClientConfig {
return confighttp.ClientConfig{
Timeout: defaultTimeout,
}
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Timeout = defaultTimeout
return clientConfig
}

func (c *Config) Validate() error {
Expand Down
8 changes: 7 additions & 1 deletion exporter/mezmoexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -42,7 +43,12 @@ func TestLoadConfig(t *testing.T) {
id: component.NewIDWithName(metadata.Type, "allsettings"),
expected: &Config{
ClientConfig: confighttp.ClientConfig{
Timeout: 5 * time.Second,
Timeout: 5 * time.Second,
MaxIdleConns: &defaultMaxIdleConns,
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &defaultIdleConnTimeout,
Headers: map[string]configopaque.String{},
},
BackOffConfig: configretry.BackOffConfig{
Enabled: false,
Expand Down
14 changes: 13 additions & 1 deletion exporter/mezmoexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package mezmoexporter

import (
"context"
"net/http"
"testing"
"time"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/exportertest"
Expand All @@ -24,6 +26,11 @@ func TestType(t *testing.T) {
assert.Equal(t, pType, metadata.Type)
}

var defaultMaxIdleConns = http.DefaultTransport.(*http.Transport).MaxIdleConns
var defaultMaxIdleConnsPerHost = http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost
var defaultMaxConnsPerHost = http.DefaultTransport.(*http.Transport).MaxConnsPerHost
var defaultIdleConnTimeout = http.DefaultTransport.(*http.Transport).IdleConnTimeout

func TestCreateDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
Expand All @@ -33,7 +40,12 @@ func TestCreateDefaultConfig(t *testing.T) {
IngestKey: "",

ClientConfig: confighttp.ClientConfig{
Timeout: 5 * time.Second,
Timeout: 5 * time.Second,
MaxIdleConns: &defaultMaxIdleConns,
MaxIdleConnsPerHost: &defaultMaxIdleConnsPerHost,
MaxConnsPerHost: &defaultMaxConnsPerHost,
IdleConnTimeout: &defaultIdleConnTimeout,
Headers: map[string]configopaque.String{},
},
BackOffConfig: configretry.NewDefaultBackOffConfig(),
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
Expand Down

0 comments on commit b97d683

Please sign in to comment.