Skip to content

Commit

Permalink
[chore] [receiver/cloudfoundry] Use confighttp.NewDefaultClientConfig…
Browse files Browse the repository at this point in the history
… instead of manually creating struct (#35612)

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

**Link to tracking Issue:** #35457
  • Loading branch information
mackjmr authored Oct 4, 2024
1 parent e20d27c commit 7f65b87
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
47 changes: 21 additions & 26 deletions receiver/cloudfoundryreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ func TestLoadConfig(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)

clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "https://log-stream.sys.example.internal"
clientConfig.TLSSetting = configtls.ClientConfig{
InsecureSkipVerify: true,
}
clientConfig.Timeout = time.Second * 20

tests := []struct {
id component.ID
expected component.Config
Expand All @@ -34,14 +41,8 @@ func TestLoadConfig(t *testing.T) {
id: component.NewIDWithName(metadata.Type, "one"),
expected: &Config{
RLPGateway: RLPGatewayConfig{
ClientConfig: confighttp.ClientConfig{
Endpoint: "https://log-stream.sys.example.internal",
TLSSetting: configtls.ClientConfig{
InsecureSkipVerify: true,
},
Timeout: time.Second * 20,
},
ShardID: "otel-test",
ClientConfig: clientConfig,
ShardID: "otel-test",
},
UAA: UAAConfig{
LimitedClientConfig: LimitedClientConfig{
Expand All @@ -67,14 +68,8 @@ func TestLoadConfig(t *testing.T) {
id: component.NewIDWithName(metadata.Type, "shardidnotdefined"),
expected: &Config{
RLPGateway: RLPGatewayConfig{
ClientConfig: confighttp.ClientConfig{
Endpoint: "https://log-stream.sys.example.internal",
TLSSetting: configtls.ClientConfig{
InsecureSkipVerify: true,
},
Timeout: time.Second * 20,
},
ShardID: "opentelemetry",
ClientConfig: clientConfig,
ShardID: "opentelemetry",
},
UAA: UAAConfig{
LimitedClientConfig: LimitedClientConfig{
Expand Down Expand Up @@ -133,22 +128,22 @@ func TestInvalidConfigValidation(t *testing.T) {
func TestHTTPConfigurationStructConsistency(t *testing.T) {
// LimitedClientConfig must have the same structure as ClientConfig, but without the fields that the UAA
// library does not support.
checkTypeFieldMatch(t, "Endpoint", reflect.TypeOf(LimitedClientConfig{}), reflect.TypeOf(confighttp.ClientConfig{}))
checkTypeFieldMatch(t, "TLSSetting", reflect.TypeOf(LimitedClientConfig{}), reflect.TypeOf(confighttp.ClientConfig{}))
checkTypeFieldMatch(t, "Endpoint", reflect.TypeOf(LimitedClientConfig{}), reflect.TypeOf(confighttp.NewDefaultClientConfig()))
checkTypeFieldMatch(t, "TLSSetting", reflect.TypeOf(LimitedClientConfig{}), reflect.TypeOf(confighttp.NewDefaultClientConfig()))
checkTypeFieldMatch(t, "InsecureSkipVerify", reflect.TypeOf(LimitedTLSClientSetting{}), reflect.TypeOf(configtls.ClientConfig{}))
}

func loadSuccessfulConfig(t *testing.T) *Config {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = "https://log-stream.sys.example.internal"
clientConfig.Timeout = time.Second * 20
clientConfig.TLSSetting = configtls.ClientConfig{
InsecureSkipVerify: true,
}
configuration := &Config{
RLPGateway: RLPGatewayConfig{
ClientConfig: confighttp.ClientConfig{
Endpoint: "https://log-stream.sys.example.internal",
Timeout: time.Second * 20,
TLSSetting: configtls.ClientConfig{
InsecureSkipVerify: true,
},
},
ShardID: "otel-test",
ClientConfig: clientConfig,
ShardID: "otel-test",
},
UAA: UAAConfig{
LimitedClientConfig: LimitedClientConfig{
Expand Down
14 changes: 7 additions & 7 deletions receiver/cloudfoundryreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ func NewFactory() receiver.Factory {
}

func createDefaultConfig() component.Config {
clientConfig := confighttp.NewDefaultClientConfig()
clientConfig.Endpoint = defaultURL
clientConfig.TLSSetting = configtls.ClientConfig{
InsecureSkipVerify: false,
}
return &Config{
RLPGateway: RLPGatewayConfig{
ClientConfig: confighttp.ClientConfig{
Endpoint: defaultURL,
TLSSetting: configtls.ClientConfig{
InsecureSkipVerify: false,
},
},
ShardID: defaultRLPGatewayShardID,
ClientConfig: clientConfig,
ShardID: defaultRLPGatewayShardID,
},
UAA: UAAConfig{
LimitedClientConfig: LimitedClientConfig{
Expand Down

0 comments on commit 7f65b87

Please sign in to comment.