Skip to content

Commit

Permalink
[chore][exporter/splunkhecexporter] Enable goleak check (open-telemet…
Browse files Browse the repository at this point in the history
…ry#30968)

**Description:** 
This enables `goleak` checks for the splunkhecexporter, to help ensure
no goroutines are being leaked. This is a test only change, some
`Shutdown` calls were missing, as well as channel send operations were
blocking in tests because there was no one reading from the channel.

**Link to tracking Issue:**
open-telemetry#30438

**Testing:** 
Existing tests are all passing as well as added `goleak` check.
  • Loading branch information
crobert-1 committed Mar 8, 2024
1 parent 039b606 commit 8fba4db
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 153 deletions.
15 changes: 9 additions & 6 deletions exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ func (c *capturingData) ServeHTTP(w http.ResponseWriter, r *http.Request) {
panic(err)
}
go func() {
c.receivedRequest <- receivedRequest{body, r.Header}
if c.receivedRequest != nil {
c.receivedRequest <- receivedRequest{body, r.Header}
}
}()
w.WriteHeader(c.statusCode)
}
Expand Down Expand Up @@ -1266,7 +1268,7 @@ func Test_PushMetricsData_Summary_NaN_Sum(t *testing.T) {
func TestReceiveMetricsWithCompression(t *testing.T) {
cfg := NewFactory().CreateDefaultConfig().(*Config)
cfg.MaxContentLengthMetrics = 1800
request, err := runMetricsExport(cfg, createMetricsData(1, 100), 1, false, t)
request, err := runMetricsExport(cfg, createMetricsData(1, 100), 2, false, t)
assert.NoError(t, err)
assert.Equal(t, "gzip", request[0].headers.Get("Content-Encoding"))
assert.NotEqual(t, "", request)
Expand Down Expand Up @@ -1363,8 +1365,7 @@ func TestInvalidURL(t *testing.T) {
}

func TestHeartbeatStartupFailed(t *testing.T) {
rr := make(chan receivedRequest)
capture := capturingData{receivedRequest: rr, statusCode: 403}
capture := capturingData{statusCode: 403}
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
Expand Down Expand Up @@ -1398,6 +1399,7 @@ func TestHeartbeatStartupFailed(t *testing.T) {
exporter.Start(context.Background(), componenttest.NewNopHost()),
fmt.Sprintf("%s: heartbeat on startup failed: HTTP 403 \"Forbidden\"", params.ID.Type()),
)
assert.NoError(t, exporter.Shutdown(context.Background()))
}

func TestHeartbeatStartupPass_Disabled(t *testing.T) {
Expand Down Expand Up @@ -1433,11 +1435,11 @@ 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) {
rr := make(chan receivedRequest)
capture := capturingData{receivedRequest: rr, statusCode: 200}
capture := capturingData{statusCode: 200}
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
Expand Down Expand Up @@ -1468,6 +1470,7 @@ 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()))
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.96.1-0.20240306115632-b2693620eff6
go.opentelemetry.io/otel/metric v1.24.0
go.opentelemetry.io/otel/trace v1.24.0
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
Loading

0 comments on commit 8fba4db

Please sign in to comment.