Skip to content

Commit f624bb7

Browse files
committed
Merge branch 'w/9.3/bugfix/CLDSRV-894-turnaround-time-put-operations' into tmp/octopus/w/9.4/bugfix/CLDSRV-894-turnaround-time-put-operations
2 parents c59fbb5 + 8021753 commit f624bb7

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
@@ -264,6 +264,19 @@ const api = {
264264
request.serverAccessLog.analyticsUserName = authNames.userName;
265265
}
266266
if (apiMethod === 'objectPut' || apiMethod === 'objectPutPart') {
267+
const setStartTurnAroundTime = () => {
268+
if (request.serverAccessLog) {
269+
request.serverAccessLog.startTurnAroundTime = process.hrtime.bigint();
270+
}
271+
};
272+
// For 0-byte uploads, downstream handlers do not consume
273+
// the request stream, so 'end' never fires. Set
274+
// startTurnAroundTime synchronously in that case.
275+
if (request.headers['content-length'] === '0') {
276+
setStartTurnAroundTime();
277+
} else {
278+
request.on('end', setStartTurnAroundTime);
279+
}
267280
return next(null, userInfo, authorizationResults, streamingV4Params, infos);
268281
}
269282
// 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)