Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 5f726e5

Browse files
author
Dave Kelsey
authored
[Master] Improve perf logging (#4495)
* Log connect/disconnect, improve query perf log Signed-off-by: Dave Kelsey <d_kelsey@uk.ibm.com> * Improvements based on example Signed-off-by: Dave Kelsey <d_kelsey@uk.ibm.com>
1 parent 5f63223 commit 5f726e5

File tree

6 files changed

+53
-9
lines changed

6 files changed

+53
-9
lines changed

packages/composer-connector-hlfv1/lib/hlfconnection.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ class HLFConnection extends Connection {
102102
// don't log the client, channel, caClient objects here they're too big
103103
LOG.entry(method, connectionManager, connectionProfile, businessNetworkIdentifier, connectOptions);
104104

105+
if (this.businessNetworkIdentifier) {
106+
LOG.info(method, `Creating a connection using profile ${connectionProfile} to network ${businessNetworkIdentifier}`);
107+
} else {
108+
LOG.info(method, `Creating a connection using profile ${connectionProfile} to fabric (no business network)`);
109+
}
110+
105111
// Validate all the arguments.
106112
if (!connectOptions) {
107113
throw new Error('connectOptions not specified');
@@ -141,6 +147,11 @@ class HLFConnection extends Connection {
141147
disconnect() {
142148
const method = 'disconnect';
143149
LOG.entry(method);
150+
if (this.businessNetworkIdentifier) {
151+
LOG.info(method, `Disconnecting the connection to ${this.businessNetworkIdentifier}`);
152+
} else {
153+
LOG.info(method, 'Disconnecting the connection to fabric (no business network)');
154+
}
144155

145156
if (this.exitListener) {
146157
process.removeListener('exit', this.exitListener);
@@ -922,7 +933,11 @@ class HLFConnection extends Connection {
922933
let txId = this.client.newTransactionID();
923934

924935
const t0 = Date.now();
936+
LOG.perf(method, `start of querying chaincode ${functionName}(${args})`, txId, t0);
937+
925938
let result = await this.queryHandler.queryChaincode(txId, functionName, args);
939+
940+
// need to know which query was executed, otherwise just need to know which function was executed.
926941
LOG.perf(method, `Total duration for queryChaincode to ${functionName}: `, txId, t0);
927942
LOG.exit(method, result ? result : null);
928943
return result ? result : null;
@@ -978,8 +993,8 @@ class HLFConnection extends Connection {
978993

979994
let eventHandler;
980995
let validResponses;
981-
982996
let t0 = Date.now();
997+
LOG.perf(method, `start of chaincode invocation ${functionName}(${args})`, txId, t0);
983998
try {
984999
LOG.debug(method, 'checking the event hub strategy');
9851000
await this._checkEventHubStrategy();
@@ -1000,7 +1015,7 @@ class HLFConnection extends Connection {
10001015
fcn: functionName,
10011016
args: args
10021017
};
1003-
LOG.perf(method, 'Total duration to initialize channel: ', txId, t0);
1018+
LOG.perf(method, 'Total duration to initialize: ', txId, t0);
10041019
t0 = Date.now();
10051020

10061021
let results;

packages/composer-connector-hlfv1/lib/hlfqueryhandler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ class HLFQueryHandler {
139139
args: args
140140
};
141141

142+
const t0 = Date.now();
142143
let payloads = await this.connection.channel.queryByChaincode(request);
144+
LOG.perf(method, `Total duration for node-sdk queryByChaincode to ${functionName}: `, txId, t0);
143145
LOG.debug(method, `Received ${payloads.length} payloads(s) from querying the composer runtime chaincode`);
144146
if (!payloads.length) {
145147
LOG.error(method, 'No payloads were returned from the query request:' + functionName);

packages/composer-connector-hlfv1/lib/hlftxeventhandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ class HLFTxEventHandler {
120120
LOG.error(method, msg);
121121
throw Error(msg);
122122
}
123-
LOG.exit(method);
123+
} else {
124+
LOG.warn(method, `No event hubs available to listen on to wait for a commit for transaction '${this.txId}'`);
124125
}
125-
LOG.warn(method, `No event hubs available to listen on to wait for a commit for transaction '${this.txId}'`);
126126
LOG.exit(method);
127127
}
128128

packages/composer-connector-hlfv1/test/hlfconnection.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ describe('HLFConnection', () => {
5656
let mockPeer1, mockPeer2, mockPeer3, mockEventHub1, mockEventHub2, mockEventHub3, mockQueryHandler;
5757
let connectOptions;
5858
let connection;
59-
let mockTransactionID, logWarnSpy, logErrorSpy;
59+
let mockTransactionID, logWarnSpy, logErrorSpy, logInfoSpy, LOG;
6060

6161
beforeEach(() => {
6262
sandbox = sinon.sandbox.create();
6363
clock = sinon.useFakeTimers();
64-
const LOG = Logger.getLog('HLFConnection');
64+
LOG = Logger.getLog('HLFConnection');
6565
logWarnSpy = sandbox.spy(LOG, 'warn');
6666
logErrorSpy = sandbox.spy(LOG, 'error');
6767
mockConnectionManager = sinon.createStubInstance(HLFConnectionManager);
@@ -194,6 +194,18 @@ describe('HLFConnection', () => {
194194
connection = new HLFConnection(mockConnectionManager, 'hlfabric1', mockBusinessNetwork.getName(), {'x-requiredEventHubs': 'fred'}, mockClient, mockChannel, mockCAClient);
195195
connection.requiredEventHubs.should.equal(1);
196196
});
197+
198+
it('should log at info a fabric level connection being created', () => {
199+
logInfoSpy = sandbox.spy(LOG, 'info');
200+
connection = new HLFConnection(mockConnectionManager, 'hlfabric1', null, {'x-requiredEventHubs': 'fred'}, mockClient, mockChannel, mockCAClient);
201+
sinon.assert.calledWith(logInfoSpy, 'constructor', sinon.match(/no business network/));
202+
});
203+
204+
it('should log at info a business network level connection being created', () => {
205+
logInfoSpy = sandbox.spy(LOG, 'info');
206+
connection = new HLFConnection(mockConnectionManager, 'hlfabric1', 'test-business-network', {'x-requiredEventHubs': 'fred'}, mockClient, mockChannel, mockCAClient);
207+
sinon.assert.calledWith(logInfoSpy, 'constructor', sinon.match(/test-business-network/));
208+
});
197209
});
198210

199211
describe('#_connectToEventHubs', () => {
@@ -638,6 +650,20 @@ describe('HLFConnection', () => {
638650
sinon.assert.calledTwice(connection._disconnect);
639651
});
640652

653+
it('should log at info a fabric level connection being disconnected', () => {
654+
logInfoSpy = sandbox.spy(LOG, 'info');
655+
connection = new HLFConnection(mockConnectionManager, 'hlfabric1', null, {'x-requiredEventHubs': 'fred'}, mockClient, mockChannel, mockCAClient);
656+
connection.disconnect();
657+
sinon.assert.calledWith(logInfoSpy.secondCall, 'disconnect', sinon.match(/no business network/));
658+
});
659+
660+
it('should log at info a business network level connection being created', () => {
661+
logInfoSpy = sandbox.spy(LOG, 'info');
662+
connection = new HLFConnection(mockConnectionManager, 'hlfabric1', 'test-business-network', {'x-requiredEventHubs': 'fred'}, mockClient, mockChannel, mockCAClient);
663+
connection.disconnect();
664+
sinon.assert.calledWith(logInfoSpy.secondCall, 'disconnect', sinon.match(/test-business-network/));
665+
});
666+
641667
});
642668

643669
describe('#_disconnect', () => {

packages/composer-connector-hlfv1/test/hlfqueryhandler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('HLFQueryHandler', () => {
4646
mockPeer3.index = 3;
4747
mockConnection = sinon.createStubInstance(HLFConnection);
4848
mockTransactionID = sinon.createStubInstance(TransactionID);
49+
mockTransactionID.getTransactionID.returns('0987654321');
4950
mockChannel = sinon.createStubInstance(Channel);
5051
mockConnection.channel = mockChannel;
5152
mockConnection.getChannelPeersInOrg.withArgs([FABRIC_CONSTANTS.NetworkConfig.CHAINCODE_QUERY_ROLE]).returns([mockPeer2, mockPeer1, mockPeer3]);

packages/composer-connector-hlfv1/test/hlftxeventhandler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ describe('HLFTxEventHandler', () => {
175175
});
176176
});
177177

178-
it('Should handle a transaction listener error response all event hubs and event hubs required', async () => {
178+
it('Should handle a transaction listener error response from all event hubs and event hubs required', async () => {
179179
sandbox.stub(global, 'setTimeout');
180180
sandbox.stub(global, 'clearTimeout');
181181
const ehc = sandbox.stub(HLFUtil, 'eventHubConnected');
@@ -194,7 +194,7 @@ describe('HLFTxEventHandler', () => {
194194
sinon.assert.calledTwice(logWarnSpy);
195195
});
196196

197-
it('Should handle a transaction listener error response all event hubs but no event hubs required', async () => {
197+
it('Should handle a transaction listener error response from all event hubs but no event hubs required', async () => {
198198
sandbox.stub(global, 'setTimeout');
199199
sandbox.stub(global, 'clearTimeout');
200200
const ehc = sandbox.stub(HLFUtil, 'eventHubConnected');
@@ -214,7 +214,7 @@ describe('HLFTxEventHandler', () => {
214214
} catch(err) {
215215
should.fail(null,null,`${err} unexpected`);
216216
}
217-
sinon.assert.calledThrice(logWarnSpy);
217+
sinon.assert.calledTwice(logWarnSpy);
218218
});
219219

220220
it('Should handle a transaction listener error response on one but not all of the event hubs', async () => {

0 commit comments

Comments
 (0)