Skip to content

Commit 6993233

Browse files
committed
CLDSRV-827: Fix contentLength and objectSize in access logs
Fix contentLength to capture actual transfer size (egress for GET, ingress for PUT) instead of always using request body size. This restores backwards compatibility with S3 analytics. Fix objectSize to always reflect full object size by passing metadata from objectGet, preventing partial sizes in range get.
1 parent 23e383a commit 6993233

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

lib/api/objectGet.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ function objectGet(authInfo, request, returnTagCount, log, callback) {
139139

140140
const objLength = (objMD.location === null ?
141141
0 : parseInt(objMD['content-length'], 10));
142+
// Store full object size for server access logs
143+
if (request.serverAccessLog) {
144+
// eslint-disable-next-line no-param-reassign
145+
request.serverAccessLog.objectSize = objLength;
146+
}
142147
let byteRange;
143148
const streamingParams = {};
144149
if (request.headers.range) {

lib/utilities/serverAccessLogger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ function logServerAccess(req, res) {
420420
bodyLength: req.headers['content-length'] !== undefined
421421
? parseInt(req.headers['content-length'], 10)
422422
: undefined,
423-
contentLength: Number.isInteger(req.parsedContentLength) ? req.parsedContentLength : undefined,
423+
contentLength: getObjectSize(req, res) ?? undefined,
424424
// eslint-disable-next-line camelcase
425425
elapsed_ms: calculateElapsedMS(params.startTime, params.onCloseEndTime) ?? undefined,
426426
@@ -430,7 +430,7 @@ function logServerAccess(req, res) {
430430
operation: getOperation(req),
431431
requestURI: getURI(req) ?? undefined,
432432
errorCode: errorCode ?? undefined,
433-
objectSize: getObjectSize(req, res) ?? undefined,
433+
objectSize: params.objectSize ?? getObjectSize(req, res) ?? undefined,
434434
totalTime: calculateTotalTime(params.startTime, params.onFinishEndTime) ?? undefined,
435435
turnAroundTime: calculateTurnAroundTime(params.startTurnAroundTime, endTurnAroundTime) ?? undefined,
436436
referer: req.headers.referer ?? undefined,

tests/unit/utils/serverAccessLogger.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ describe('serverAccessLogger utility functions', () => {
808808
assert.strictEqual(loggedData.bytesDeleted, 0);
809809
assert.strictEqual(loggedData.bytesReceived, 1024);
810810
assert.strictEqual(loggedData.bodyLength, 1024);
811-
assert.strictEqual(loggedData.contentLength, 1024);
811+
assert.strictEqual(loggedData.contentLength, 2048);
812812
assert.strictEqual(loggedData.elapsed_ms, 20.5);
813813

814814
// Verify AWS access server log fields
@@ -1054,6 +1054,7 @@ describe('serverAccessLogger utility functions', () => {
10541054
serverAccessLog: {
10551055
analyticsBytesDeleted: 0,
10561056
},
1057+
apiMethod: 'objectPut',
10571058
headers: { 'content-length': '0' },
10581059
parsedContentLength: 0,
10591060
socket: {},

0 commit comments

Comments
 (0)