Skip to content

Commit 7f65b87

Browse files
authored
[chore] [receiver/cloudfoundry] Use confighttp.NewDefaultClientConfig 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
1 parent e20d27c commit 7f65b87

File tree

2 files changed

+28
-33
lines changed

2 files changed

+28
-33
lines changed

receiver/cloudfoundryreceiver/config_test.go

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func TestLoadConfig(t *testing.T) {
2525
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
2626
require.NoError(t, err)
2727

28+
clientConfig := confighttp.NewDefaultClientConfig()
29+
clientConfig.Endpoint = "https://log-stream.sys.example.internal"
30+
clientConfig.TLSSetting = configtls.ClientConfig{
31+
InsecureSkipVerify: true,
32+
}
33+
clientConfig.Timeout = time.Second * 20
34+
2835
tests := []struct {
2936
id component.ID
3037
expected component.Config
@@ -34,14 +41,8 @@ func TestLoadConfig(t *testing.T) {
3441
id: component.NewIDWithName(metadata.Type, "one"),
3542
expected: &Config{
3643
RLPGateway: RLPGatewayConfig{
37-
ClientConfig: confighttp.ClientConfig{
38-
Endpoint: "https://log-stream.sys.example.internal",
39-
TLSSetting: configtls.ClientConfig{
40-
InsecureSkipVerify: true,
41-
},
42-
Timeout: time.Second * 20,
43-
},
44-
ShardID: "otel-test",
44+
ClientConfig: clientConfig,
45+
ShardID: "otel-test",
4546
},
4647
UAA: UAAConfig{
4748
LimitedClientConfig: LimitedClientConfig{
@@ -67,14 +68,8 @@ func TestLoadConfig(t *testing.T) {
6768
id: component.NewIDWithName(metadata.Type, "shardidnotdefined"),
6869
expected: &Config{
6970
RLPGateway: RLPGatewayConfig{
70-
ClientConfig: confighttp.ClientConfig{
71-
Endpoint: "https://log-stream.sys.example.internal",
72-
TLSSetting: configtls.ClientConfig{
73-
InsecureSkipVerify: true,
74-
},
75-
Timeout: time.Second * 20,
76-
},
77-
ShardID: "opentelemetry",
71+
ClientConfig: clientConfig,
72+
ShardID: "opentelemetry",
7873
},
7974
UAA: UAAConfig{
8075
LimitedClientConfig: LimitedClientConfig{
@@ -133,22 +128,22 @@ func TestInvalidConfigValidation(t *testing.T) {
133128
func TestHTTPConfigurationStructConsistency(t *testing.T) {
134129
// LimitedClientConfig must have the same structure as ClientConfig, but without the fields that the UAA
135130
// library does not support.
136-
checkTypeFieldMatch(t, "Endpoint", reflect.TypeOf(LimitedClientConfig{}), reflect.TypeOf(confighttp.ClientConfig{}))
137-
checkTypeFieldMatch(t, "TLSSetting", reflect.TypeOf(LimitedClientConfig{}), reflect.TypeOf(confighttp.ClientConfig{}))
131+
checkTypeFieldMatch(t, "Endpoint", reflect.TypeOf(LimitedClientConfig{}), reflect.TypeOf(confighttp.NewDefaultClientConfig()))
132+
checkTypeFieldMatch(t, "TLSSetting", reflect.TypeOf(LimitedClientConfig{}), reflect.TypeOf(confighttp.NewDefaultClientConfig()))
138133
checkTypeFieldMatch(t, "InsecureSkipVerify", reflect.TypeOf(LimitedTLSClientSetting{}), reflect.TypeOf(configtls.ClientConfig{}))
139134
}
140135

141136
func loadSuccessfulConfig(t *testing.T) *Config {
137+
clientConfig := confighttp.NewDefaultClientConfig()
138+
clientConfig.Endpoint = "https://log-stream.sys.example.internal"
139+
clientConfig.Timeout = time.Second * 20
140+
clientConfig.TLSSetting = configtls.ClientConfig{
141+
InsecureSkipVerify: true,
142+
}
142143
configuration := &Config{
143144
RLPGateway: RLPGatewayConfig{
144-
ClientConfig: confighttp.ClientConfig{
145-
Endpoint: "https://log-stream.sys.example.internal",
146-
Timeout: time.Second * 20,
147-
TLSSetting: configtls.ClientConfig{
148-
InsecureSkipVerify: true,
149-
},
150-
},
151-
ShardID: "otel-test",
145+
ClientConfig: clientConfig,
146+
ShardID: "otel-test",
152147
},
153148
UAA: UAAConfig{
154149
LimitedClientConfig: LimitedClientConfig{

receiver/cloudfoundryreceiver/factory.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ func NewFactory() receiver.Factory {
3333
}
3434

3535
func createDefaultConfig() component.Config {
36+
clientConfig := confighttp.NewDefaultClientConfig()
37+
clientConfig.Endpoint = defaultURL
38+
clientConfig.TLSSetting = configtls.ClientConfig{
39+
InsecureSkipVerify: false,
40+
}
3641
return &Config{
3742
RLPGateway: RLPGatewayConfig{
38-
ClientConfig: confighttp.ClientConfig{
39-
Endpoint: defaultURL,
40-
TLSSetting: configtls.ClientConfig{
41-
InsecureSkipVerify: false,
42-
},
43-
},
44-
ShardID: defaultRLPGatewayShardID,
43+
ClientConfig: clientConfig,
44+
ShardID: defaultRLPGatewayShardID,
4545
},
4646
UAA: UAAConfig{
4747
LimitedClientConfig: LimitedClientConfig{

0 commit comments

Comments
 (0)