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/prometheusexporter] Enable goleak check #30965

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exporter/prometheusexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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/zap v1.27.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
17 changes: 17 additions & 0 deletions exporter/prometheusexporter/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 prometheusexporter

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"))
}
21 changes: 16 additions & 5 deletions exporter/prometheusexporter/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ func TestPrometheusExporter_WithTLS(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, exp.Shutdown(context.Background()))
// trigger a get so that the server cleans up our keepalive socket
_, err = httpClient.Get("https://localhost:7777/metrics")
var resp *http.Response
resp, err = httpClient.Get("https://localhost:7777/metrics")
require.NoError(t, err)
require.NoError(t, resp.Body.Close())

crobert-1 marked this conversation as resolved.
Show resolved Hide resolved
})

assert.NotNil(t, exp)
Expand Down Expand Up @@ -195,8 +198,10 @@ func TestPrometheusExporter_endToEndMultipleTargets(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, exp.Shutdown(context.Background()))
// trigger a get so that the server cleans up our keepalive socket
_, err = http.Get("http://localhost:7777/metrics")
var resp *http.Response
resp, err = http.Get("http://localhost:7777/metrics")
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
})

assert.NotNil(t, exp)
Expand Down Expand Up @@ -277,8 +282,10 @@ func TestPrometheusExporter_endToEnd(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, exp.Shutdown(context.Background()))
// trigger a get so that the server cleans up our keepalive socket
_, err = http.Get("http://localhost:7777/metrics")
var resp *http.Response
resp, err = http.Get("http://localhost:7777/metrics")
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
})

assert.NotNil(t, exp)
Expand Down Expand Up @@ -354,8 +361,10 @@ func TestPrometheusExporter_endToEndWithTimestamps(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, exp.Shutdown(context.Background()))
// trigger a get so that the server cleans up our keepalive socket
_, err = http.Get("http://localhost:7777/metrics")
var resp *http.Response
resp, err = http.Get("http://localhost:7777/metrics")
require.NoError(t, err)
require.NoError(t, resp.Body.Close())
})

assert.NotNil(t, exp)
Expand Down Expand Up @@ -434,8 +443,10 @@ func TestPrometheusExporter_endToEndWithResource(t *testing.T) {
t.Cleanup(func() {
require.NoError(t, exp.Shutdown(context.Background()))
// trigger a get so that the server cleans up our keepalive socket
_, err = http.Get("http://localhost:7777/metrics")
var resp *http.Response
resp, err = http.Get("http://localhost:7777/metrics")
require.NoError(t, err, "Failed to perform a scrape")
require.NoError(t, resp.Body.Close())
})

assert.NotNil(t, exp)
Expand Down
Loading