Skip to content

Commit

Permalink
Merge pull request #1973 from qiangmzsx/master
Browse files Browse the repository at this point in the history
fix: metrics still taking up too much memory when metrics.UseNilMetrics=true
  • Loading branch information
bai authored Sep 7, 2021
2 parents 8e33dc9 + a873069 commit 6743c12
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (b *Broker) Open(conf *Config) error {
b.requestsInFlight = metrics.GetOrRegisterCounter("requests-in-flight", conf.MetricRegistry)
// Do not gather metrics for seeded broker (only used during bootstrap) because they share
// the same id (-1) and are already exposed through the global metrics above
if b.id >= 0 {
if b.id >= 0 && !metrics.UseNilMetrics {
b.registerMetrics()
}

Expand Down
33 changes: 33 additions & 0 deletions broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,3 +1041,36 @@ func validateBrokerMetrics(t *testing.T, broker *Broker, mockBrokerMetrics broke
// Run the validators
metricValidators.run(t, broker.conf.MetricRegistry)
}

func BenchmarkBroker_Open(b *testing.B) {
mb := NewMockBroker(nil, 0)
broker := NewBroker(mb.Addr())
// Set the broker id in order to validate local broker metrics
broker.id = 0
metrics.UseNilMetrics = false
conf := NewTestConfig()
conf.Version = V1_0_0_0
for i := 0; i < b.N; i++ {
err := broker.Open(conf)
if err != nil {
b.Fatal(err)
}
broker.Close()
}
}

func BenchmarkBroker_No_Metrics_Open(b *testing.B) {
mb := NewMockBroker(nil, 0)
broker := NewBroker(mb.Addr())
broker.id = 0
metrics.UseNilMetrics = true
conf := NewTestConfig()
conf.Version = V1_0_0_0
for i := 0; i < b.N; i++ {
err := broker.Open(conf)
if err != nil {
b.Fatal(err)
}
broker.Close()
}
}
3 changes: 2 additions & 1 deletion functional_client_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build functional
//go:build functional
// +build functional

package sarama

Expand Down
3 changes: 2 additions & 1 deletion functional_consumer_group_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build functional
//go:build functional
// +build functional

package sarama

Expand Down
3 changes: 2 additions & 1 deletion functional_consumer_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build functional
//go:build functional
// +build functional

package sarama

Expand Down
3 changes: 2 additions & 1 deletion functional_offset_manager_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build functional
//go:build functional
// +build functional

package sarama

Expand Down
3 changes: 2 additions & 1 deletion functional_producer_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build functional
//go:build functional
// +build functional

package sarama

Expand Down
3 changes: 2 additions & 1 deletion functional_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build functional
//go:build functional
// +build functional

package sarama

Expand Down

0 comments on commit 6743c12

Please sign in to comment.