From 97ee54cbaacd21b813f432fc28234fe60b3a3dd1 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Mon, 8 Apr 2024 14:41:40 -0700 Subject: [PATCH 1/5] [config/configtls] Enable goleak check This change enables goleak to check the config/configtls package for memory and goroutine leaks. There was originally a goroutine leak which is fixed by calling the newly added method TLSServerSetting.Shutdown. Make reloader member private Add changelog Add changelog Call shutdown Implement shutdown callback Remove unnecessary Shutdown method Use defer instead of list of shutdown calls Update changelog Move logic to shutdown call Add missing shutdown, fix import ordering Fix references Changes requested by Tyler - Make all functions same receiver type - Call all shutdown functions Use error.join instead of multierr Fix errors.join usage --- .chloggen/goleak_configtls.yaml | 25 ++++ config/configtls/clientcasfilereloader.go | 2 +- .../configtls/clientcasfilereloader_test.go | 4 +- config/configtls/configtls.go | 23 +++- config/configtls/configtls_test.go | 33 +++++ config/configtls/go.mod | 1 + config/configtls/package_test.go | 17 +++ receiver/otlpreceiver/go.mod | 2 +- receiver/otlpreceiver/otlp.go | 13 +- receiver/otlpreceiver/otlp_test.go | 115 ++++++++++++++++++ receiver/otlpreceiver/testdata/ca.crt | 20 +++ receiver/otlpreceiver/testdata/server.crt | 20 +++ receiver/otlpreceiver/testdata/server.key | 27 ++++ 13 files changed, 293 insertions(+), 9 deletions(-) create mode 100755 .chloggen/goleak_configtls.yaml create mode 100644 config/configtls/package_test.go create mode 100644 receiver/otlpreceiver/testdata/ca.crt create mode 100644 receiver/otlpreceiver/testdata/server.crt create mode 100644 receiver/otlpreceiver/testdata/server.key diff --git a/.chloggen/goleak_configtls.yaml b/.chloggen/goleak_configtls.yaml new file mode 100755 index 00000000000..93aa95a4ce3 --- /dev/null +++ b/.chloggen/goleak_configtls.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: config/configtls + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add shutdown method to TLS ServerConfig to fix memory leaks + +# One or more tracking issues or pull requests related to the change +issues: [9165] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] \ No newline at end of file diff --git a/config/configtls/clientcasfilereloader.go b/config/configtls/clientcasfilereloader.go index 1ee9c72ef9f..cd728941a12 100644 --- a/config/configtls/clientcasfilereloader.go +++ b/config/configtls/clientcasfilereloader.go @@ -132,7 +132,7 @@ func (r *clientCAsFileReloader) handleWatcherEvents() { func (r *clientCAsFileReloader) shutdown() error { if r.shutdownCH == nil { - return fmt.Errorf("client CAs file watcher is not running") + return nil } r.shutdownCH <- true close(r.shutdownCH) diff --git a/config/configtls/clientcasfilereloader_test.go b/config/configtls/clientcasfilereloader_test.go index 925c77e1ad5..3bc786c2f78 100644 --- a/config/configtls/clientcasfilereloader_test.go +++ b/config/configtls/clientcasfilereloader_test.go @@ -15,10 +15,10 @@ import ( "github.com/stretchr/testify/assert" ) -func TestCannotShutdownIfNotWatching(t *testing.T) { +func TestCanShutdownIfNotWatching(t *testing.T) { reloader, _, _ := createReloader(t) err := reloader.shutdown() - assert.Error(t, err) + assert.NoError(t, err) } func TestCannotStartIfAlreadyWatching(t *testing.T) { diff --git a/config/configtls/configtls.go b/config/configtls/configtls.go index 2090f775d49..c6ca7120bf6 100644 --- a/config/configtls/configtls.go +++ b/config/configtls/configtls.go @@ -125,6 +125,9 @@ type ServerConfig struct { // Reload the ClientCAs file when it is modified // (optional, default false) ReloadClientCAFile bool `mapstructure:"client_ca_file_reload"` + + // Shutdown functions used to shutdown the file reloader for the Client CA. + reloaderShutdownFuncs []func() error } // NewDefaultServerConfig creates a new TLSServerSetting with any default values set. @@ -401,18 +404,18 @@ func (c ClientConfig) LoadTLSConfig(_ context.Context) (*tls.Config, error) { // LoadTLSConfigContext loads the TLS configuration. // // Deprecated: [v0.99.0] Use LoadTLSConfig instead. -func (c ServerConfig) LoadTLSConfigContext(ctx context.Context) (*tls.Config, error) { +func (c *ServerConfig) LoadTLSConfigContext(ctx context.Context) (*tls.Config, error) { return c.LoadTLSConfig(ctx) } // LoadTLSConfig loads the TLS configuration. -func (c ServerConfig) LoadTLSConfig(_ context.Context) (*tls.Config, error) { +func (c *ServerConfig) LoadTLSConfig(_ context.Context) (*tls.Config, error) { tlsCfg, err := c.loadTLSConfig() if err != nil { return nil, fmt.Errorf("failed to load TLS config: %w", err) } if c.ClientCAFile != "" { - reloader, err := newClientCAsReloader(c.ClientCAFile, &c) + reloader, err := newClientCAsReloader(c.ClientCAFile, c) if err != nil { return nil, err } @@ -422,17 +425,29 @@ func (c ServerConfig) LoadTLSConfig(_ context.Context) (*tls.Config, error) { return nil, err } tlsCfg.GetConfigForClient = func(*tls.ClientHelloInfo) (*tls.Config, error) { return reloader.getClientConfig(tlsCfg) } + c.reloaderShutdownFuncs = append(c.reloaderShutdownFuncs, reloader.shutdown) } tlsCfg.ClientCAs = reloader.certPool tlsCfg.ClientAuth = tls.RequireAndVerifyClientCert } + return tlsCfg, nil } -func (c ServerConfig) loadClientCAFile() (*x509.CertPool, error) { +func (c *ServerConfig) loadClientCAFile() (*x509.CertPool, error) { return c.loadCert(c.ClientCAFile) } +func (c *ServerConfig) Shutdown() error { + var errs []error + + for _, shutdown := range c.reloaderShutdownFuncs { + errs = append(errs, shutdown()) + } + + return errors.Join(errs...) +} + func (c Config) hasCA() bool { return c.hasCAFile() || c.hasCAPem() } func (c Config) hasCert() bool { return c.hasCertFile() || c.hasCertPem() } func (c Config) hasKey() bool { return c.hasKeyFile() || c.hasKeyPem() } diff --git a/config/configtls/configtls_test.go b/config/configtls/configtls_test.go index 91c0e871055..38de95d3564 100644 --- a/config/configtls/configtls_test.go +++ b/config/configtls/configtls_test.go @@ -310,12 +310,14 @@ func TestLoadTLSServerConfigError(t *testing.T) { KeyFile: "doesnt/exist", }, } + _, err := tlsSetting.LoadTLSConfig(context.Background()) assert.Error(t, err) tlsSetting = ServerConfig{ ClientCAFile: "doesnt/exist", } + _, err = tlsSetting.LoadTLSConfig(context.Background()) assert.Error(t, err) } @@ -325,6 +327,9 @@ func TestLoadTLSServerConfig(t *testing.T) { tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background()) assert.NoError(t, err) assert.NotNil(t, tlsCfg) + defer func() { + assert.NoError(t, tlsSetting.Shutdown()) + }() } func TestLoadTLSServerConfigReload(t *testing.T) { @@ -341,6 +346,9 @@ func TestLoadTLSServerConfigReload(t *testing.T) { tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background()) assert.NoError(t, err) assert.NotNil(t, tlsCfg) + defer func() { + assert.NoError(t, tlsSetting.Shutdown()) + }() firstClient, err := tlsCfg.GetConfigForClient(nil) assert.NoError(t, err) @@ -358,6 +366,25 @@ func TestLoadTLSServerConfigReload(t *testing.T) { assert.NotEqual(t, firstClient.ClientCAs, secondClient.ClientCAs) } +func TestLoadTLSServerMultipleConfigs(t *testing.T) { + tmpCaPath := createTempClientCaFile(t) + + overwriteClientCA(t, tmpCaPath, "ca-1.crt") + + tlsSetting := ServerConfig{ + ClientCAFile: tmpCaPath, + ReloadClientCAFile: true, + } + + for i := 0; i < 10; i++ { + tlsCfg, err := tlsSetting.LoadTLSConfigContext(context.Background()) + assert.NoError(t, err) + assert.NotNil(t, tlsCfg) + } + + assert.NoError(t, tlsSetting.Shutdown()) +} + func TestLoadTLSServerConfigFailingReload(t *testing.T) { tmpCaPath := createTempClientCaFile(t) @@ -372,6 +399,9 @@ func TestLoadTLSServerConfigFailingReload(t *testing.T) { tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background()) assert.NoError(t, err) assert.NotNil(t, tlsCfg) + defer func() { + assert.NoError(t, tlsSetting.Shutdown()) + }() firstClient, err := tlsCfg.GetConfigForClient(nil) assert.NoError(t, err) @@ -433,6 +463,9 @@ func TestLoadTLSServerConfigFailing(t *testing.T) { tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background()) assert.NoError(t, err) assert.NotNil(t, tlsCfg) + defer func() { + assert.NoError(t, tlsSetting.Shutdown()) + }() firstClient, err := tlsCfg.GetConfigForClient(nil) assert.NoError(t, err) diff --git a/config/configtls/go.mod b/config/configtls/go.mod index 13163ae4005..6ab0282a744 100644 --- a/config/configtls/go.mod +++ b/config/configtls/go.mod @@ -6,6 +6,7 @@ require ( github.com/fsnotify/fsnotify v1.7.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/config/configopaque v1.5.0 + go.uber.org/goleak v1.3.0 ) require ( diff --git a/config/configtls/package_test.go b/config/configtls/package_test.go new file mode 100644 index 00000000000..012b9059c0f --- /dev/null +++ b/config/configtls/package_test.go @@ -0,0 +1,17 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package configtls + +import ( + "testing" + + "go.uber.org/goleak" +) + +// The IgnoreTopFunction call prevents catching the leak generated by opencensus +// defaultWorker.Start which at this time is part of the package's init call. +// See https://github.com/open-telemetry/opentelemetry-collector/issues/9165#issuecomment-1874836336 for more context. +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start")) +} diff --git a/receiver/otlpreceiver/go.mod b/receiver/otlpreceiver/go.mod index 13347010fa0..3eba2155b7a 100644 --- a/receiver/otlpreceiver/go.mod +++ b/receiver/otlpreceiver/go.mod @@ -20,6 +20,7 @@ require ( go.opentelemetry.io/otel/metric v1.25.0 go.opentelemetry.io/otel/trace v1.25.0 go.uber.org/goleak v1.3.0 + go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda google.golang.org/grpc v1.63.2 @@ -75,7 +76,6 @@ require ( go.opentelemetry.io/otel/sdk v1.25.0 // indirect go.opentelemetry.io/otel/sdk/metric v1.25.0 // indirect go.opentelemetry.io/proto/otlp v1.1.0 // indirect - go.uber.org/multierr v1.11.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index 43eed9b821a..14733d49559 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -10,6 +10,7 @@ import ( "net/http" "sync" + "go.uber.org/multierr" "go.uber.org/zap" "google.golang.org/grpc" @@ -186,8 +187,18 @@ func (r *otlpReceiver) Start(ctx context.Context, host component.Host) error { func (r *otlpReceiver) Shutdown(ctx context.Context) error { var err error + if r.cfg != nil { + if r.cfg.HTTP != nil && r.cfg.HTTP.TLSSetting != nil { + err = r.cfg.HTTP.TLSSetting.Shutdown() + } + + if r.cfg.GRPC != nil && r.cfg.GRPC.TLSSetting != nil { + err = multierr.Append(err, r.cfg.GRPC.TLSSetting.Shutdown()) + } + } + if r.serverHTTP != nil { - err = r.serverHTTP.Shutdown(ctx) + err = multierr.Append(err, r.serverHTTP.Shutdown(ctx)) } if r.serverGRPC != nil { diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index f15e1cc6db3..3e833982723 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -13,6 +13,7 @@ import ( "io" "net" "net/http" + "path/filepath" "strings" "sync" "testing" @@ -712,6 +713,62 @@ func TestGRPCInvalidTLSCredentials(t *testing.T) { `failed to load TLS config: failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither`) } +func TestGRPCValidTLSCredentials(t *testing.T) { + + tests := []struct { + name string + config *configtls.ServerConfig + }{ + { + name: "Base case", + config: &configtls.ServerConfig{ + TLSSetting: configtls.Config{ + CAFile: filepath.Join("testdata", "ca.crt"), + CertFile: filepath.Join("testdata", "server.crt"), + KeyFile: filepath.Join("testdata", "server.key"), + }, + }, + }, + { + name: "Test reload enabled", + config: &configtls.ServerConfig{ + TLSSetting: configtls.Config{ + CAFile: filepath.Join("testdata", "ca.crt"), + CertFile: filepath.Join("testdata", "server.crt"), + KeyFile: filepath.Join("testdata", "server.key"), + }, + ReloadClientCAFile: true, + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + cfg := &Config{ + Protocols: Protocols{ + GRPC: &configgrpc.ServerConfig{ + NetAddr: confignet.AddrConfig{ + Endpoint: testutil.GetAvailableLocalAddress(t), + Transport: "tcp", + }, + TLSSetting: test.config, + }, + }, + } + + r, err := NewFactory().CreateTracesReceiver( + context.Background(), + receivertest.NewNopCreateSettings(), + cfg, + consumertest.NewNop()) + require.NoError(t, err) + assert.NotNil(t, r) + assert.NoError(t, r.Start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, r.Shutdown(context.Background())) + }) + } +} + func TestGRPCMaxRecvSize(t *testing.T) { addr := testutil.GetAvailableLocalAddress(t) sink := newErrOrSinkConsumer() @@ -778,6 +835,64 @@ func TestHTTPInvalidTLSCredentials(t *testing.T) { `failed to load TLS config: failed to load TLS cert and key: for auth via TLS, provide both certificate and key, or neither`) } +func TestHTTPTLSCredentials(t *testing.T) { + // Add test cases like GRPC test + tests := []struct { + name string + config *configtls.ServerConfig + }{ + { + name: "Base case", + config: &configtls.ServerConfig{ + TLSSetting: configtls.Config{ + CAFile: filepath.Join("testdata", "ca.crt"), + CertFile: filepath.Join("testdata", "server.crt"), + KeyFile: filepath.Join("testdata", "server.key"), + }, + }, + }, + { + name: "Test reload enabled", + config: &configtls.ServerConfig{ + TLSSetting: configtls.Config{ + CAFile: filepath.Join("testdata", "ca.crt"), + CertFile: filepath.Join("testdata", "server.crt"), + KeyFile: filepath.Join("testdata", "server.key"), + }, + ReloadClientCAFile: true, + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + cfg := &Config{ + Protocols: Protocols{ + HTTP: &HTTPConfig{ + ServerConfig: &confighttp.ServerConfig{ + Endpoint: testutil.GetAvailableLocalAddress(t), + TLSSetting: test.config, + }, + TracesURLPath: defaultTracesURLPath, + MetricsURLPath: defaultMetricsURLPath, + LogsURLPath: defaultLogsURLPath, + }, + }, + } + + r, err := NewFactory().CreateTracesReceiver( + context.Background(), + receivertest.NewNopCreateSettings(), + cfg, + consumertest.NewNop()) + require.NoError(t, err) + assert.NotNil(t, r) + assert.NoError(t, r.Start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, r.Shutdown(context.Background())) + }) + } +} + func testHTTPMaxRequestBodySize(t *testing.T, path string, contentType string, payload []byte, size int, expectedStatusCode int) { addr := testutil.GetAvailableLocalAddress(t) url := "http://" + addr + path diff --git a/receiver/otlpreceiver/testdata/ca.crt b/receiver/otlpreceiver/testdata/ca.crt new file mode 100644 index 00000000000..e850c66f4f7 --- /dev/null +++ b/receiver/otlpreceiver/testdata/ca.crt @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDNjCCAh4CCQCBqDI24JacNTANBgkqhkiG9w0BAQsFADBdMQswCQYDVQQGEwJB +VTESMBAGA1UECAwJQXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoM +CU15T3JnTmFtZTEVMBMGA1UEAwwMTXlDb21tb25OYW1lMB4XDTIyMDgwMzA0MTAx +N1oXDTMyMDczMTA0MTAxN1owXTELMAkGA1UEBhMCQVUxEjAQBgNVBAgMCUF1c3Ry +YWxpYTEPMA0GA1UEBwwGU3lkbmV5MRIwEAYDVQQKDAlNeU9yZ05hbWUxFTATBgNV +BAMMDE15Q29tbW9uTmFtZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +ANFDGZCSxNdaJQ1q7P5qVAZDKCj+3ClpFWAVT5HYDlOqgIjYRZ45/YGfKsDbK6rj +/+v5xTnTZt8e8kRfPgrZTBtPtefu6tKwxYYr3sSCR3TU4bX4dIM9ZwrFaTrPP1hk +UXR8zlk7F6gcWS+WX7LdupMs5SdZIePhkzpkxYIBatdRMf7w2f5v6M3UnOrCoyz0 +YPvvyZKq5zo9uBlVkrUL/QDrOB5yYjith7l8FkLHAirGTaszfF+8pZwzZn4ykVbn +eQQs1g6ujR0DgQh/k6A6XDQfg4JWQqNt3kkiO7NPIHTrl+W/nKdqve864ECAHSM2 +NIgGtQqVavPKD6pr15V328cCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEALZuCeu8U +yjJlR+BbDqiZw7/EBpGgTX4mv9CofJc9ErxFGJTYiaLZ1Jf3bwE+0G9ym8UfxKG8 +9xCYmoVbEQhgLzYDpYPxkKi5X7RUMw9fKlbRqwy2Ek1mDnSIYPRalhfOXBT5E652 +OUeILLRJlAPL3SrALjJM5Jjn4pkwankE53mfU4LpC7xWOjuwkSPRor1XCwoAZMTz +EZsZGUQf5M69ZAy0wWHu4C94rlgD37hybUEzhsr9UiK2v1Gn3a7BSAgtkbD0OIe5 +BzCu+UHQO4u841SbXn4q8aO1idaR8UhPAqfVno+L7ZmHRGsgvMk1vlMbroIIYaAz +2LQP6IwYUWRM9Q== +-----END CERTIFICATE----- diff --git a/receiver/otlpreceiver/testdata/server.crt b/receiver/otlpreceiver/testdata/server.crt new file mode 100644 index 00000000000..cc48c740762 --- /dev/null +++ b/receiver/otlpreceiver/testdata/server.crt @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDVTCCAj2gAwIBAgIJANt5fkUlfxyNMA0GCSqGSIb3DQEBCwUAMF0xCzAJBgNV +BAYTAkFVMRIwEAYDVQQIDAlBdXN0cmFsaWExDzANBgNVBAcMBlN5ZG5leTESMBAG +A1UECgwJTXlPcmdOYW1lMRUwEwYDVQQDDAxNeUNvbW1vbk5hbWUwHhcNMjIwODAz +MDQxMDE3WhcNMzIwNzMxMDQxMDE3WjBdMQswCQYDVQQGEwJBVTESMBAGA1UECAwJ +QXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoMCU15T3JnTmFtZTEV +MBMGA1UEAwwMTXlDb21tb25OYW1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB +CgKCAQEAupEXxNIX+2k0PC/yLfuWSbFr22eLwYSYkPDydFENKYID905hcWqaqr4o +u1Fu8nofbeKrpTgmx7lwXB5VIkdNcnwLyt40nPETGN2m0vBa7Bm6z/KJTW0iHmTz +5fVzt9rggnRTRSovNy43weKoZXHcl/lmGbGy+lqQ69jJTT9yXipkMTIkscYgSHK3 +GVxUhrsBc/mZyBLSj3Tpt3Az71N4npTp6XYbgx4MhllbH9xFlw2hLs1DU+vwJhSE +w99UrLhRz8L3ePmShdkySD9QZxCKD5euiumVfPLfzWV2JmLejC3MD3sd5ql+5itv +WrnYPcky3OclXcnZgDo+ZloWLYPWhQIDAQABoxgwFjAUBgNVHREEDTALgglsb2Nh +bGhvc3QwDQYJKoZIhvcNAQELBQADggEBAJGfixdI6T6dxb37fJPNa0Uerq5aZPb9 +GLJg3CqkZ4yjfsveZ91lH7fRPRjXld3aMb6978kpoczGYJeAdY8j0BPvA+UfsuYO +bzm6HUgiTjyCnLPQIuAlzuYDsBQhzz6gdRclgnuQ8JO/xTDIxVLJDuueannqEn9x +s/RQ5PeWf0D+zvSu4p8UENKfaPqoI5q7nb93IHL38PMDfB7n4oEDIkG0zfxX/zYI +h5ZhzlWSscfCRE4Hdcb8RcSuzwI2JzidMY/ZXUr20iNuCSbv4zhsoDASk7Ud+yj4 +d4JkdOA4NbaT8/aR+Ectc2ItBc2lb0xzEqQnjg3zRQjEzeryHN0hxWU= +-----END CERTIFICATE----- diff --git a/receiver/otlpreceiver/testdata/server.key b/receiver/otlpreceiver/testdata/server.key new file mode 100644 index 00000000000..16818a16599 --- /dev/null +++ b/receiver/otlpreceiver/testdata/server.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEAupEXxNIX+2k0PC/yLfuWSbFr22eLwYSYkPDydFENKYID905h +cWqaqr4ou1Fu8nofbeKrpTgmx7lwXB5VIkdNcnwLyt40nPETGN2m0vBa7Bm6z/KJ +TW0iHmTz5fVzt9rggnRTRSovNy43weKoZXHcl/lmGbGy+lqQ69jJTT9yXipkMTIk +scYgSHK3GVxUhrsBc/mZyBLSj3Tpt3Az71N4npTp6XYbgx4MhllbH9xFlw2hLs1D +U+vwJhSEw99UrLhRz8L3ePmShdkySD9QZxCKD5euiumVfPLfzWV2JmLejC3MD3sd +5ql+5itvWrnYPcky3OclXcnZgDo+ZloWLYPWhQIDAQABAoIBAF8u/01vUsT126yJ +WamUHgzi9AAwR+EnYR8xjsFBSNHQf22BE73lgZtzARzwYwZawAY0CxZ0G3TyaxzU +bOLcNese1nVeAMHBTNj23NHpxrmGNwU43EwgTbPsFXNRUwSOKtTjvEghSY2Bivjk +Rr3a5YyztR+OxZ1s71skcy9yG0tmveGRQS2Gn3SrLgrX7PjgUULpd7TNkWlAyTB7 +sFvVeHVEv8AcFDvHCBvlNJvMG2WT7kD4vjbRc0V1y89D4wO3kNVumajNjiSUopsU +zFe1vegcSLIgf1i2QEtXLob6mrQJplDA3G8oQX4FF0Oovk/bLwzC6IHNeFOo5eFM +TfGzd9ECgYEA6Ixx+2Bai2zdSz19NVaQEksDVdT/ivorgYGpIllLOwjU3ZCIEs2J +iNNPlIX9uFcwIGcfoHsU66iUWrwprfnbloezq5aPdHuhW2PE+JUEBqzmQDy+ax/i +HI2IaD42+OJY5RdRfS7cvczIFrW9XECCTkhr08CxZTO7W7VCP0OnpPMCgYEAzWGQ +hHgpyj5kfco/KlRrK6bQBkhbqWkbkoZohVL6hJ2UxC/NBFS3fWYQ2LFyFPBdu+lI +RXkDxroCQJfWGNAe4PlbKcWh5Q9Ps/s8wl0DIR/KM2yhzE2GqfDC6pQ3xFpizbcm +jl+AL2U6Y9Et1nvPjZKo6STf5yrEdIuHgaq61KcCgYEA4g/tmf2/53vr4AGlXx2I +LpBHbMADrzmk41+FaMO/M2NRcxXWgdjW03EAEpTy4am4Ojelch9UZgZaOZ5jMiIL +Slke2zYgvI6WfD4Ps8tAv7CCoH2sanzzFOitaxDX5bg7zHCPog7VPZj+Bb2kmDKJ +ucoDMDVI/eV9RBh/jvqY1OsCgYEAx5iYxVSucGFgcis6Zd3y5VJRermZczO12xmK +vH9e/cDTUjKOUTYvuMuXdbBFiXnr7nIRjYrFE72z8KhfJnAkgklzwk3SP3U45VY1 +v0J7hxaJAJ8DQzTYuZFFLIptBAM/YGMtMlI3llgPffBNVtOuawzr4OC4RMV4dTcg +svCEb6MCgYEAnRx87p5bAgDVug3pdFI7qRi5Tgxa25c5GsFwhmmr3EgtxKQKLFIH +G6KOWJBpFePVrz3PH71d+J1mB/g8GqzpHBuYTBDD3hyz8iKHN+pmoM4m2/tTqKRY +26XUGOUIxnksgsw2O2R9AASrEm4hhAg5AxmANgqOIZijIcHWF8q9QpE= +-----END RSA PRIVATE KEY----- From 729b56553bed5162d6a31c39ffa35d30a2c5cca2 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Tue, 9 Apr 2024 08:44:28 -0700 Subject: [PATCH 2/5] Update struct member name --- receiver/otlpreceiver/otlp_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 3e833982723..61acac0492a 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -722,7 +722,7 @@ func TestGRPCValidTLSCredentials(t *testing.T) { { name: "Base case", config: &configtls.ServerConfig{ - TLSSetting: configtls.Config{ + Config: configtls.Config{ CAFile: filepath.Join("testdata", "ca.crt"), CertFile: filepath.Join("testdata", "server.crt"), KeyFile: filepath.Join("testdata", "server.key"), @@ -732,7 +732,7 @@ func TestGRPCValidTLSCredentials(t *testing.T) { { name: "Test reload enabled", config: &configtls.ServerConfig{ - TLSSetting: configtls.Config{ + Config: configtls.Config{ CAFile: filepath.Join("testdata", "ca.crt"), CertFile: filepath.Join("testdata", "server.crt"), KeyFile: filepath.Join("testdata", "server.key"), @@ -844,7 +844,7 @@ func TestHTTPTLSCredentials(t *testing.T) { { name: "Base case", config: &configtls.ServerConfig{ - TLSSetting: configtls.Config{ + Config: configtls.Config{ CAFile: filepath.Join("testdata", "ca.crt"), CertFile: filepath.Join("testdata", "server.crt"), KeyFile: filepath.Join("testdata", "server.key"), @@ -854,7 +854,7 @@ func TestHTTPTLSCredentials(t *testing.T) { { name: "Test reload enabled", config: &configtls.ServerConfig{ - TLSSetting: configtls.Config{ + Config: configtls.Config{ CAFile: filepath.Join("testdata", "ca.crt"), CertFile: filepath.Join("testdata", "server.crt"), KeyFile: filepath.Join("testdata", "server.key"), From d3e927393e31090139704509a18cf752be7c6c53 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Wed, 17 Apr 2024 14:37:59 -0700 Subject: [PATCH 3/5] Use errors.Join instead of multierr --- receiver/otlpreceiver/go.mod | 2 +- receiver/otlpreceiver/otlp.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/receiver/otlpreceiver/go.mod b/receiver/otlpreceiver/go.mod index 3eba2155b7a..13347010fa0 100644 --- a/receiver/otlpreceiver/go.mod +++ b/receiver/otlpreceiver/go.mod @@ -20,7 +20,6 @@ require ( go.opentelemetry.io/otel/metric v1.25.0 go.opentelemetry.io/otel/trace v1.25.0 go.uber.org/goleak v1.3.0 - go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda google.golang.org/grpc v1.63.2 @@ -76,6 +75,7 @@ require ( go.opentelemetry.io/otel/sdk v1.25.0 // indirect go.opentelemetry.io/otel/sdk/metric v1.25.0 // indirect go.opentelemetry.io/proto/otlp v1.1.0 // indirect + go.uber.org/multierr v1.11.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/receiver/otlpreceiver/otlp.go b/receiver/otlpreceiver/otlp.go index 14733d49559..8da0ae69c25 100644 --- a/receiver/otlpreceiver/otlp.go +++ b/receiver/otlpreceiver/otlp.go @@ -10,7 +10,6 @@ import ( "net/http" "sync" - "go.uber.org/multierr" "go.uber.org/zap" "google.golang.org/grpc" @@ -185,20 +184,20 @@ func (r *otlpReceiver) Start(ctx context.Context, host component.Host) error { // Shutdown is a method to turn off receiving. func (r *otlpReceiver) Shutdown(ctx context.Context) error { - var err error + var errs []error if r.cfg != nil { if r.cfg.HTTP != nil && r.cfg.HTTP.TLSSetting != nil { - err = r.cfg.HTTP.TLSSetting.Shutdown() + errs = append(errs, r.cfg.HTTP.TLSSetting.Shutdown()) } if r.cfg.GRPC != nil && r.cfg.GRPC.TLSSetting != nil { - err = multierr.Append(err, r.cfg.GRPC.TLSSetting.Shutdown()) + errs = append(errs, r.cfg.GRPC.TLSSetting.Shutdown()) } } if r.serverHTTP != nil { - err = multierr.Append(err, r.serverHTTP.Shutdown(ctx)) + errs = append(errs, r.serverHTTP.Shutdown(ctx)) } if r.serverGRPC != nil { @@ -206,7 +205,7 @@ func (r *otlpReceiver) Shutdown(ctx context.Context) error { } r.shutdownWG.Wait() - return err + return errors.Join(errs...) } func (r *otlpReceiver) registerTraceConsumer(tc consumer.Traces) { From 74661882d9fd0dd29e8f7a2df17ab46dc2c0a4e4 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Thu, 6 Jun 2024 09:09:06 -0700 Subject: [PATCH 4/5] Remove reference to deleted method --- config/configtls/configtls_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/configtls/configtls_test.go b/config/configtls/configtls_test.go index 38de95d3564..6da03a79aa6 100644 --- a/config/configtls/configtls_test.go +++ b/config/configtls/configtls_test.go @@ -377,7 +377,7 @@ func TestLoadTLSServerMultipleConfigs(t *testing.T) { } for i := 0; i < 10; i++ { - tlsCfg, err := tlsSetting.LoadTLSConfigContext(context.Background()) + tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background()) assert.NoError(t, err) assert.NotNil(t, tlsCfg) } From f24d5491f12159facbf5354a0860b63915fd474c Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Fri, 7 Jun 2024 14:59:16 -0700 Subject: [PATCH 5/5] Remove deprecated method --- receiver/otlpreceiver/otlp_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/receiver/otlpreceiver/otlp_test.go b/receiver/otlpreceiver/otlp_test.go index 906617bfc9c..14004316052 100644 --- a/receiver/otlpreceiver/otlp_test.go +++ b/receiver/otlpreceiver/otlp_test.go @@ -758,7 +758,7 @@ func TestGRPCValidTLSCredentials(t *testing.T) { r, err := NewFactory().CreateTracesReceiver( context.Background(), - receivertest.NewNopCreateSettings(), + receivertest.NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err) @@ -883,7 +883,7 @@ func TestHTTPTLSCredentials(t *testing.T) { r, err := NewFactory().CreateTracesReceiver( context.Background(), - receivertest.NewNopCreateSettings(), + receivertest.NewNopSettings(), cfg, consumertest.NewNop()) require.NoError(t, err)