Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore][exporter/splunkhecexporter] Enable goleak check #30968

Merged
merged 10 commits into from
Mar 8, 2024
9 changes: 9 additions & 0 deletions exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ func runMetricsExport(cfg *Config, metrics pmetric.Metrics, expectedBatchesNum i
assert.NoError(t, err)
assert.NoError(t, exporter.Start(context.Background(), componenttest.NewNopHost()))
defer func() {
// Read from channel so that the goroutine running the send operation can exit successfully
_ = <-capture.receivedRequest
crobert-1 marked this conversation as resolved.
Show resolved Hide resolved
assert.NoError(t, exporter.Shutdown(context.Background()))
}()

Expand Down Expand Up @@ -1396,6 +1398,9 @@ func TestHeartbeatStartupFailed(t *testing.T) {
assert.NoError(t, err)
// The exporter's name is "" while generating default params
assert.EqualError(t, exporter.Start(context.Background(), componenttest.NewNopHost()), ": heartbeat on startup failed: HTTP 403 \"Forbidden\"")
// Read from channel so that the goroutine running the send operation can exit successfully
_ = <-capture.receivedRequest
assert.NoError(t, exporter.Shutdown(context.Background()))
}

func TestHeartbeatStartupPass_Disabled(t *testing.T) {
Expand Down Expand Up @@ -1431,6 +1436,7 @@ func TestHeartbeatStartupPass_Disabled(t *testing.T) {
exporter, err := factory.CreateTracesExporter(context.Background(), params, cfg)
assert.NoError(t, err)
assert.NoError(t, exporter.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, exporter.Shutdown(context.Background()))
}

func TestHeartbeatStartupPass(t *testing.T) {
Expand Down Expand Up @@ -1466,6 +1472,9 @@ func TestHeartbeatStartupPass(t *testing.T) {
exporter, err := factory.CreateTracesExporter(context.Background(), params, cfg)
assert.NoError(t, err)
assert.NoError(t, exporter.Start(context.Background(), componenttest.NewNopHost()))
// Read from channel so that the goroutine running the send operation can exit successfully
_ = <-capture.receivedRequest
assert.NoError(t, exporter.Shutdown(context.Background()))
}

type badJSON struct {
Expand Down
1 change: 1 addition & 0 deletions exporter/splunkhecexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
go.opentelemetry.io/collector/semconv v0.93.1-0.20240130182548-89388addcc7f
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/multierr v1.11.0
go.uber.org/zap v1.26.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
1 change: 1 addition & 0 deletions exporter/splunkhecexporter/go.sum

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

24 changes: 12 additions & 12 deletions exporter/splunkhecexporter/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"crypto/tls"
"fmt"
"net/http"
"os"
"os/exec"
"strconv"
"testing"
Expand Down Expand Up @@ -74,17 +73,6 @@ func teardown(cfg SplunkContainerConfig) {
fmt.Printf("Command output:\n%s\n", output)
}

func TestMain(m *testing.M) {
crobert-1 marked this conversation as resolved.
Show resolved Hide resolved
splunkContCfg := setup()

// Run the tests
code := m.Run()

teardown(splunkContCfg)
// Exit with the test result code
os.Exit(code)
}

func createInsecureClient() *http.Client {
// Create a custom transport with insecure settings
tr := &http.Transport{
Expand Down Expand Up @@ -223,6 +211,9 @@ func prepareTracesData(index string, source string, sourcetype string) ptrace.Tr
}

func TestSplunkHecExporterEventsToSplunk(t *testing.T) {
splunkContCfg := setup()
defer teardown(splunkContCfg)

logger := zaptest.NewLogger(t)
logger.Info("Test -> Splunk running at:", zap.String("host", integrationtestutils.GetConfigVariable("HOST")),
zap.String("uiPort", integrationtestutils.GetConfigVariable("UI_PORT")),
Expand Down Expand Up @@ -266,6 +257,9 @@ func TestSplunkHecExporterEventsToSplunk(t *testing.T) {
}

func TestSplunkHecExporterEventsToSplunkNonDefaultIndex(t *testing.T) {
splunkContCfg := setup()
defer teardown(splunkContCfg)

logger := zaptest.NewLogger(t)
logger.Info("Test -> Splunk running at:", zap.String("host", integrationtestutils.GetConfigVariable("HOST")),
zap.String("uiPort", integrationtestutils.GetConfigVariable("UI_PORT")),
Expand Down Expand Up @@ -315,6 +309,9 @@ func TestSplunkHecExporterEventsToSplunkNonDefaultIndex(t *testing.T) {
}

func TestSplunkHecExporterMetricsToSplunk(t *testing.T) {
splunkContCfg := setup()
defer teardown(splunkContCfg)

logger := zaptest.NewLogger(t)
logger.Info("Test -> Splunk running at:", zap.String("host", integrationtestutils.GetConfigVariable("HOST")),
zap.String("uiPort", integrationtestutils.GetConfigVariable("UI_PORT")),
Expand Down Expand Up @@ -350,6 +347,9 @@ func TestSplunkHecExporterMetricsToSplunk(t *testing.T) {
}

func TestSplunkHecExporterTracesToSplunk(t *testing.T) {
splunkContCfg := setup()
defer teardown(splunkContCfg)

logger := zaptest.NewLogger(t)
logger.Info("Test -> Splunk running at:", zap.String("host", integrationtestutils.GetConfigVariable("HOST")),
zap.String("uiPort", integrationtestutils.GetConfigVariable("UI_PORT")),
Expand Down
17 changes: 17 additions & 0 deletions exporter/splunkhecexporter/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 splunkhecexporter

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"))
}
Loading