Skip to content

Commit

Permalink
Merge pull request #991 from Shopify/cleanup-broker-metric-leaks
Browse files Browse the repository at this point in the history
Unregister metrics when closing broker
  • Loading branch information
eapache authored Dec 5, 2017
2 parents 8f05b2f + 99dfd77 commit cd645bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ func (b *Broker) Close() error {
b.done = nil
b.responses = nil

if b.id >= 0 {
b.conf.MetricRegistry.Unregister(getMetricNameForBroker("incoming-byte-rate", b))
b.conf.MetricRegistry.Unregister(getMetricNameForBroker("request-rate", b))
b.conf.MetricRegistry.Unregister(getMetricNameForBroker("outgoing-byte-rate", b))
b.conf.MetricRegistry.Unregister(getMetricNameForBroker("response-rate", b))
}

if err == nil {
Logger.Printf("Closed connection to broker %s\n", b.addr)
} else {
Expand Down
8 changes: 4 additions & 4 deletions broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ func TestSimpleBrokerCommunication(t *testing.T) {
t.Fatal(err)
}
tt.runner(t, broker)
err = broker.Close()
if err != nil {
t.Error(err)
}
// Wait up to 500 ms for the remote broker to process the request and
// notify us about the metrics
timeout := 500 * time.Millisecond
Expand All @@ -91,6 +87,10 @@ func TestSimpleBrokerCommunication(t *testing.T) {
t.Errorf("No request received for: %s after waiting for %v", tt.name, timeout)
}
mb.Close()
err = broker.Close()
if err != nil {
t.Error(err)
}
}

}
Expand Down

0 comments on commit cd645bf

Please sign in to comment.