[chore][processor/batchprocessor] Enable goleak check (#9224)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Add `goleak` to detect leaks in tests. Leaking goroutines were detected
that were caused by a dependency that we can ignore
(`go.opencensus.io/stats/view.(*worker).start`), some `Shutdown` calls
were also added that were missing.

**Link to tracking Issue:** <Issue number if applicable>
#9165 

**Testing:** <Describe what testing was performed and which tests were
added.>
Added check is passing as well as existing tests.
This commit is contained in:
Curtis Robert 2024-01-09 12:23:37 -08:00 committed by GitHub
parent c5a2c78d61
commit fbfbe04fbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 1 deletions

View File

@ -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)

View File

@ -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")
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")
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")
assert.NoError(t, lp.Shutdown(context.Background()))
}

View File

@ -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
)

View File

@ -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=

View File

@ -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"))
}