Skip to content

Commit

Permalink
[chore][config/configgrpc] Enable goleak check (#9217)
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.-->
Enables goleak to run on the configgrpc package. Requires ignoring the
opencensus-go leak.

A few tests required an additional client connection close command to
exit the client go routine. Additional information can be found
[here](https://pkg.go.dev/google.golang.org/grpc#DialContext) in the
explanation for the method grpc.DialContext, specifically this comment:
```
Users should call ClientConn.Close to terminate all the pending operations after this function returns.
```
configgrpc's method
[`ToClientConn`](https://github.com/open-telemetry/opentelemetry-collector/blob/36730599ae4fb2ffc05d8e6e8a42e0bb0880703f/config/configgrpc/configgrpc.go#L178)
is directly calling the `grpc.DialContext` method referenced.

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

**Testing:** <Describe what testing was performed and which tests were
added.>
Added goleak check is passing
  • Loading branch information
crobert-1 committed Feb 3, 2024
1 parent 74485a5 commit c746d8b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ func TestHttpReception(t *testing.T) {
}
grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings())
assert.NoError(t, errClient)
defer func() { assert.NoError(t, grpcClientConn.Close()) }()
c := ptraceotlp.NewGRPCClient(grpcClientConn)
ctx, cancelFunc := context.WithTimeout(context.Background(), 2*time.Second)
resp, errResp := c.Export(ctx, ptraceotlp.NewExportRequest(), grpc.WaitForReady(true))
Expand Down Expand Up @@ -686,6 +687,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) {
}
grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings())
assert.NoError(t, errClient)
defer func() { assert.NoError(t, grpcClientConn.Close()) }()
c := ptraceotlp.NewGRPCClient(grpcClientConn)
ctx, cancelFunc := context.WithTimeout(context.Background(), 2*time.Second)
resp, errResp := c.Export(ctx, ptraceotlp.NewExportRequest(), grpc.WaitForReady(true))
Expand Down Expand Up @@ -894,6 +896,7 @@ func TestClientInfoInterceptors(t *testing.T) {

grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings())
require.NoError(t, errClient)
defer func() { assert.NoError(t, grpcClientConn.Close()) }()

cl := ptraceotlp.NewGRPCClient(grpcClientConn)
ctx, cancelFunc := context.WithTimeout(context.Background(), 2*time.Second)
Expand Down
1 change: 1 addition & 0 deletions config/configgrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
go.opentelemetry.io/collector/pdata v1.0.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0
go.opentelemetry.io/otel v1.22.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.26.0
google.golang.org/grpc v1.61.0
)
Expand Down
1 change: 1 addition & 0 deletions config/configgrpc/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 config/configgrpc/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 configgrpc

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 c746d8b

Please sign in to comment.