Skip to content

Commit

Permalink
Add debug log for brokers discovered through zookeeper (#122)
Browse files Browse the repository at this point in the history
Add debug logs for brokers discovered through zookeeper
  • Loading branch information
davidbrota authored May 26, 2021
1 parent a59bf78 commit 460eb62
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 2.15.1 (2021-05-26)
### Changed
- Add debug broker logs from Zookeeper

## 2.15.0 (2021-03-24)
### Changed
- Upgraded github.com/newrelic/infra-integrations-sdk to v3.6.6
Expand Down
3 changes: 2 additions & 1 deletion src/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func GetBrokerFromZookeeper(zkConn zookeeper.Connection, id, preferredListener s
if err != nil {
return nil, fmt.Errorf("failed to unmarshal broker information from zookeeper: %s", err)
}
log.Debug("zookeeper instance %s is reporting broker %s with the following information %+v", zkConn.Server(), id, brokerDecoded)

// Go through the list of brokers until we find one that uses a protocol we know how to handle
for _, endpoint := range brokerDecoded.Endpoints {
Expand All @@ -357,7 +358,7 @@ func GetBrokerFromZookeeper(zkConn zookeeper.Connection, id, preferredListener s
// Check that the protocol map
protocol, ok := brokerDecoded.ProtocolMap[listener]
if !ok {
log.Error("Listener '%s' was not found in the protocol map")
log.Error("Listener '%s' not found in protocol map for %s:%d", listener, host, port)
continue
}

Expand Down
1 change: 1 addition & 0 deletions src/connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func Test_GetBrokerFromZookeeper(t *testing.T) {

zkConn := &zookeeper.MockConnection{}
zkConn.On("Get", "/brokers/ids/0").Return([]byte(`{"listener_security_protocol_map":{"SASL_SSL":"SASL_SSL","SSL":"SSL", "PLAINTEXT":"PLAINTEXT"},"endpoints":["SASL_SSL://my-broker.host:9193","SSL://my-broker.host:9093","PLAINTEXT://my-broker.host:9092"],"rack":"us-east-1d","jmx_port":9999,"host":null,"timestamp":"1542127633364","port":-1,"version":4}`), new(zk.Stat), nil)
zkConn.On("Server").Return("localhost:2181")

_, err := GetBrokerFromZookeeper(zkConn, "0", "PLAINTEXT")
assert.Error(t, err, "Expected error getting broker information from mock")
Expand Down
2 changes: 1 addition & 1 deletion src/jmxwrapper/jmx_wrapper.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package jmxwrapper contains varaibles for using github.com/newrelic/infra-integrations-sdk/jmx package
// Package jmxwrapper contains variables for using github.com/newrelic/infra-integrations-sdk/jmx package
// while allowing everything to be mocked for testing.
package jmxwrapper

Expand Down
5 changes: 5 additions & 0 deletions src/zookeeper/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Connection interface {
Get(string) ([]byte, *zk.Stat, error)
Children(string) ([]string, *zk.Stat, error)
Close()
Server() string
}

type zookeeperConnection struct {
Expand All @@ -29,6 +30,10 @@ func (z zookeeperConnection) Get(s string) ([]byte, *zk.Stat, error) {
return z.inner.Get(s)
}

func (z zookeeperConnection) Server() string {
return z.inner.Server()
}

type zookeeperLogger struct{}

func (z zookeeperLogger) Printf(format string, args ...interface{}) {
Expand Down
6 changes: 6 additions & 0 deletions src/zookeeper/mock_zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ func (m *MockConnection) Children(s string) ([]string, *zk.Stat, error) {
func (m *MockConnection) Close() {
// do nothing
}

// Server returns the hostname
func (m *MockConnection) Server() string {
args := m.Called()
return args.String(0)
}

0 comments on commit 460eb62

Please sign in to comment.