Skip to content

Commit 028fc46

Browse files
author
alrex
authored
Revert "Make TLSClient config to pointer type (#4104)" (#4196)
This reverts commit ebb0fbd.
1 parent 5570093 commit 028fc46

File tree

9 files changed

+46
-57
lines changed

9 files changed

+46
-57
lines changed

config/configgrpc/configgrpc.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type GRPCClientSettings struct {
7373
Compression string `mapstructure:"compression"`
7474

7575
// TLSSetting struct exposes TLS client configuration.
76-
TLSSetting *configtls.TLSClientSetting `mapstructure:"tls,omitempty"`
76+
TLSSetting configtls.TLSClientSetting `mapstructure:"tls,omitempty"`
7777

7878
// The keepalive parameters for gRPC client. See grpc.WithKeepaliveParams.
7979
// (https://godoc.org/google.golang.org/grpc#WithKeepaliveParams).
@@ -181,28 +181,24 @@ func (gcs *GRPCClientSettings) isSchemeHTTPS() bool {
181181
// ToDialOptions maps configgrpc.GRPCClientSettings to a slice of dial options for gRPC.
182182
func (gcs *GRPCClientSettings) ToDialOptions(host component.Host) ([]grpc.DialOption, error) {
183183
var opts []grpc.DialOption
184-
var tlsCfg *tls.Config
185-
var err error
186184
if gcs.Compression != "" {
187185
if compressionKey := GetGRPCCompressionKey(gcs.Compression); compressionKey != CompressionUnsupported {
188186
opts = append(opts, grpc.WithDefaultCallOptions(grpc.UseCompressor(compressionKey)))
189187
} else {
190188
return nil, fmt.Errorf("unsupported compression type %q", gcs.Compression)
191189
}
192190
}
193-
tlsDialOption := grpc.WithInsecure()
194-
if gcs.TLSSetting != nil {
195-
tlsCfg, err = gcs.TLSSetting.LoadTLSConfig()
196-
if err != nil {
197-
return nil, err
198-
}
191+
192+
tlsCfg, err := gcs.TLSSetting.LoadTLSConfig()
193+
if err != nil {
194+
return nil, err
199195
}
196+
tlsDialOption := grpc.WithInsecure()
200197
if tlsCfg != nil {
201198
tlsDialOption = grpc.WithTransportCredentials(credentials.NewTLS(tlsCfg))
202199
} else if gcs.isSchemeHTTPS() {
203200
tlsDialOption = grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))
204201
}
205-
206202
opts = append(opts, tlsDialOption)
207203

208204
if gcs.ReadBufferSize > 0 {
@@ -239,7 +235,7 @@ func (gcs *GRPCClientSettings) ToDialOptions(host component.Host) ([]grpc.DialOp
239235

240236
perRPCCredentials, perr := grpcAuthenticator.PerRPCCredentials()
241237
if perr != nil {
242-
return nil, perr
238+
return nil, err
243239
}
244240
opts = append(opts, grpc.WithPerRPCCredentials(perRPCCredentials))
245241
}

config/configgrpc/configgrpc_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838

3939
func TestDefaultGrpcClientSettings(t *testing.T) {
4040
gcs := &GRPCClientSettings{
41-
TLSSetting: &configtls.TLSClientSetting{
41+
TLSSetting: configtls.TLSClientSetting{
4242
Insecure: true,
4343
},
4444
}
@@ -54,7 +54,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
5454
},
5555
Endpoint: "localhost:1234",
5656
Compression: "gzip",
57-
TLSSetting: &configtls.TLSClientSetting{
57+
TLSSetting: configtls.TLSClientSetting{
5858
Insecure: false,
5959
},
6060
Keepalive: &KeepaliveClientConfig{
@@ -160,7 +160,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
160160
Headers: nil,
161161
Endpoint: "",
162162
Compression: "",
163-
TLSSetting: &configtls.TLSClientSetting{
163+
TLSSetting: configtls.TLSClientSetting{
164164
TLSSetting: configtls.TLSSetting{
165165
CAFile: "/doesnt/exist",
166166
},
@@ -176,7 +176,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
176176
Headers: nil,
177177
Endpoint: "",
178178
Compression: "",
179-
TLSSetting: &configtls.TLSClientSetting{
179+
TLSSetting: configtls.TLSClientSetting{
180180
TLSSetting: configtls.TLSSetting{
181181
CertFile: "/doesnt/exist",
182182
},
@@ -194,7 +194,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
194194
},
195195
Endpoint: "localhost:1234",
196196
Compression: "gzip",
197-
TLSSetting: &configtls.TLSClientSetting{
197+
TLSSetting: configtls.TLSClientSetting{
198198
Insecure: false,
199199
},
200200
Keepalive: &KeepaliveClientConfig{
@@ -250,7 +250,7 @@ func TestUseSecure(t *testing.T) {
250250
Headers: nil,
251251
Endpoint: "",
252252
Compression: "",
253-
TLSSetting: &configtls.TLSClientSetting{},
253+
TLSSetting: configtls.TLSClientSetting{},
254254
Keepalive: nil,
255255
}
256256
dialOpts, err := gcs.ToDialOptions(componenttest.NewNopHost())
@@ -472,7 +472,7 @@ func TestHttpReception(t *testing.T) {
472472

473473
gcs := &GRPCClientSettings{
474474
Endpoint: ln.Addr().String(),
475-
TLSSetting: tt.tlsClientCreds,
475+
TLSSetting: *tt.tlsClientCreds,
476476
}
477477
clientOpts, errClient := gcs.ToDialOptions(componenttest.NewNopHost())
478478
assert.NoError(t, errClient)
@@ -517,7 +517,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) {
517517

518518
gcs := &GRPCClientSettings{
519519
Endpoint: "unix://" + ln.Addr().String(),
520-
TLSSetting: &configtls.TLSClientSetting{
520+
TLSSetting: configtls.TLSClientSetting{
521521
Insecure: true,
522522
},
523523
}

config/confighttp/confighttp.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type HTTPClientSettings struct {
3838
Endpoint string `mapstructure:"endpoint"`
3939

4040
// TLSSetting struct exposes TLS client configuration.
41-
TLSSetting *configtls.TLSClientSetting `mapstructure:"tls,omitempty"`
41+
TLSSetting configtls.TLSClientSetting `mapstructure:"tls,omitempty"`
4242

4343
// ReadBufferSize for HTTP client. See http.Transport.ReadBufferSize.
4444
ReadBufferSize int `mapstructure:"read_buffer_size"`
@@ -62,19 +62,14 @@ type HTTPClientSettings struct {
6262

6363
// ToClient creates an HTTP client.
6464
func (hcs *HTTPClientSettings) ToClient(ext map[config.ComponentID]component.Extension) (*http.Client, error) {
65-
var err error
65+
tlsCfg, err := hcs.TLSSetting.LoadTLSConfig()
66+
if err != nil {
67+
return nil, err
68+
}
6669
transport := http.DefaultTransport.(*http.Transport).Clone()
67-
68-
if hcs.TLSSetting != nil {
69-
tlsCfg, terr := hcs.TLSSetting.LoadTLSConfig()
70-
if terr != nil {
71-
return nil, terr
72-
}
73-
if tlsCfg != nil {
74-
transport.TLSClientConfig = tlsCfg
75-
}
70+
if tlsCfg != nil {
71+
transport.TLSClientConfig = tlsCfg
7672
}
77-
7873
if hcs.ReadBufferSize > 0 {
7974
transport.ReadBufferSize = hcs.ReadBufferSize
8075
}

config/confighttp/confighttp_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestAllHTTPClientSettings(t *testing.T) {
5757
name: "all_valid_settings",
5858
settings: HTTPClientSettings{
5959
Endpoint: "localhost:1234",
60-
TLSSetting: &configtls.TLSClientSetting{
60+
TLSSetting: configtls.TLSClientSetting{
6161
Insecure: false,
6262
},
6363
ReadBufferSize: 1024,
@@ -70,7 +70,7 @@ func TestAllHTTPClientSettings(t *testing.T) {
7070
name: "error_round_tripper_returned",
7171
settings: HTTPClientSettings{
7272
Endpoint: "localhost:1234",
73-
TLSSetting: &configtls.TLSClientSetting{
73+
TLSSetting: configtls.TLSClientSetting{
7474
Insecure: false,
7575
},
7676
ReadBufferSize: 1024,
@@ -105,7 +105,7 @@ func TestHTTPClientSettingsError(t *testing.T) {
105105
err: "^failed to load TLS config: failed to load CA CertPool: failed to load CA /doesnt/exist:",
106106
settings: HTTPClientSettings{
107107
Endpoint: "",
108-
TLSSetting: &configtls.TLSClientSetting{
108+
TLSSetting: configtls.TLSClientSetting{
109109
TLSSetting: configtls.TLSSetting{
110110
CAFile: "/doesnt/exist",
111111
},
@@ -118,7 +118,7 @@ func TestHTTPClientSettingsError(t *testing.T) {
118118
err: "^failed to load TLS config: for auth via TLS, either both certificate and key must be supplied, or neither",
119119
settings: HTTPClientSettings{
120120
Endpoint: "",
121-
TLSSetting: &configtls.TLSClientSetting{
121+
TLSSetting: configtls.TLSClientSetting{
122122
TLSSetting: configtls.TLSSetting{
123123
CertFile: "/doesnt/exist",
124124
},
@@ -407,7 +407,7 @@ func TestHttpReception(t *testing.T) {
407407

408408
hcs := &HTTPClientSettings{
409409
Endpoint: prefix + ln.Addr().String(),
410-
TLSSetting: tt.tlsClientCreds,
410+
TLSSetting: *tt.tlsClientCreds,
411411
}
412412
client, errClient := hcs.ToClient(map[config.ComponentID]component.Extension{})
413413
assert.NoError(t, errClient)
@@ -582,7 +582,7 @@ func TestHttpHeaders(t *testing.T) {
582582
serverURL, _ := url.Parse(server.URL)
583583
setting := HTTPClientSettings{
584584
Endpoint: serverURL.String(),
585-
TLSSetting: &configtls.TLSClientSetting{},
585+
TLSSetting: configtls.TLSClientSetting{},
586586
ReadBufferSize: 0,
587587
WriteBufferSize: 0,
588588
Timeout: 0,

exporter/otlpexporter/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestLoadConfig(t *testing.T) {
7272
},
7373
Endpoint: "1.2.3.4:1234",
7474
Compression: "on",
75-
TLSSetting: &configtls.TLSClientSetting{
75+
TLSSetting: configtls.TLSClientSetting{
7676
TLSSetting: configtls.TLSSetting{
7777
CAFile: "/var/lib/mycert.pem",
7878
},

exporter/otlpexporter/factory_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestCreateTracesExporter(t *testing.T) {
7878
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
7979
GRPCClientSettings: configgrpc.GRPCClientSettings{
8080
Endpoint: endpoint,
81-
TLSSetting: &configtls.TLSClientSetting{
81+
TLSSetting: configtls.TLSClientSetting{
8282
Insecure: false,
8383
},
8484
},
@@ -147,7 +147,7 @@ func TestCreateTracesExporter(t *testing.T) {
147147
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
148148
GRPCClientSettings: configgrpc.GRPCClientSettings{
149149
Endpoint: endpoint,
150-
TLSSetting: &configtls.TLSClientSetting{
150+
TLSSetting: configtls.TLSClientSetting{
151151
TLSSetting: configtls.TLSSetting{
152152
CAFile: "testdata/test_cert.pem",
153153
},
@@ -161,7 +161,7 @@ func TestCreateTracesExporter(t *testing.T) {
161161
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
162162
GRPCClientSettings: configgrpc.GRPCClientSettings{
163163
Endpoint: endpoint,
164-
TLSSetting: &configtls.TLSClientSetting{
164+
TLSSetting: configtls.TLSClientSetting{
165165
TLSSetting: configtls.TLSSetting{
166166
CAFile: "nosuchfile",
167167
},

exporter/otlpexporter/otlp_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TestSendTraces(t *testing.T) {
195195
cfg := factory.CreateDefaultConfig().(*Config)
196196
cfg.GRPCClientSettings = configgrpc.GRPCClientSettings{
197197
Endpoint: ln.Addr().String(),
198-
TLSSetting: &configtls.TLSClientSetting{
198+
TLSSetting: configtls.TLSClientSetting{
199199
Insecure: true,
200200
},
201201
Headers: map[string]string{
@@ -258,19 +258,17 @@ func TestSendTracesWhenEndpointHasHttpScheme(t *testing.T) {
258258
gRPCClientSettings configgrpc.GRPCClientSettings
259259
}{
260260
{
261-
name: "Use https scheme",
262-
useTLS: true,
263-
scheme: "https://",
264-
gRPCClientSettings: configgrpc.GRPCClientSettings{
265-
TLSSetting: &configtls.TLSClientSetting{},
266-
},
261+
name: "Use https scheme",
262+
useTLS: true,
263+
scheme: "https://",
264+
gRPCClientSettings: configgrpc.GRPCClientSettings{},
267265
},
268266
{
269267
name: "Use http scheme",
270268
useTLS: false,
271269
scheme: "http://",
272270
gRPCClientSettings: configgrpc.GRPCClientSettings{
273-
TLSSetting: &configtls.TLSClientSetting{
271+
TLSSetting: configtls.TLSClientSetting{
274272
Insecure: true,
275273
},
276274
},
@@ -338,7 +336,7 @@ func TestSendMetrics(t *testing.T) {
338336
cfg := factory.CreateDefaultConfig().(*Config)
339337
cfg.GRPCClientSettings = configgrpc.GRPCClientSettings{
340338
Endpoint: ln.Addr().String(),
341-
TLSSetting: &configtls.TLSClientSetting{
339+
TLSSetting: configtls.TLSClientSetting{
342340
Insecure: true,
343341
},
344342
Headers: map[string]string{
@@ -406,7 +404,7 @@ func TestSendTraceDataServerDownAndUp(t *testing.T) {
406404
cfg.QueueSettings.Enabled = false
407405
cfg.GRPCClientSettings = configgrpc.GRPCClientSettings{
408406
Endpoint: ln.Addr().String(),
409-
TLSSetting: &configtls.TLSClientSetting{
407+
TLSSetting: configtls.TLSClientSetting{
410408
Insecure: true,
411409
},
412410
// Need to wait for every request blocking until either request timeouts or succeed.
@@ -466,7 +464,7 @@ func TestSendTraceDataServerStartWhileRequest(t *testing.T) {
466464
cfg := factory.CreateDefaultConfig().(*Config)
467465
cfg.GRPCClientSettings = configgrpc.GRPCClientSettings{
468466
Endpoint: ln.Addr().String(),
469-
TLSSetting: &configtls.TLSClientSetting{
467+
TLSSetting: configtls.TLSClientSetting{
470468
Insecure: true,
471469
},
472470
}
@@ -542,7 +540,7 @@ func TestSendLogData(t *testing.T) {
542540
cfg := factory.CreateDefaultConfig().(*Config)
543541
cfg.GRPCClientSettings = configgrpc.GRPCClientSettings{
544542
Endpoint: ln.Addr().String(),
545-
TLSSetting: &configtls.TLSClientSetting{
543+
TLSSetting: configtls.TLSClientSetting{
546544
Insecure: true,
547545
},
548546
}

exporter/otlphttpexporter/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestLoadConfig(t *testing.T) {
6666
"another": "somevalue",
6767
},
6868
Endpoint: "https://1.2.3.4:1234",
69-
TLSSetting: &configtls.TLSClientSetting{
69+
TLSSetting: configtls.TLSClientSetting{
7070
TLSSetting: configtls.TLSSetting{
7171
CAFile: "/var/lib/mycert.pem",
7272
CertFile: "certfile",

exporter/otlphttpexporter/factory_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestCreateTracesExporter(t *testing.T) {
8282
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
8383
HTTPClientSettings: confighttp.HTTPClientSettings{
8484
Endpoint: endpoint,
85-
TLSSetting: &configtls.TLSClientSetting{
85+
TLSSetting: configtls.TLSClientSetting{
8686
Insecure: false,
8787
},
8888
},
@@ -107,7 +107,7 @@ func TestCreateTracesExporter(t *testing.T) {
107107
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
108108
HTTPClientSettings: confighttp.HTTPClientSettings{
109109
Endpoint: endpoint,
110-
TLSSetting: &configtls.TLSClientSetting{
110+
TLSSetting: configtls.TLSClientSetting{
111111
TLSSetting: configtls.TLSSetting{
112112
CAFile: "testdata/test_cert.pem",
113113
},
@@ -121,7 +121,7 @@ func TestCreateTracesExporter(t *testing.T) {
121121
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
122122
HTTPClientSettings: confighttp.HTTPClientSettings{
123123
Endpoint: endpoint,
124-
TLSSetting: &configtls.TLSClientSetting{
124+
TLSSetting: configtls.TLSClientSetting{
125125
TLSSetting: configtls.TLSSetting{
126126
CAFile: "nosuchfile",
127127
},

0 commit comments

Comments
 (0)