Skip to content

Commit e223d14

Browse files
BB-727: Log zookeeper details
1 parent 694086a commit e223d14

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

lib/clients/ZookeeperManager.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ class ZookeeperManager extends EventEmitter {
2121
this._connect();
2222
}
2323

24+
zkDetails(client) {
25+
const localAddress = client.connectionManager.socket.address();
26+
return {
27+
sessionId: `0x${ client.getSessionId().toString('hex')}`,
28+
socket: `${localAddress.address}:${localAddress.port}`,
29+
stateConn: client.connectionManager.state,
30+
state: client.getState(),
31+
xid: client.connectionManager.xid,
32+
zxid: client.connectionManager.zxid.toString('hex'),
33+
nextServerIndex: client.connectionManager.nextServerIndex,
34+
serverAttempts: client.connectionManager.serverAttempts,
35+
};
36+
}
37+
2438
/**
2539
* Establishes a connection to the ZooKeeper server.
2640
*
@@ -51,6 +65,10 @@ class ZookeeperManager extends EventEmitter {
5165
async.series([
5266
// Check zookeeper client is connected
5367
next => this.client.once('connected', next),
68+
next => {
69+
this.log.info('connected to zookeeper', { zk: this.zkDetails(this.client) });
70+
next();
71+
},
5472
// Create namespace if it exists and options.autoCreateNamespace is true
5573
next => {
5674
// TODO: ARTESCA-10337 The 'autoCreateNamespace' functionality is currently specific to
@@ -82,7 +100,12 @@ class ZookeeperManager extends EventEmitter {
82100
const hostPort = this.connectionString.slice(0, nsIndex);
83101
rootZkClient = zookeeper.createClient(hostPort, this.options);
84102
rootZkClient.connect();
85-
rootZkClient.once('connected', () => next());
103+
rootZkClient.once('connected', () => {
104+
this.log.info('connected to root zookeeper', {
105+
zk: this.zkDetails(rootZkClient),
106+
});
107+
next();
108+
});
86109
},
87110
// Once connected, use the root zookeeper client to create the namespace
88111
next => rootZkClient.mkdirp(namespace, err => {
@@ -93,30 +116,35 @@ class ZookeeperManager extends EventEmitter {
93116
return next({ event: 'ready' });
94117
}),
95118
], ({ event, err }) => {
119+
this.log.info('zookeeper client event', { event, err, zk: this.zkDetails(this.client) });
96120
this.emit(event, err);
97121
});
98122

99123
this.client.once('expired', () => {
100124
this.log.info('zookeeper client expired', {
101125
method: 'ZookeeperManager.once.expired',
126+
zk: this.zkDetails(this.client),
102127
});
103128
// establish a new session with the ZooKeeper.
104129
this._connect();
105130
});
106131

107132
this.client.on('state', state => {
108-
this.log.debug('zookeeper new state', {
133+
this.log.info('zookeeper new state', {
109134
state,
110135
method: 'ZookeeperManager.on.state',
136+
zk: this.zkDetails(this.client),
111137
});
112138
});
113139

114140
// Forward ZooKeeper events
115141
this.client.on('connected', () => {
142+
this.log.info('zookeeper client connected', { zk: this.zkDetails(this.client) });
116143
this.emit('connected');
117144
});
118145

119146
this.client.on('disconnected', () => {
147+
this.log.info('zookeeper client disconnected', { zk: this.zkDetails(this.client) });
120148
this.emit('disconnected');
121149
});
122150

@@ -131,6 +159,7 @@ class ZookeeperManager extends EventEmitter {
131159
* @return {undefined}
132160
*/
133161
close() {
162+
this.log.info('closing existing zookeeper client', { zk: this.zkDetails(this.client) });
134163
this.client.close();
135164
return;
136165
}

0 commit comments

Comments
 (0)