Skip to content

Commit

Permalink
Merge pull request #744 from slaunay/enhancement/custom-metric-registry
Browse files Browse the repository at this point in the history
Use a local registry for metrics
  • Loading branch information
eapache authored Sep 7, 2016
2 parents e03d23b + 3f8bfba commit 482c471
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 13 deletions.
4 changes: 0 additions & 4 deletions broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"testing"
"time"

"github.com/rcrowley/go-metrics"
)

func ExampleBroker() {
Expand Down Expand Up @@ -74,8 +72,6 @@ func TestSimpleBrokerCommunication(t *testing.T) {
broker.id = 0
conf := NewConfig()
conf.Version = V0_10_0_0
// Use a new registry every time to prevent side effect caused by the global one
conf.MetricRegistry = metrics.NewRegistry()
err := broker.Open(conf)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ type Config struct {
// running may lead to random breakage.
Version KafkaVersion
// The registry to define metrics into.
// Defaults to metrics.DefaultRegistry.
// Defaults to a local registry.
// If you want to disable metrics gathering, set "metrics.UseNilMetrics" to "true"
// prior to starting Sarama.
// See Examples on how to use the metrics registry
Expand Down Expand Up @@ -276,7 +276,7 @@ func NewConfig() *Config {
c.ClientID = defaultClientID
c.ChannelBufferSize = 256
c.Version = minVersion
c.MetricRegistry = metrics.DefaultRegistry
c.MetricRegistry = metrics.NewRegistry()

return c
}
Expand Down
6 changes: 3 additions & 3 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func TestDefaultConfigValidates(t *testing.T) {
if err := config.Validate(); err != nil {
t.Error(err)
}
if config.MetricRegistry != metrics.DefaultRegistry {
t.Error("Expected metrics.DefaultRegistry, got ", config.MetricRegistry)
if config.MetricRegistry == nil {
t.Error("Expected non nil metrics.MetricRegistry, got nil")
}
}

Expand Down Expand Up @@ -42,7 +42,7 @@ func ExampleConfig_metrics() {
appGauge.Update(1)

config := NewConfig()
// Use a prefix registry instead of the default global one
// Use a prefix registry instead of the default local one
config.MetricRegistry = metrics.NewPrefixedChildRegistry(appMetricRegistry, "sarama.")

// Simulate a metric created by sarama without starting a broker
Expand Down
3 changes: 0 additions & 3 deletions functional_producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ func testProducingMessages(t *testing.T, config *Config) {
setupFunctionalTest(t)
defer teardownFunctionalTest(t)

// Use a dedicated registry to prevent side effect caused by the global one
config.MetricRegistry = metrics.NewRegistry()

config.Producer.Return.Successes = true
config.Consumer.Return.Errors = true

Expand Down
2 changes: 1 addition & 1 deletion sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ the producers and the consumer. The Request/Response objects and properties are
exactly with the protocol fields documented by Kafka at
https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
Metrics are exposed through https://github.com/rcrowley/go-metrics library.
Metrics are exposed through https://github.com/rcrowley/go-metrics library in a local registry.
Broker related metrics:
Expand Down

0 comments on commit 482c471

Please sign in to comment.