Skip to content

Commit

Permalink
[chore] [receiver/expvar] Use confighttp.NewDefaultClientConfig inste…
Browse files Browse the repository at this point in the history
…ad of manually creating struct (open-telemetry#35614)

**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 jmichalek132 committed Oct 10, 2024
1 parent 1008a19 commit c906d78
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
9 changes: 4 additions & 5 deletions receiver/expvarreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func TestLoadConfig(t *testing.T) {
metricCfg := metadata.DefaultMetricsBuilderConfig()
metricCfg.Metrics.ProcessRuntimeMemstatsTotalAlloc.Enabled = true
metricCfg.Metrics.ProcessRuntimeMemstatsMallocs.Enabled = false

clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "http://localhost:8000/custom/path"
clientConfig.Timeout = time.Second * 5
tests := []struct {
id component.ID
expected component.Config
Expand All @@ -45,10 +47,7 @@ func TestLoadConfig(t *testing.T) {
InitialDelay: time.Second,
Timeout: time.Second * 5,
},
ClientConfig: confighttp.ClientConfig{
Endpoint: "http://localhost:8000/custom/path",
Timeout: time.Second * 5,
},
ClientConfig: clientConfig,
MetricsBuilderConfig: metricCfg,
},
},
Expand Down
10 changes: 5 additions & 5 deletions receiver/expvarreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func newMetricsReceiver(
}

func newDefaultConfig() component.Config {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = defaultEndpoint
clientConfig.Timeout = defaultTimeout
return &Config{
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultEndpoint,
Timeout: defaultTimeout,
},
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
}
6 changes: 3 additions & 3 deletions receiver/expvarreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ func TestValidConfig(t *testing.T) {

func TestCreateMetrics(t *testing.T) {
factory := NewFactory()
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = defaultEndpoint
metricsReceiver, err := factory.CreateMetrics(
context.Background(),
receivertest.NewNopSettings(),
&Config{
ControllerConfig: scraperhelper.ControllerConfig{
CollectionInterval: 10 * time.Second,
},
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultEndpoint,
},
ClientConfig: clientConfig,
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
},
consumertest.NewNop(),
Expand Down

0 comments on commit c906d78

Please sign in to comment.