Skip to content

Commit 494105f

Browse files
BB-727: Log zookeeper details
1 parent f4614f2 commit 494105f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/clients/ZookeeperManager.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ 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+
state: client.getState(),
30+
xid: client.connectionManager?.xid,
31+
zxid: client.connectionManager?.zxid?.toString('hex'),
32+
nextServerIndex: client.connectionManager?.nextServerIndex,
33+
serverAttempts: client.connectionManager?.serverAttempts,
34+
};
35+
}
36+
2437
/**
2538
* Establishes a connection to the ZooKeeper server.
2639
*
@@ -51,6 +64,10 @@ class ZookeeperManager extends EventEmitter {
5164
async.series([
5265
// Check zookeeper client is connected
5366
next => this.client.once('connected', next),
67+
next => {
68+
this.log.info('connected to zookeeper', { zk: this.zkDetails(this.client) });
69+
next();
70+
},
5471
// Create namespace if it exists and options.autoCreateNamespace is true
5572
next => {
5673
// TODO: ARTESCA-10337 The 'autoCreateNamespace' functionality is currently specific to
@@ -82,7 +99,12 @@ class ZookeeperManager extends EventEmitter {
8299
const hostPort = this.connectionString.slice(0, nsIndex);
83100
rootZkClient = zookeeper.createClient(hostPort, this.options);
84101
rootZkClient.connect();
85-
rootZkClient.once('connected', () => next());
102+
rootZkClient.once('connected', () => {
103+
this.log.info('connected to root zookeeper', {
104+
zk: this.zkDetails(rootZkClient),
105+
});
106+
next();
107+
});
86108
},
87109
// Once connected, use the root zookeeper client to create the namespace
88110
next => rootZkClient.mkdirp(namespace, err => {
@@ -99,15 +121,17 @@ class ZookeeperManager extends EventEmitter {
99121
this.client.once('expired', () => {
100122
this.log.info('zookeeper client expired', {
101123
method: 'ZookeeperManager.once.expired',
124+
zk: this.zkDetails(this.client),
102125
});
103126
// establish a new session with the ZooKeeper.
104127
this._connect();
105128
});
106129

107130
this.client.on('state', state => {
108-
this.log.debug('zookeeper new state', {
131+
this.log.info('zookeeper new state', {
109132
state,
110133
method: 'ZookeeperManager.on.state',
134+
zk: this.zkDetails(this.client),
111135
});
112136
});
113137

@@ -131,6 +155,7 @@ class ZookeeperManager extends EventEmitter {
131155
* @return {undefined}
132156
*/
133157
close() {
158+
this.log.info('closing existing zookeeper client', { zk: this.zkDetails(this.client) });
134159
this.client.close();
135160
return;
136161
}

tests/unit/clients/ZookeeperManager.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ describe('ZookeeperManager', () => {
1212
beforeEach(() => {
1313
// Create a mock client
1414
mockClient = {
15+
connectionManager: {
16+
socket: {
17+
address: () => ({ address: '127.0.0.1', port: 42000 }),
18+
},
19+
xid: 1,
20+
zxid: Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0xFF]),
21+
nextServerIndex: 1,
22+
serverAttempts: 1,
23+
},
24+
getSessionId: () => Buffer.from([0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88]),
25+
getState: () => ({ name: 'SYNC_CONNECTED', code: 3 }),
1526
on: sinon.stub(),
1627
once: sinon.stub(),
1728
connect: sinon.stub(),

0 commit comments

Comments
 (0)