Skip to content

Commit

Permalink
[chore][cmd/configschema] Enable goleak (#30492)
Browse files Browse the repository at this point in the history
**Description:**
A lot of leaks were happening in this package because of the extensive
list of indirect dependencies. I've filed issues and referenced them for
each indirect leak.

This PR contains two main changes:
1. Enable `goleak` checks for all tests within `cmd/configschema`.
2. k8s.io/klog v1 has a leaking goroutine that was [resolved in
v2](kubernetes/klog#188). I upgraded the
dependency in `recevier/awscontainerinsights` to resolve this issue.
This is a code change, but is totally internal and no user impact.

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

**Testing:**
goleak test is passing

**Thoughts**
1. Some of these indirect dependencies may never get fixed. For example,
one source of a leaking goroutine is
[cihub/seelog](https://github.com/cihub/seelog), which hasn't had a
commit in 8 years.
2. Indirect dependencies that start goroutines in `init()` are the most
common cause. For an example of how indirect it gets, we can look at the
dbus leak.
```
crobert$ ~/dev/opentelemetry-collector-contrib/cmd/configschema $ go mod why github.com/godbus/dbus
# github.com/godbus/dbus
github.com/open-telemetry/opentelemetry-collector-contrib/cmd/configschema/cfgmetadatagen
github.com/open-telemetry/opentelemetry-collector-contrib/internal/components
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/snowflakereceiver
github.com/snowflakedb/gosnowflake
github.com/99designs/keyring
github.com/godbus/dbus
```
The bug is in the `99designs/keyring` dependency, and the `goleak` is
detected as far back as `cmd/configschema` tests.
  • Loading branch information
crobert-1 authored Mar 6, 2024
1 parent 0fb37dc commit 7dd145a
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 14 deletions.
1 change: 0 additions & 1 deletion cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ require (
k8s.io/api v0.29.2 // indirect
k8s.io/apimachinery v0.29.2 // indirect
k8s.io/client-go v0.29.2 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/kubelet v0.29.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions cmd/configschema/go.sum

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

31 changes: 31 additions & 0 deletions cmd/configschema/package_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package configschema

import (
"testing"

"go.uber.org/goleak"
)

// The Ignore function calls prevent catching leaks generated by indirect dependencies.
// All of these are leaks that we can't fix from within the collector code base.
// Regarding the OpenCensus ignore: see https://github.com/census-instrumentation/opencensus-go/issues/1191
// Regarding the DataDog ignore: see https://github.com/DataDog/datadog-agent/issues/22030
// Regarding the database/sql ignore: see https://github.com/SAP/go-hdb/issues/130
// Regarding the SAP/go-hdb ignore: see https://github.com/SAP/go-hdb/issues/131
// Regarding the cihub/seelog ignore: see https://github.com/cihub/seelog/issues/182
// Regarding the godbus/dbus ignore: see https://github.com/99designs/keyring/issues/135
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m,
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
goleak.IgnoreTopFunction("github.com/DataDog/datadog-agent/pkg/trace/metrics/timing.(*Set).Autoreport.func1"),
// Unfortunately this ignore can't be anymore specific, even though it's caused by the SAP/go-hdb/driver
// package. There's no reference to this package in the goleak output. This has the potential of
// hiding future leaks, so we should remove as soon as the referenced issue is resolved.
goleak.IgnoreTopFunction("database/sql.(*DB).connectionOpener"),
goleak.IgnoreTopFunction("github.com/SAP/go-hdb/driver.(*metrics).collect"),
goleak.IgnoreAnyFunction("github.com/cihub/seelog.(*asyncLoopLogger).processQueue"),
goleak.IgnoreAnyFunction("github.com/godbus/dbus.(*Conn).inWorker"))
}
1 change: 0 additions & 1 deletion cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,6 @@ require (
k8s.io/api v0.29.2 // indirect
k8s.io/apimachinery v0.29.2 // indirect
k8s.io/client-go v0.29.2 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/kubelet v0.29.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions cmd/otelcontribcol/go.sum

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

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,6 @@ require (
k8s.io/api v0.29.2 // indirect
k8s.io/apimachinery v0.29.2 // indirect
k8s.io/client-go v0.29.2 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/kubelet v0.29.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum

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

3 changes: 1 addition & 2 deletions receiver/awscontainerinsightreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
k8s.io/api v0.29.2
k8s.io/apimachinery v0.29.2
k8s.io/client-go v0.29.2
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.110.1
)

require (
Expand Down Expand Up @@ -145,7 +145,6 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.0.3 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
2 changes: 0 additions & 2 deletions receiver/awscontainerinsightreceiver/go.sum

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

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/client-go/tools/record"
"k8s.io/klog"
"k8s.io/klog/v2"

ci "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s/k8sclient"
Expand Down

0 comments on commit 7dd145a

Please sign in to comment.