Skip to content

Commit 892f431

Browse files
ARSN-479: Add details about kmip in logs
Log the host for multi ip Log the latency for support to notice slow KMS problem Log the operation and the success of kmip request to know latency and host
1 parent 3f88ac6 commit 892f431

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

lib/network/kmip/Client.ts

+39-11
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const searchFilter = {
5454
* @param cb - The callback triggered after the negotiation.
5555
*/
5656
function _negotiateProtocolVersion(client: any, logger: werelogs.Logger, cb: any) {
57+
const startDate = Date.now();
5758
return client.kmip.request(logger, 'Discover Versions', [
5859
KMIP.Structure('Protocol Version', [
5960
KMIP.Integer('Protocol Version Major', 1),
@@ -68,10 +69,14 @@ function _negotiateProtocolVersion(client: any, logger: werelogs.Logger, cb: any
6869
KMIP.Integer('Protocol Version Minor', 2),
6970
]),
7071
], (err, response) => {
72+
const kmipLog = {
73+
host: client.host,
74+
latencyMs: Date.now() - startDate
75+
};
7176
if (err) {
7277
const error = arsenalErrorKMIP(err);
7378
logger.error('KMIP::negotiateProtocolVersion',
74-
{ error,
79+
{ error, kmip: kmipLog,
7580
vendorIdentification: client.vendorIdentification });
7681
return cb(error);
7782
}
@@ -83,7 +88,7 @@ function _negotiateProtocolVersion(client: any, logger: werelogs.Logger, cb: any
8388
majorVersions.length !== minorVersions.length) {
8489
const error = arsenalErrorKMIP('No suitable protocol version');
8590
logger.error('KMIP::negotiateProtocolVersion',
86-
{ error,
91+
{ error, kmip: kmipLog,
8792
vendorIdentification: client.vendorIdentification });
8893
return cb(error);
8994
}
@@ -100,13 +105,18 @@ function _negotiateProtocolVersion(client: any, logger: werelogs.Logger, cb: any
100105
* @param cb - The callback triggered after the extension mapping
101106
*/
102107
function _mapExtensions(client: any, logger: werelogs.Logger, cb: any) {
108+
const startDate = Date.now();
103109
return client.kmip.request(logger, 'Query', [
104110
KMIP.Enumeration('Query Function', 'Query Extension Map'),
105111
], (err, response) => {
112+
const kmipLog = {
113+
host: client.host,
114+
latencyMs: Date.now() - startDate
115+
};
106116
if (err) {
107117
const error = arsenalErrorKMIP(err);
108118
logger.error('KMIP::mapExtensions',
109-
{ error,
119+
{ error, kmip: kmipLog,
110120
vendorIdentification: client.vendorIdentification });
111121
return cb(error);
112122
}
@@ -115,7 +125,7 @@ function _mapExtensions(client: any, logger: werelogs.Logger, cb: any) {
115125
if (extensionNames.length !== extensionTags.length) {
116126
const error = arsenalErrorKMIP('Inconsistent extension list');
117127
logger.error('KMIP::mapExtensions',
118-
{ error,
128+
{ error, kmip: kmipLog,
119129
vendorIdentification: client.vendorIdentification });
120130
return cb(error);
121131
}
@@ -133,13 +143,18 @@ function _mapExtensions(client: any, logger: werelogs.Logger, cb: any) {
133143
* @param cb - The callback triggered after the information discovery
134144
*/
135145
function _queryServerInformation(client: any, logger: werelogs.Logger, cb: any) {
146+
const startDate = Date.now();
136147
client.kmip.request(logger, 'Query', [
137148
KMIP.Enumeration('Query Function', 'Query Server Information'),
138149
], (err, response) => {
150+
const kmipLog = {
151+
host: client.host,
152+
latencyMs: Date.now() - startDate
153+
};
139154
if (err) {
140155
const error = arsenalErrorKMIP(err);
141156
logger.warn('KMIP::queryServerInformation',
142-
{ error });
157+
{ error, kmip: kmipLog });
143158
/* no error returned, caller can keep going */
144159
return cb();
145160
}
@@ -151,7 +166,8 @@ function _queryServerInformation(client: any, logger: werelogs.Logger, cb: any)
151166
logger.info('KMIP Server identified',
152167
{ vendorIdentification: client.vendorIdentification,
153168
serverInformation: client.serverInformation,
154-
negotiatedProtocolVersion: client.kmip.protocolVersion });
169+
negotiatedProtocolVersion: client.kmip.protocolVersion,
170+
kmip: kmipLog });
155171
return cb();
156172
});
157173
}
@@ -167,14 +183,19 @@ function _queryServerInformation(client: any, logger: werelogs.Logger, cb: any)
167183
* @param cb - The callback triggered after the information discovery
168184
*/
169185
function _queryOperationsAndObjects(client: any, logger: werelogs.Logger, cb: any) {
186+
const startDate = Date.now();
170187
return client.kmip.request(logger, 'Query', [
171188
KMIP.Enumeration('Query Function', 'Query Operations'),
172189
KMIP.Enumeration('Query Function', 'Query Objects'),
173190
], (err, response) => {
191+
const kmipLog = {
192+
host: client.host,
193+
latencyMs: Date.now() - startDate
194+
};
174195
if (err) {
175196
const error = arsenalErrorKMIP(err);
176197
logger.error('KMIP::queryOperationsAndObjects',
177-
{ error,
198+
{ error, kmip: kmipLog,
178199
vendorIdentification: client.vendorIdentification });
179200
return cb(error);
180201
}
@@ -205,10 +226,12 @@ function _queryOperationsAndObjects(client: any, logger: werelogs.Logger, cb: an
205226
supportsEncrypt, supportsDecrypt,
206227
supportsActivate, supportsRevoke,
207228
supportsCreate, supportsDestroy,
208-
supportsQuery, supportsSymmetricKeys });
229+
supportsQuery, supportsSymmetricKeys,
230+
kmip: kmipLog });
209231
} else {
210232
logger.info('KMIP Server provides the necessary feature set',
211-
{ vendorIdentification: client.vendorIdentification });
233+
{ vendorIdentification: client.vendorIdentification,
234+
kmip: kmipLog });
212235
}
213236
return cb();
214237
});
@@ -219,6 +242,7 @@ export default class Client implements KMSInterface {
219242
vendorIdentification: string;
220243
serverInformation: any[];
221244
kmip: KMIP;
245+
host: string;
222246

223247
/**
224248
* Construct a high level KMIP driver suitable for cloudserver
@@ -255,6 +279,7 @@ export default class Client implements KMSInterface {
255279
CodecClass: any,
256280
TransportClass: any,
257281
) {
282+
this.host = options.kmip.transport.tls.host;
258283
this.options = options.kmip.client || {};
259284
this.vendorIdentification = '';
260285
this.serverInformation = [];
@@ -567,20 +592,23 @@ export default class Client implements KMSInterface {
567592
}
568593

569594
healthcheck(logger, cb) {
595+
const kmipLog = { host: this.host };
570596
// the bucket does not have to exist, just passing a common bucket name here
571597
this.createBucketKey('kmip-healthcheck-test-bucket', logger, (err, bucketKeyId) => {
572598
if (err) {
573599
logger.error('KMIP::healthcheck: failure to create a test bucket key', {
574-
error: err,
600+
error: err, kmip: kmipLog,
575601
});
576602
return cb(err);
577603
}
578-
logger.debug('KMIP::healthcheck: success creating a test bucket key');
604+
logger.debug('KMIP::healthcheck: success creating a test bucket key',
605+
{ kmip: kmipLog });
579606
this.destroyBucketKey(bucketKeyId, logger, err => {
580607
if (err) {
581608
logger.error('KMIP::healthcheck: failure to remove the test bucket key', {
582609
bucketKeyId,
583610
error: err,
611+
kmip: kmipLog,
584612
});
585613
}
586614
});

lib/network/kmip/index.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,18 @@ export default class KMIP {
303303
KMIP.Structure('Request Payload', payload),
304304
])])]);
305305
const encodedMessage = this._encodeMessage(message);
306+
const startDate = Date.now();
306307
this.transport.send(
307308
logger, encodedMessage,
308309
(err, conversation, rawResponse) => {
310+
const kmipLog = {
311+
host: this.options.transport.tls.host,
312+
latencyMs: Date.now() - startDate,
313+
op: operation,
314+
};
309315
if (err) {
310316
logger.error('KMIP::request: Failed to send message',
311-
{ error: err });
317+
{ error: err, kmip: kmipLog });
312318
return cb(err);
313319
}
314320
const response = this._decodeMessage(logger, rawResponse);
@@ -327,7 +333,7 @@ export default class KMIP {
327333
this.transport.abortPipeline(conversation);
328334
const error = Error('Invalid batch item ID returned');
329335
logger.error('KMIP::request: failed',
330-
{ resultUniqueBatchItemID, uuid, error });
336+
{ resultUniqueBatchItemID, uuid, error, kmip: kmipLog });
331337
return cb(error);
332338
}
333339
if (performedOperation !== operation) {
@@ -338,7 +344,7 @@ export default class KMIP {
338344
{ got: performedOperation,
339345
expected: operation });
340346
logger.error('KMIP::request: Operation mismatch',
341-
{ error });
347+
{ error, kmip: kmipLog });
342348
return cb(error);
343349
}
344350
if (resultStatus !== 'Success') {
@@ -356,9 +362,10 @@ export default class KMIP {
356362
resultMessage });
357363
logger.error('KMIP::request: request failed',
358364
{ error, resultStatus,
359-
resultReason, resultMessage });
365+
resultReason, resultMessage, kmip: kmipLog });
360366
return cb(error);
361367
}
368+
logger.info('KMIP::success', { kmip: kmipLog });
362369
return cb(null, response);
363370
});
364371
}

0 commit comments

Comments
 (0)