Skip to content

Commit b587ff8

Browse files
committed
CLDSRV-894: report turn-around time for PutObject and UploadPart
objectPut and objectPutPart return early from the request processing waterfall in api.js, skipping the request 'end' handler that sets startTurnAroundTime. Add the listener before the early return so the timestamp is captured when the last byte of the request body arrives.
1 parent 029b436 commit b587ff8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/api/api.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ const api = {
263263
request.serverAccessLog.analyticsUserName = authNames.userName;
264264
}
265265
if (apiMethod === 'objectPut' || apiMethod === 'objectPutPart') {
266+
request.on('end', () => {
267+
if (request.serverAccessLog) {
268+
request.serverAccessLog.startTurnAroundTime = process.hrtime.bigint();
269+
}
270+
});
266271
return next(null, userInfo, authorizationResults, streamingV4Params, infos);
267272
}
268273
// issue 100 Continue to the client

tests/unit/api/api.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,25 @@ describe('api.callApiMethod', () => {
115115
api.callApiMethod('multipartDelete', request, response, log);
116116
});
117117

118+
['objectPut', 'objectPutPart'].forEach(method => {
119+
it(`should set startTurnAroundTime on request end for ${method}`, done => {
120+
sandbox.stub(api, method).callsFake(
121+
(userInfo, _request, streamingV4Params, _log, cb) => {
122+
request.on('end', () => {
123+
assert.strictEqual(typeof request.serverAccessLog.startTurnAroundTime, 'bigint');
124+
cb();
125+
});
126+
request.resume();
127+
});
128+
request.objectKey = 'testobject';
129+
request.serverAccessLog = {};
130+
api.callApiMethod(method, request, response, log, err => {
131+
assert.ifError(err);
132+
done();
133+
});
134+
});
135+
});
136+
118137
describe('MD5 checksum validation', () => {
119138
const methodsWithChecksumValidation = [
120139
'bucketPutACL',

0 commit comments

Comments
 (0)