Skip to content

Commit

Permalink
[chore][exporter/coralogixexporter] Enable goleak check (#30803)
Browse files Browse the repository at this point in the history
**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.-->
This enables the `goleak` check on all tests in this package, to ensure
the exporter isn't leaking goroutines. The only updates here are tests,
as some were missing necessary `shutdown` calls. I also updated some
variable naming to match types, such as `le` for a logs exporter instead
of `me`.

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

**Testing:** <Describe what testing was performed and which tests were
added.>
All tests are passing, including added `goleak` check.

---------

Co-authored-by: Alex Boten <aboten@lightstep.com>
  • Loading branch information
crobert-1 and Alex Boten authored Feb 9, 2024
1 parent 485098b commit 302178a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
15 changes: 12 additions & 3 deletions exporter/coralogixexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func TestTraceExporter(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, te, "failed to create trace exporter")
assert.NoError(t, te.start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, te.shutdown(context.Background()))
}

func TestMetricsExporter(t *testing.T) {
Expand All @@ -198,6 +199,7 @@ func TestMetricsExporter(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, me, "failed to create metrics exporter")
require.NoError(t, me.start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, me.shutdown(context.Background()))
}

func TestLogsExporter(t *testing.T) {
Expand All @@ -213,10 +215,11 @@ func TestLogsExporter(t *testing.T) {

params := exportertest.NewNopCreateSettings()

me, err := newLogsExporter(cfg, params)
le, err := newLogsExporter(cfg, params)
require.NoError(t, err)
require.NotNil(t, me, "failed to create logs exporter")
require.NoError(t, me.start(context.Background(), componenttest.NewNopHost()))
require.NotNil(t, le, "failed to create logs exporter")
require.NoError(t, le.start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, le.shutdown(context.Background()))
}

func TestDomainWithAllExporters(t *testing.T) {
Expand All @@ -234,16 +237,19 @@ func TestDomainWithAllExporters(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, te, "failed to create trace exporter")
assert.NoError(t, te.start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, te.shutdown(context.Background()))

me, err := newMetricsExporter(cfg, params)
require.NoError(t, err)
require.NotNil(t, me, "failed to create metrics exporter")
require.NoError(t, me.start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, me.shutdown(context.Background()))

le, err := newLogsExporter(cfg, params)
require.NoError(t, err)
require.NotNil(t, le, "failed to create logs exporter")
require.NoError(t, le.start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, le.shutdown(context.Background()))
}

func TestEndpoindsAndDomainWithAllExporters(t *testing.T) {
Expand All @@ -261,16 +267,19 @@ func TestEndpoindsAndDomainWithAllExporters(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, te, "failed to create trace exporter")
assert.NoError(t, te.start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, te.shutdown(context.Background()))

me, err := newMetricsExporter(cfg, params)
require.NoError(t, err)
require.NotNil(t, me, "failed to create metrics exporter")
require.NoError(t, me.start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, me.shutdown(context.Background()))

le, err := newLogsExporter(cfg, params)
require.NoError(t, err)
require.NotNil(t, le, "failed to create logs exporter")
require.NoError(t, le.start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, le.shutdown(context.Background()))
}

func TestGetMetadataFromResource(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions exporter/coralogixexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestCreateMetricsExporter(t *testing.T) {
oexp, err := factory.CreateMetricsExporter(context.Background(), set, cfg)
require.NoError(t, err)
require.NotNil(t, oexp)
require.NoError(t, oexp.Shutdown(context.Background()))
}

func TestCreateMetricsExporterWithDomain(t *testing.T) {
Expand All @@ -65,6 +66,7 @@ func TestCreateLogsExporter(t *testing.T) {
oexp, err := factory.CreateLogsExporter(context.Background(), set, cfg)
require.NoError(t, err)
require.NotNil(t, oexp)
require.NoError(t, oexp.Shutdown(context.Background()))
}

func TestCreateLogsExporterWithDomain(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions exporter/coralogixexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
go.opentelemetry.io/collector/pdata v1.1.0
go.opentelemetry.io/otel/metric v1.23.0
go.opentelemetry.io/otel/trace v1.23.0
go.uber.org/goleak v1.3.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1
google.golang.org/grpc v1.61.0
)
Expand Down
1 change: 1 addition & 0 deletions exporter/coralogixexporter/go.sum

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

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

package coralogixexporter

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
}

0 comments on commit 302178a

Please sign in to comment.