Skip to content

Instantly share code, notes, and snippets.

@rodolfo42
Last active April 12, 2017 15:00
Show Gist options
  • Save rodolfo42/7ea3b919eb04fe551f1c54831f7819b7 to your computer and use it in GitHub Desktop.
Save rodolfo42/7ea3b919eb04fe551f1c54831f7819b7 to your computer and use it in GitHub Desktop.
Yield differences in parsing dates from log vs event log timestamp
const moment = require('moment');
const format1 = require('./format1_log_events.json');
const format2 = require('./format2_log_events.json');
const events = {
format1,
format2
};
const allDiffs = Object.keys(events).map(key => ({ key, events: events[key] })).map(stream => {
const logStream = stream.key;
const diffs = stream.events.map((event) => {
let ingestionTime = moment(event.ingestionTime);
let timestamp = moment(event.timestamp);
let dateStr = event.message.split('"')[1];
let actualDate = moment(dateStr);
return {
actualDate: actualDate.toISOString(),
ingestion: {
time: ingestionTime.toISOString(),
diff: ingestionTime.diff(actualDate, 'seconds', true)
},
timestamp: {
time: timestamp.toISOString(),
diff: timestamp.diff(actualDate, 'seconds', true)
},
};
});
return { logStream, diffs };
});
console.log(JSON.stringify(allDiffs));
[
{
"ingestionTime": 1492003986633,
"timestamp": 1492003980458,
"message": "time=\"2017-04-12T13:32:46Z\" level=info msg=\"daemon starting\" pid=1234 version=1.0.1 "
},
{
"ingestionTime": 1492003986633,
"timestamp": 1492003980458,
"message": "time=\"2017-04-12T13:32:46Z\" level=info msg=\"Attempting operation\" server_path=\"/var/lib/daemon/dev.server\" "
}
]
[
{
"ingestionTime": 1492003986676,
"timestamp": 1492003966000,
"message": "time=\"2017-04-12T13:32:46Z\" level=info msg=\"daemon starting\" pid=1234 version=1.0.1 "
},
{
"ingestionTime": 1492003986676,
"timestamp": 1492003966000,
"message": "time=\"2017-04-12T13:32:46Z\" level=info msg=\"Attempting operation\" server_path=\"/var/lib/daemon/dev.server\" "
}
]
[
{
"logStream": "format1",
"diffs": [
{
"actualDate": "2017-04-12T13:32:46.000Z",
"ingestion": {
"time": "2017-04-12T13:33:06.633Z",
"diff": 20.633
},
"timestamp": {
"time": "2017-04-12T13:33:00.458Z",
"diff": 14.458
}
},
{
"actualDate": "2017-04-12T13:32:46.000Z",
"ingestion": {
"time": "2017-04-12T13:33:06.633Z",
"diff": 20.633
},
"timestamp": {
"time": "2017-04-12T13:33:00.458Z",
"diff": 14.458
}
}
]
},
{
"logStream": "format2",
"diffs": [
{
"actualDate": "2017-04-12T13:32:46.000Z",
"ingestion": {
"time": "2017-04-12T13:33:06.676Z",
"diff": 20.676
},
"timestamp": {
"time": "2017-04-12T13:32:46.000Z",
"diff": 0
}
},
{
"actualDate": "2017-04-12T13:32:46.000Z",
"ingestion": {
"time": "2017-04-12T13:33:06.676Z",
"diff": 20.676
},
"timestamp": {
"time": "2017-04-12T13:32:46.000Z",
"diff": 0
}
}
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment