Skip to content

Commit 44084e6

Browse files
committed
CLDSRV-838: Change startTime type to ms since epoch
1 parent 6739c34 commit 44084e6

3 files changed

Lines changed: 4 additions & 57 deletions

File tree

lib/utilities/serverAccessLogger.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,6 @@ function calculateElapsedMS(startTime, onCloseEndTime) {
382382
return Number(onCloseEndTime - startTime) / 1_000_000;
383383
}
384384

385-
function timestampToDateTime643(unixMS) {
386-
if (unixMS === undefined || unixMS === null) {
387-
return null;
388-
}
389-
390-
// clickhouse DateTime64(3) expects "seconds.milliseconds" (string type).
391-
return (unixMS / 1000).toFixed(3);
392-
}
393-
394385
function logServerAccess(req, res) {
395386
if (!req.serverAccessLog || !res.serverAccessLog || !serverAccessLogger) {
396387
return;
@@ -425,7 +416,7 @@ function logServerAccess(req, res) {
425416
elapsed_ms: calculateElapsedMS(params.startTime, params.onCloseEndTime) ?? undefined,
426417
427418
// AWS access server logs fields https://docs.aws.amazon.com/AmazonS3/latest/userguide/LogFormat.html
428-
startTime: timestampToDateTime643(params.startTimeUnixMS) ?? undefined, // AWS "Time" field
419+
startTime: params.startTimeUnixMS ?? undefined, // AWS "Time" field - milliseconds since epoch
429420
requester: getRequester(authInfo) ?? undefined,
430421
operation: getOperation(req),
431422
requestURI: getURI(req) ?? undefined,
@@ -483,5 +474,4 @@ module.exports = {
483474
getBytesSent,
484475
calculateTotalTime,
485476
calculateTurnAroundTime,
486-
timestampToDateTime643,
487477
};

schema/server_access_log.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
"minimum": 0
6363
},
6464
"startTime": {
65-
"description": "Timestamp formatted as: 'seconds.milliseconds', recorded when the server first routes the request. Represents the AWS server access log 'Time' field. String type compatible with Clickhouse DateTime64(3) type.",
66-
"type": "string"
65+
"description": "Milliseconds since Unix epoch, recorded when the server first routes the request. Represents the AWS server access log 'Time' field.",
66+
"type": "number"
6767
},
6868
"requester": {
6969
"description": "AWS server access log 'Requester' field. From AWS 'The canonical user ID of the requester, or a - for unauthenticated requests. If the requester was an IAM user, this field returns the requester's IAM user name along with the AWS account that the IAM user belongs to. This identifier is the same one used for access control purposes.'. We don't use null instead of '-' when the requester is missing.",

tests/unit/utils/serverAccessLogger.js

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const {
1111
getBytesSent,
1212
calculateTotalTime,
1313
calculateTurnAroundTime,
14-
timestampToDateTime643,
1514
} = require('../../../lib/utilities/serverAccessLogger');
1615

1716
describe('serverAccessLogger utility functions', () => {
@@ -618,48 +617,6 @@ describe('serverAccessLogger utility functions', () => {
618617
});
619618
});
620619

621-
describe('timestampToDateTime643', () => {
622-
it('should convert milliseconds to seconds with 3 decimal places', () => {
623-
const startTimeUnixMS = 1234567890000;
624-
const result = timestampToDateTime643(startTimeUnixMS);
625-
assert.strictEqual(result, '1234567890.000');
626-
});
627-
628-
it('should handle timestamp with milliseconds', () => {
629-
const startTimeUnixMS = 1234567890123;
630-
const result = timestampToDateTime643(startTimeUnixMS);
631-
assert.strictEqual(result, '1234567890.123');
632-
});
633-
634-
it('should handle 0', () => {
635-
const startTimeUnixMS = 0;
636-
const result = timestampToDateTime643(startTimeUnixMS);
637-
assert.strictEqual(result, '0.000');
638-
});
639-
640-
it('should return null when startTimeUnixMS is null', () => {
641-
const result = timestampToDateTime643(null);
642-
assert.strictEqual(result, null);
643-
});
644-
645-
it('should return null when startTimeUnixMS is undefined', () => {
646-
const result = timestampToDateTime643(undefined);
647-
assert.strictEqual(result, null);
648-
});
649-
650-
it('should handle small timestamps', () => {
651-
const startTimeUnixMS = 1000;
652-
const result = timestampToDateTime643(startTimeUnixMS);
653-
assert.strictEqual(result, '1.000');
654-
});
655-
656-
it('should handle timestamps with partial milliseconds', () => {
657-
const startTimeUnixMS = 1500;
658-
const result = timestampToDateTime643(startTimeUnixMS);
659-
assert.strictEqual(result, '1.500');
660-
});
661-
});
662-
663620
describe('logServerAccess', () => {
664621
let mockLogger;
665622
let sandbox;
@@ -812,7 +769,7 @@ describe('serverAccessLogger utility functions', () => {
812769
assert.strictEqual(loggedData.elapsed_ms, 20.5);
813770

814771
// Verify AWS access server log fields
815-
assert.strictEqual(loggedData.startTime, '1234567890.000');
772+
assert.strictEqual(loggedData.startTime, 1234567890000);
816773
assert.strictEqual(loggedData.requester, 'canonical123');
817774
assert.strictEqual(loggedData.operation, 'REST.GET.OBJECT');
818775
assert.strictEqual(loggedData.requestURI, 'GET /test-bucket/test-key.txt HTTP/1.1');

0 commit comments

Comments
 (0)