Skip to content

Commit

Permalink
[chore][exporter/alertmanagerexporter] Enable goleak check (open-tele…
Browse files Browse the repository at this point in the history
…metry#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>
open-telemetry#30438

**Testing:** <Describe what testing was performed and which tests were
added.>
All tests are passing, goleak check is passing.
  • Loading branch information
crobert-1 authored and cparkins committed Feb 1, 2024
1 parent d53cbc0 commit 1f62d29
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func newMockServer(t *testing.T) *MockServer {

func TestAlertManagerPostAlert(t *testing.T) {
mock := newMockServer(t)
defer func() { mock.mockserver.Close() }()
factory := NewFactory()
cfg := factory.CreateDefaultConfig().(*Config)

Expand Down
1 change: 1 addition & 0 deletions exporter/alertmanagerexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
go.opentelemetry.io/collector/semconv v0.93.1-0.20240124123350-9047c0e373f9
go.opentelemetry.io/otel/metric v1.22.0
go.opentelemetry.io/otel/trace v1.22.0
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.26.0
)

Expand Down
1 change: 1 addition & 0 deletions exporter/alertmanagerexporter/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 exporter/alertmanagerexporter/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 alertmanagerexporter

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/census-instrumentation/opencensus-go/issues/1191 for more information.
func TestMain(m *testing.M) {
goleak.VerifyTestMain(m, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"))
}

0 comments on commit 1f62d29

Please sign in to comment.