From 61ac8eeb563caacbd414e11f619a006053982af2 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Thu, 8 Feb 2024 16:24:11 -0800 Subject: [PATCH 1/2] [chore][extension/jaegarremotesampling] Enable goleak check --- extension/jaegerremotesampling/extension_test.go | 3 +++ extension/jaegerremotesampling/go.mod | 1 + extension/jaegerremotesampling/go.sum | 1 + extension/jaegerremotesampling/package_test.go | 14 ++++++++++++++ 4 files changed, 19 insertions(+) create mode 100644 extension/jaegerremotesampling/package_test.go diff --git a/extension/jaegerremotesampling/extension_test.go b/extension/jaegerremotesampling/extension_test.go index abb8b243b252..95461a659dcf 100644 --- a/extension/jaegerremotesampling/extension_test.go +++ b/extension/jaegerremotesampling/extension_test.go @@ -120,6 +120,7 @@ func TestRemote(t *testing.T) { resp, err := http.Get("http://127.0.0.1:5778/sampling?service=foo") assert.NoError(t, err) assert.Equal(t, 200, resp.StatusCode) + assert.NoError(t, resp.Body.Close()) } // shut down the server @@ -137,6 +138,8 @@ func TestRemote(t *testing.T) { assert.Equal(t, []string{string(expectedHeaderValue)}, md.Get(expectedHeaderName)) } } + + server.Stop() }) } } diff --git a/extension/jaegerremotesampling/go.mod b/extension/jaegerremotesampling/go.mod index 64668e90a229..46ee685242da 100644 --- a/extension/jaegerremotesampling/go.mod +++ b/extension/jaegerremotesampling/go.mod @@ -19,6 +19,7 @@ require ( go.opentelemetry.io/collector/featuregate 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 go.uber.org/zap v1.26.0 google.golang.org/grpc v1.61.0 ) diff --git a/extension/jaegerremotesampling/go.sum b/extension/jaegerremotesampling/go.sum index 49a5025178f3..85f3a5cb05ca 100644 --- a/extension/jaegerremotesampling/go.sum +++ b/extension/jaegerremotesampling/go.sum @@ -165,6 +165,7 @@ go.opentelemetry.io/otel/sdk/metric v1.23.0/go.mod h1:2LUOToN/FdX6wtfpHybOnCZjoZ go.opentelemetry.io/otel/trace v1.23.0 h1:37Ik5Ib7xfYVb4V1UtnT97T1jI+AoIYkJyPkuL4iJgI= go.opentelemetry.io/otel/trace v1.23.0/go.mod h1:GSGTbIClEsuZrGIzoEHqsVfxgn5UkggkflQwDScNUsk= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= diff --git a/extension/jaegerremotesampling/package_test.go b/extension/jaegerremotesampling/package_test.go new file mode 100644 index 000000000000..1084b9ea4a9e --- /dev/null +++ b/extension/jaegerremotesampling/package_test.go @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package jaegerremotesampling + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} From efeb89b9508c9805a451ca280b54c0d83354f45b Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Fri, 9 Feb 2024 08:05:02 -0800 Subject: [PATCH 2/2] Move stop closer to start, use defer --- extension/jaegerremotesampling/extension_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extension/jaegerremotesampling/extension_test.go b/extension/jaegerremotesampling/extension_test.go index 95461a659dcf..53be6b87d7d8 100644 --- a/extension/jaegerremotesampling/extension_test.go +++ b/extension/jaegerremotesampling/extension_test.go @@ -94,6 +94,7 @@ func TestRemote(t *testing.T) { err = server.Serve(lis) require.NoError(t, err) }() + defer func() { server.Stop() }() // create the config, pointing to the mock server cfg := testConfig() @@ -138,8 +139,6 @@ func TestRemote(t *testing.T) { assert.Equal(t, []string{string(expectedHeaderValue)}, md.Get(expectedHeaderName)) } } - - server.Stop() }) } }