diff --git a/broker.go b/broker.go index dd01e4ef1..36a522c26 100644 --- a/broker.go +++ b/broker.go @@ -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() } diff --git a/broker_test.go b/broker_test.go index 2fa40ceb4..4f8986ce5 100644 --- a/broker_test.go +++ b/broker_test.go @@ -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() + } +} diff --git a/functional_client_test.go b/functional_client_test.go index bc4715dc4..949508c75 100644 --- a/functional_client_test.go +++ b/functional_client_test.go @@ -1,4 +1,5 @@ -//+build functional +//go:build functional +// +build functional package sarama diff --git a/functional_consumer_group_test.go b/functional_consumer_group_test.go index 5fb063bf5..45f6c540f 100644 --- a/functional_consumer_group_test.go +++ b/functional_consumer_group_test.go @@ -1,4 +1,5 @@ -//+build functional +//go:build functional +// +build functional package sarama diff --git a/functional_consumer_test.go b/functional_consumer_test.go index 6364f5b95..2f59183f0 100644 --- a/functional_consumer_test.go +++ b/functional_consumer_test.go @@ -1,4 +1,5 @@ -//+build functional +//go:build functional +// +build functional package sarama diff --git a/functional_offset_manager_test.go b/functional_offset_manager_test.go index 5d7f65663..2d983f287 100644 --- a/functional_offset_manager_test.go +++ b/functional_offset_manager_test.go @@ -1,4 +1,5 @@ -//+build functional +//go:build functional +// +build functional package sarama diff --git a/functional_producer_test.go b/functional_producer_test.go index 74f9682a2..63bf02110 100644 --- a/functional_producer_test.go +++ b/functional_producer_test.go @@ -1,4 +1,5 @@ -//+build functional +//go:build functional +// +build functional package sarama diff --git a/functional_test.go b/functional_test.go index 7f10a9eea..6e9484740 100644 --- a/functional_test.go +++ b/functional_test.go @@ -1,4 +1,5 @@ -//+build functional +//go:build functional +// +build functional package sarama diff --git a/go.mod b/go.mod index ccbd8e2d1..ed9bf16d4 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,6 @@ require ( github.com/xdg/stringprep v1.0.3 // indirect golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect golang.org/x/net v0.0.0-20210614182718-04defd469f4e - golang.org/x/text v0.3.6 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect diff --git a/go.sum b/go.sum index a49776049..508c3ae30 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,6 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210427231257-85d9c07bbe3a h1:njMmldwFTyDLqonHMagNXKBWptTBeDZOdblgaDsNEGQ= -golang.org/x/net v0.0.0-20210427231257-85d9c07bbe3a/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q= golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=