Skip to content

Commit e30397b

Browse files
committed
CLDSRV-894: Report turn-around time for PutObject and UploadPart
Server access logs did not report turn-around time for PutObject and UploadPart while all other operations reported it correctly. AWS reports turn-around time for these operations. (cherry picked from commit 314ba8c)
1 parent 6ac8392 commit e30397b

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/api/api.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ const api = {
263263
request.serverAccessLog.analyticsUserName = authNames.userName;
264264
}
265265
if (apiMethod === 'objectPut' || apiMethod === 'objectPutPart') {
266+
const setStartTurnAroundTime = () => {
267+
if (request.serverAccessLog) {
268+
request.serverAccessLog.startTurnAroundTime = process.hrtime.bigint();
269+
}
270+
};
271+
// For 0-byte uploads, downstream handlers do not consume
272+
// the request stream, so 'end' never fires. Set
273+
// startTurnAroundTime synchronously in that case.
274+
if (request.headers['content-length'] === '0') {
275+
setStartTurnAroundTime();
276+
} else {
277+
request.on('end', setStartTurnAroundTime);
278+
}
266279
return next(null, userInfo, authorizationResults, streamingV4Params, infos);
267280
}
268281
// issue 100 Continue to the client

tests/unit/api/api.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,40 @@ 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+
it(`should set startTurnAroundTime synchronously for 0-byte ${method}`, done => {
137+
sandbox.stub(api, method).callsFake(
138+
(userInfo, _request, streamingV4Params, _log, cb) => {
139+
assert.strictEqual(typeof request.serverAccessLog.startTurnAroundTime, 'bigint');
140+
cb();
141+
});
142+
request.objectKey = 'testobject';
143+
request.serverAccessLog = {};
144+
request.headers = Object.assign({}, request.headers, { 'content-length': '0' });
145+
api.callApiMethod(method, request, response, log, err => {
146+
assert.ifError(err);
147+
done();
148+
});
149+
});
150+
});
151+
118152
describe('MD5 checksum validation', () => {
119153
const methodsWithChecksumValidation = [
120154
'bucketPutACL',

0 commit comments

Comments
 (0)