MCPcopy Index your code
hub / github.com/scality/cloudserver / logServerAccess

Function logServerAccess

lib/utilities/serverAccessLogger.js:588–691  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

586}
587
588function logServerAccess(req, res) {
589 if (!req.serverAccessLog || !res.serverAccessLog || !serverAccessLogger) {
590 return;
591 }
592
593 const params = req.serverAccessLog;
594 const errorCode = res.serverAccessLog.errorCode;
595 const endTurnAroundTime = res.serverAccessLog.endTurnAroundTime;
596 const requestID = res.serverAccessLog.requestID;
597 const bytesSent = res.serverAccessLog.bytesSent;
598
599 const logEntry = buildLogEntry(req, params, {
600 bytesDeleted: params.analyticsBytesDeleted,
601 bytesReceived: Number.isInteger(req.parsedContentLength) ? req.parsedContentLength : undefined,
602 bodyLength: req.headers['content-length'] !== undefined
603 ? parseInt(req.headers['content-length'], 10)
604 : undefined,
605 contentLength: getObjectSize(req, res),
606 // eslint-disable-next-line camelcase
607 elapsed_ms: calculateElapsedMS(params.startTime, params.onCloseEndTime),
608 operation: getOperation(req),
609 requestURI: getURI(req),
610 errorCode,
611 objectSize: params.objectSize ?? getObjectSize(req, res),
612 totalTime: calculateTotalTime(params.startTime, params.onFinishEndTime),
613 turnAroundTime: calculateTurnAroundTime(params.startTurnAroundTime, endTurnAroundTime),
614 versionId: req.query?.versionId,
615 aclRequired: req.serverAccessLog.aclRequired,
616 referer: req.headers?.referer,
617 userAgent: req.headers?.['user-agent'],
618 requestID,
619 bytesSent: getBytesSent(res, bytesSent),
620 httpCode: res.statusCode,
621 objectKey: params.objectKey,
622 });
623
624 // Lifecycle expiration is an internal operation.
625 // Null out HTTP-layer fields to match AWS access log format.
626 if (params.expiration) {
627 logEntry.requester = 'ScalityS3LifecycleService';
628 logEntry.clientIP = undefined;
629 logEntry.requestURI = undefined;
630 logEntry.httpCode = undefined;
631 logEntry.bytesSent = undefined;
632 logEntry.totalTime = undefined;
633 logEntry.turnAroundTime = undefined;
634 logEntry.signatureVersion = undefined;
635 logEntry.cipherSuite = undefined;
636 logEntry.authenticationType = undefined;
637 logEntry.hostHeader = undefined;
638 logEntry.tlsVersion = undefined;
639 logEntry.referer = undefined;
640 logEntry.userAgent = undefined;
641 logEntry.versionId = undefined;
642 logEntry.awsAccessKeyID = undefined;
643 }
644
645 // Match AWS log shape for replication entries: blank clientIP, userAgent

Callers 2

monitorEndOfRequestMethod · 0.85

Calls 11

buildLogEntryFunction · 0.85
getObjectSizeFunction · 0.85
calculateElapsedMSFunction · 0.85
getOperationFunction · 0.85
getURIFunction · 0.85
calculateTotalTimeFunction · 0.85
calculateTurnAroundTimeFunction · 0.85
getBytesSentFunction · 0.85
logBatchDeleteObjectFunction · 0.85
logCopySourceAccessFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected