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

Add go leak check to Cassandra and Kafka e2e tests #6336

Merged
merged 10 commits into from
Dec 11, 2024
13 changes: 12 additions & 1 deletion pkg/testutils/leakcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ func IgnoreOpenCensusWorkerLeak() goleak.Option {
return goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start")
}

// IgnoreGoMetricsMeterLeak prevents the leak created by go-metrics which is
// used by Sarama (Kafka Client) in Jaeger v1. This reason of this leak is
// not Jaeger but the go-metrics used by Samara.
// See these issues for the context
// - https://github.com/IBM/sarama/issues/1321
// - https://github.com/IBM/sarama/issues/1340
// - https://github.com/IBM/sarama/issues/2832
func IgnoreGoMetricsMeterLeak() goleak.Option {
return goleak.IgnoreTopFunction("github.com/rcrowley/go-metrics.(*meterArbiter).tick")
}

// VerifyGoLeaks verifies that unit tests do not leak any goroutines.
// It should be called in TestMain.
func VerifyGoLeaks(m *testing.M) {
Expand All @@ -36,5 +47,5 @@ func VerifyGoLeaks(m *testing.M) {
//
// defer testutils.VerifyGoLeaksOnce(t)
func VerifyGoLeaksOnce(t *testing.T) {
goleak.VerifyNone(t, IgnoreGlogFlushDaemonLeak(), IgnoreOpenCensusWorkerLeak())
goleak.VerifyNone(t, IgnoreGlogFlushDaemonLeak(), IgnoreOpenCensusWorkerLeak(), IgnoreGoMetricsMeterLeak())
}
2 changes: 2 additions & 0 deletions plugin/storage/integration/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/cassandra"
"github.com/jaegertracing/jaeger/storage/dependencystore"
)
Expand Down Expand Up @@ -80,6 +81,7 @@ func (s *CassandraStorageIntegration) initializeCassandra(t *testing.T) {
s.initializeDependencyReaderAndWriter(t, f)
t.Cleanup(func() {
require.NoError(t, f.Close())
testutils.VerifyGoLeaksOnce(t)
Manik2708 marked this conversation as resolved.
Show resolved Hide resolved
})
}

Expand Down
7 changes: 6 additions & 1 deletion plugin/storage/integration/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/kafka/consumer"
"github.com/jaegertracing/jaeger/pkg/metrics"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/plugin/storage/kafka"
"github.com/jaegertracing/jaeger/plugin/storage/memory"
"github.com/jaegertracing/jaeger/storage/spanstore"
Expand Down Expand Up @@ -56,7 +57,6 @@ func (s *KafkaIntegrationTestSuite) initialize(t *testing.T) {

spanWriter, err := f.CreateSpanWriter()
require.NoError(t, err)

v, command = config.Viperize(app.AddFlags)
err = command.ParseFlags([]string{
"--kafka.consumer.topic",
Expand Down Expand Up @@ -88,6 +88,11 @@ func (s *KafkaIntegrationTestSuite) initialize(t *testing.T) {
s.SpanReader = &ingester{traceStore}
s.CleanUp = func(_ *testing.T) {}
s.SkipArchiveTest = true
t.Cleanup(func() {
require.NoError(t, f.Close())
require.NoError(t, spanConsumer.Close())
testutils.VerifyGoLeaksOnce(t)
})
Manik2708 marked this conversation as resolved.
Show resolved Hide resolved
}

// The ingester consumes spans from kafka and writes them to an in-memory traceStore
Expand Down