Skip to content

Commit 2db76a6

Browse files
authored
[chore][exporter/alertmanagerexporter] Enable goleak check (#30710)
**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 check on tests in the `alertmanager` exporter to ensure it's not leaking goroutines. This is a test only change. **Link to tracking Issue:** <Issue number if applicable> #30438 **Testing:** <Describe what testing was performed and which tests were added.> All tests are passing, goleak check is passing.
1 parent 082c427 commit 2db76a6

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

exporter/alertmanagerexporter/alertmanager_exporter_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ func newMockServer(t *testing.T) *MockServer {
308308

309309
func TestAlertManagerPostAlert(t *testing.T) {
310310
mock := newMockServer(t)
311+
defer func() { mock.mockserver.Close() }()
311312
factory := NewFactory()
312313
cfg := factory.CreateDefaultConfig().(*Config)
313314

exporter/alertmanagerexporter/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
go.opentelemetry.io/collector/semconv v0.93.1-0.20240124123350-9047c0e373f9
2121
go.opentelemetry.io/otel/metric v1.22.0
2222
go.opentelemetry.io/otel/trace v1.22.0
23+
go.uber.org/goleak v1.3.0
2324
go.uber.org/zap v1.26.0
2425
)
2526

exporter/alertmanagerexporter/go.sum

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package alertmanagerexporter
5+
6+
import (
7+
"testing"
8+
9+
"go.uber.org/goleak"
10+
)
11+
12+
// The IgnoreTopFunction call prevents catching the leak generated by opencensus
13+
// defaultWorker.Start which at this time is part of the package's init call.
14+
// See https://github.com/census-instrumentation/opencensus-go/issues/1191 for more information.
15+
func TestMain(m *testing.M) {
16+
goleak.VerifyTestMain(m, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"))
17+
}

0 commit comments

Comments
 (0)