Skip to content

Commit

Permalink
[chore][processor/batchprocessor] Enable goleak check (#9224)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
crobert-1 committed Jan 9, 2024
1 parent c5a2c78 commit fbfbe04
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion processor/batchprocessor/batch_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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++ {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions processor/batchprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
1 change: 1 addition & 0 deletions processor/batchprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
1 change: 1 addition & 0 deletions processor/batchprocessor/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions processor/batchprocessor/package_test.go
Original file line number Diff line number Diff line change
@@ -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"))
}

0 comments on commit fbfbe04

Please sign in to comment.