Skip to content

Commit 5705bc5

Browse files
crobert-1DougManton
authored andcommitted
[chore][cmd/configschema] Enable goleak (open-telemetry#30492)
**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> open-telemetry#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.
1 parent abf9fe4 commit 5705bc5

File tree

10 files changed

+33
-14
lines changed

10 files changed

+33
-14
lines changed

cmd/configschema/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,6 @@ require (
704704
k8s.io/api v0.29.2 // indirect
705705
k8s.io/apimachinery v0.29.2 // indirect
706706
k8s.io/client-go v0.29.2 // indirect
707-
k8s.io/klog v1.0.0 // indirect
708707
k8s.io/klog/v2 v2.110.1 // indirect
709708
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
710709
k8s.io/kubelet v0.29.2 // indirect

cmd/configschema/go.sum

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/configschema/package_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package configschema
5+
6+
import (
7+
"testing"
8+
9+
"go.uber.org/goleak"
10+
)
11+
12+
// The Ignore function calls prevent catching leaks generated by indirect dependencies.
13+
// All of these are leaks that we can't fix from within the collector code base.
14+
// Regarding the OpenCensus ignore: see https://github.com/census-instrumentation/opencensus-go/issues/1191
15+
// Regarding the DataDog ignore: see https://github.com/DataDog/datadog-agent/issues/22030
16+
// Regarding the database/sql ignore: see https://github.com/SAP/go-hdb/issues/130
17+
// Regarding the SAP/go-hdb ignore: see https://github.com/SAP/go-hdb/issues/131
18+
// Regarding the cihub/seelog ignore: see https://github.com/cihub/seelog/issues/182
19+
// Regarding the godbus/dbus ignore: see https://github.com/99designs/keyring/issues/135
20+
func TestMain(m *testing.M) {
21+
goleak.VerifyTestMain(m,
22+
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
23+
goleak.IgnoreTopFunction("github.com/DataDog/datadog-agent/pkg/trace/metrics/timing.(*Set).Autoreport.func1"),
24+
// Unfortunately this ignore can't be anymore specific, even though it's caused by the SAP/go-hdb/driver
25+
// package. There's no reference to this package in the goleak output. This has the potential of
26+
// hiding future leaks, so we should remove as soon as the referenced issue is resolved.
27+
goleak.IgnoreTopFunction("database/sql.(*DB).connectionOpener"),
28+
goleak.IgnoreTopFunction("github.com/SAP/go-hdb/driver.(*metrics).collect"),
29+
goleak.IgnoreAnyFunction("github.com/cihub/seelog.(*asyncLoopLogger).processQueue"),
30+
goleak.IgnoreAnyFunction("github.com/godbus/dbus.(*Conn).inWorker"))
31+
}

cmd/otelcontribcol/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ require (
720720
k8s.io/api v0.29.2 // indirect
721721
k8s.io/apimachinery v0.29.2 // indirect
722722
k8s.io/client-go v0.29.2 // indirect
723-
k8s.io/klog v1.0.0 // indirect
724723
k8s.io/klog/v2 v2.110.1 // indirect
725724
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
726725
k8s.io/kubelet v0.29.2 // indirect

cmd/otelcontribcol/go.sum

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@ require (
700700
k8s.io/api v0.29.2 // indirect
701701
k8s.io/apimachinery v0.29.2 // indirect
702702
k8s.io/client-go v0.29.2 // indirect
703-
k8s.io/klog v1.0.0 // indirect
704703
k8s.io/klog/v2 v2.110.1 // indirect
705704
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
706705
k8s.io/kubelet v0.29.2 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/awscontainerinsightreceiver/go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
k8s.io/api v0.29.2
2727
k8s.io/apimachinery v0.29.2
2828
k8s.io/client-go v0.29.2
29-
k8s.io/klog v1.0.0
29+
k8s.io/klog/v2 v2.110.1
3030
)
3131

3232
require (
@@ -145,7 +145,6 @@ require (
145145
gopkg.in/yaml.v2 v2.4.0 // indirect
146146
gopkg.in/yaml.v3 v3.0.1 // indirect
147147
gotest.tools/v3 v3.0.3 // indirect
148-
k8s.io/klog/v2 v2.110.1 // indirect
149148
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
150149
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
151150
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect

receiver/awscontainerinsightreceiver/go.sum

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/awscontainerinsightreceiver/internal/k8sapiserver/k8sapiserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"k8s.io/client-go/tools/leaderelection"
2525
"k8s.io/client-go/tools/leaderelection/resourcelock"
2626
"k8s.io/client-go/tools/record"
27-
"k8s.io/klog"
27+
"k8s.io/klog/v2"
2828

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

0 commit comments

Comments
 (0)