From b7e9742cda630491e06c5b77ac9b2933abbf8f42 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Thu, 4 Jan 2024 15:40:01 -0800 Subject: [PATCH] [chore][processor/batchprocessor] Enable goleak check Enable goleak detection in tests for the batchprocessor package. Ignore a dependency unrelated to this package that has a leak, as well as add missing Shutdown calls that were also leaking goroutines. --- .../batchprocessor/batch_processor_test.go | 4 +++- processor/batchprocessor/factory_test.go | 3 +++ processor/batchprocessor/go.mod | 1 + processor/batchprocessor/go.sum | 1 + processor/batchprocessor/package_test.go | 17 +++++++++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 processor/batchprocessor/package_test.go diff --git a/processor/batchprocessor/batch_processor_test.go b/processor/batchprocessor/batch_processor_test.go index 11eaa9b071f..0cd25b7bef0 100644 --- a/processor/batchprocessor/batch_processor_test.go +++ b/processor/batchprocessor/batch_processor_test.go @@ -1034,7 +1034,7 @@ func TestBatchProcessorMetadataCardinalityLimit(t *testing.T) { func TestBatchZeroConfig(t *testing.T) { // This is a no-op configuration. No need for a timer, no - // minimum, no mxaimum, just a pass through. + // minimum, no maximum, just a pass through. cfg := Config{} require.NoError(t, cfg.Validate()) @@ -1047,6 +1047,7 @@ func TestBatchZeroConfig(t *testing.T) { batcher, err := newBatchLogsProcessor(creationSet, sink, &cfg, false) require.NoError(t, err) require.NoError(t, batcher.Start(context.Background(), componenttest.NewNopHost())) + defer func() { require.NoError(t, batcher.Shutdown(context.Background())) }() expect := 0 for requestNum := 0; requestNum < requestCount; requestNum++ { @@ -1087,6 +1088,7 @@ func TestBatchSplitOnly(t *testing.T) { batcher, err := newBatchLogsProcessor(creationSet, sink, &cfg, false) require.NoError(t, err) require.NoError(t, batcher.Start(context.Background(), componenttest.NewNopHost())) + defer func() { require.NoError(t, batcher.Shutdown(context.Background())) }() for requestNum := 0; requestNum < requestCount; requestNum++ { ld := testdata.GenerateLogs(logsPerRequest) diff --git a/processor/batchprocessor/factory_test.go b/processor/batchprocessor/factory_test.go index 1be144c794a..2550dd5f534 100644 --- a/processor/batchprocessor/factory_test.go +++ b/processor/batchprocessor/factory_test.go @@ -29,12 +29,15 @@ func TestCreateProcessor(t *testing.T) { tp, err := factory.CreateTracesProcessor(context.Background(), creationSet, cfg, nil) assert.NotNil(t, tp) assert.NoError(t, err, "cannot create trace processor") + defer func() { assert.NoError(t, tp.Shutdown(context.Background())) }() mp, err := factory.CreateMetricsProcessor(context.Background(), creationSet, cfg, nil) assert.NotNil(t, mp) assert.NoError(t, err, "cannot create metric processor") + defer func() { assert.NoError(t, mp.Shutdown(context.Background())) }() lp, err := factory.CreateLogsProcessor(context.Background(), creationSet, cfg, nil) assert.NotNil(t, lp) assert.NoError(t, err, "cannot create logs processor") + defer func() { assert.NoError(t, lp.Shutdown(context.Background())) }() } diff --git a/processor/batchprocessor/go.mod b/processor/batchprocessor/go.mod index b5f235a2feb..db004f3eca0 100644 --- a/processor/batchprocessor/go.mod +++ b/processor/batchprocessor/go.mod @@ -22,6 +22,7 @@ require ( go.opentelemetry.io/otel/sdk v1.21.0 go.opentelemetry.io/otel/sdk/metric v1.21.0 go.opentelemetry.io/otel/trace v1.21.0 + go.uber.org/goleak v1.3.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.26.0 ) diff --git a/processor/batchprocessor/go.sum b/processor/batchprocessor/go.sum index 18a6ff42bfb..0fa8482b09f 100644 --- a/processor/batchprocessor/go.sum +++ b/processor/batchprocessor/go.sum @@ -275,6 +275,7 @@ go.opentelemetry.io/otel/sdk/metric v1.21.0/go.mod h1:FJ8RAsoPGv/wYMgBdUJXOm+6pz go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= 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/processor/batchprocessor/package_test.go b/processor/batchprocessor/package_test.go new file mode 100644 index 00000000000..0ada4de78d5 --- /dev/null +++ b/processor/batchprocessor/package_test.go @@ -0,0 +1,17 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package batchprocessor + +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")) +}