From 302178aae3f80c6994ec17e37809ceae23b2ab20 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Fri, 9 Feb 2024 02:59:36 -0800 Subject: [PATCH] [chore][exporter/coralogixexporter] Enable goleak check (#30803) **Description:** This enables the `goleak` check on all tests in this package, to ensure the exporter isn't leaking goroutines. The only updates here are tests, as some were missing necessary `shutdown` calls. I also updated some variable naming to match types, such as `le` for a logs exporter instead of `me`. **Link to tracking Issue:** #30438 **Testing:** All tests are passing, including added `goleak` check. --------- Co-authored-by: Alex Boten --- exporter/coralogixexporter/config_test.go | 15 ++++++++++++--- exporter/coralogixexporter/factory_test.go | 2 ++ exporter/coralogixexporter/go.mod | 1 + exporter/coralogixexporter/go.sum | 1 + exporter/coralogixexporter/package_test.go | 14 ++++++++++++++ 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 exporter/coralogixexporter/package_test.go diff --git a/exporter/coralogixexporter/config_test.go b/exporter/coralogixexporter/config_test.go index 997a48ad7ea6..e3ccf3a154c5 100644 --- a/exporter/coralogixexporter/config_test.go +++ b/exporter/coralogixexporter/config_test.go @@ -179,6 +179,7 @@ func TestTraceExporter(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, te, "failed to create trace exporter") assert.NoError(t, te.start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, te.shutdown(context.Background())) } func TestMetricsExporter(t *testing.T) { @@ -198,6 +199,7 @@ func TestMetricsExporter(t *testing.T) { require.NoError(t, err) require.NotNil(t, me, "failed to create metrics exporter") require.NoError(t, me.start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, me.shutdown(context.Background())) } func TestLogsExporter(t *testing.T) { @@ -213,10 +215,11 @@ func TestLogsExporter(t *testing.T) { params := exportertest.NewNopCreateSettings() - me, err := newLogsExporter(cfg, params) + le, err := newLogsExporter(cfg, params) require.NoError(t, err) - require.NotNil(t, me, "failed to create logs exporter") - require.NoError(t, me.start(context.Background(), componenttest.NewNopHost())) + require.NotNil(t, le, "failed to create logs exporter") + require.NoError(t, le.start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, le.shutdown(context.Background())) } func TestDomainWithAllExporters(t *testing.T) { @@ -234,16 +237,19 @@ func TestDomainWithAllExporters(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, te, "failed to create trace exporter") assert.NoError(t, te.start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, te.shutdown(context.Background())) me, err := newMetricsExporter(cfg, params) require.NoError(t, err) require.NotNil(t, me, "failed to create metrics exporter") require.NoError(t, me.start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, me.shutdown(context.Background())) le, err := newLogsExporter(cfg, params) require.NoError(t, err) require.NotNil(t, le, "failed to create logs exporter") require.NoError(t, le.start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, le.shutdown(context.Background())) } func TestEndpoindsAndDomainWithAllExporters(t *testing.T) { @@ -261,16 +267,19 @@ func TestEndpoindsAndDomainWithAllExporters(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, te, "failed to create trace exporter") assert.NoError(t, te.start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, te.shutdown(context.Background())) me, err := newMetricsExporter(cfg, params) require.NoError(t, err) require.NotNil(t, me, "failed to create metrics exporter") require.NoError(t, me.start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, me.shutdown(context.Background())) le, err := newLogsExporter(cfg, params) require.NoError(t, err) require.NotNil(t, le, "failed to create logs exporter") require.NoError(t, le.start(context.Background(), componenttest.NewNopHost())) + assert.NoError(t, le.shutdown(context.Background())) } func TestGetMetadataFromResource(t *testing.T) { diff --git a/exporter/coralogixexporter/factory_test.go b/exporter/coralogixexporter/factory_test.go index d1783be77dc0..9c98356722fd 100644 --- a/exporter/coralogixexporter/factory_test.go +++ b/exporter/coralogixexporter/factory_test.go @@ -43,6 +43,7 @@ func TestCreateMetricsExporter(t *testing.T) { oexp, err := factory.CreateMetricsExporter(context.Background(), set, cfg) require.NoError(t, err) require.NotNil(t, oexp) + require.NoError(t, oexp.Shutdown(context.Background())) } func TestCreateMetricsExporterWithDomain(t *testing.T) { @@ -65,6 +66,7 @@ func TestCreateLogsExporter(t *testing.T) { oexp, err := factory.CreateLogsExporter(context.Background(), set, cfg) require.NoError(t, err) require.NotNil(t, oexp) + require.NoError(t, oexp.Shutdown(context.Background())) } func TestCreateLogsExporterWithDomain(t *testing.T) { diff --git a/exporter/coralogixexporter/go.mod b/exporter/coralogixexporter/go.mod index d271438aff14..0c7aadc2511c 100644 --- a/exporter/coralogixexporter/go.mod +++ b/exporter/coralogixexporter/go.mod @@ -18,6 +18,7 @@ require ( go.opentelemetry.io/collector/pdata v1.1.0 go.opentelemetry.io/otel/metric v1.23.0 go.opentelemetry.io/otel/trace v1.23.0 + go.uber.org/goleak v1.3.0 google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 google.golang.org/grpc v1.61.0 ) diff --git a/exporter/coralogixexporter/go.sum b/exporter/coralogixexporter/go.sum index bff0f9ce119e..a4afaee01f3d 100644 --- a/exporter/coralogixexporter/go.sum +++ b/exporter/coralogixexporter/go.sum @@ -129,6 +129,7 @@ go.opentelemetry.io/otel/sdk/metric v1.23.0/go.mod h1:2LUOToN/FdX6wtfpHybOnCZjoZ go.opentelemetry.io/otel/trace v1.23.0 h1:37Ik5Ib7xfYVb4V1UtnT97T1jI+AoIYkJyPkuL4iJgI= go.opentelemetry.io/otel/trace v1.23.0/go.mod h1:GSGTbIClEsuZrGIzoEHqsVfxgn5UkggkflQwDScNUsk= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= diff --git a/exporter/coralogixexporter/package_test.go b/exporter/coralogixexporter/package_test.go new file mode 100644 index 000000000000..5c3305c1c0e1 --- /dev/null +++ b/exporter/coralogixexporter/package_test.go @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package coralogixexporter + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +}