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())
}
11 changes: 8 additions & 3 deletions plugin/storage/integration/cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"

"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 @@ -65,6 +67,9 @@ func (s *CassandraStorageIntegration) initializeCassandra(t *testing.T) {
"--cassandra-archive.password=" + password,
"--cassandra-archive.username=" + username,
})
t.Cleanup(func() {
Manik2708 marked this conversation as resolved.
Show resolved Hide resolved
assert.NoError(t, f.Close())
})
s.factory = f
var err error
s.SpanWriter, err = f.CreateSpanWriter()
Expand All @@ -78,9 +83,6 @@ func (s *CassandraStorageIntegration) initializeCassandra(t *testing.T) {
s.SamplingStore, err = f.CreateSamplingStore(0)
require.NoError(t, err)
s.initializeDependencyReaderAndWriter(t, f)
t.Cleanup(func() {
require.NoError(t, f.Close())
})
}

func (s *CassandraStorageIntegration) initializeDependencyReaderAndWriter(t *testing.T, f *cassandra.Factory) {
Expand All @@ -98,6 +100,9 @@ func (s *CassandraStorageIntegration) initializeDependencyReaderAndWriter(t *tes
}

func TestCassandraStorage(t *testing.T) {
t.Cleanup(func() {
testutils.VerifyGoLeaksOnce(t)
})
SkipUnlessEnv(t, "cassandra")
s := newCassandraStorageIntegration()
s.initializeCassandra(t)
Expand Down
12 changes: 11 additions & 1 deletion plugin/storage/integration/kafka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/Shopify/sarama"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
Expand All @@ -20,6 +21,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 All @@ -40,6 +42,9 @@ func (s *KafkaIntegrationTestSuite) initialize(t *testing.T) {
topic := "jaeger-kafka-integration-test-" + strconv.FormatInt(time.Now().UnixNano(), 10)

f := kafka.NewFactory()
t.Cleanup(func() {
assert.NoError(t, f.Close())
})
Manik2708 marked this conversation as resolved.
Show resolved Hide resolved
v, command := config.Viperize(f.AddFlags)
err := command.ParseFlags([]string{
"--kafka.producer.topic",
Expand All @@ -56,7 +61,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 All @@ -82,6 +86,9 @@ func (s *KafkaIntegrationTestSuite) initialize(t *testing.T) {
traceStore := memory.NewStore()
spanConsumer, err := builder.CreateConsumer(logger, metrics.NullFactory, traceStore, options)
require.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, spanConsumer.Close())
})
spanConsumer.Start()

s.SpanWriter = spanWriter
Expand Down Expand Up @@ -119,6 +126,9 @@ func (*ingester) FindTraceIDs(context.Context, *spanstore.TraceQueryParameters)
}

func TestKafkaStorage(t *testing.T) {
t.Cleanup(func() {
testutils.VerifyGoLeaksOnce(t)
})
SkipUnlessEnv(t, "kafka")
s := &KafkaIntegrationTestSuite{}
s.initialize(t)
Expand Down