-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: logs processing speed increased
- Loading branch information
Showing
13 changed files
with
5,221 additions
and
3,509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
time node producer.js 1000000 | node --trace-uncaught ../index.js log -c ../__mocks__/custom-schema.json -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'strict' | ||
|
||
for (let i = 0; i < process.argv.slice(2)[0]; i++) { | ||
process.stdout.write('{"level":30,"time":1531171074631,"msg":"hello world","nested":{"mock":666},"test2":"red","pid":657,"hostname":"box","name":"app","v":1}' + '\n') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
const fastJsonParse = require('fast-json-parse') | ||
const pipeline = require('./pipeline') | ||
const pump = require('pump') | ||
const processLogs = require('./process-logs') | ||
const streamLogs = require('./stream-logs') | ||
const split = require('split2') | ||
const { pipeline } = require('readable-stream') | ||
|
||
module.exports = function (opts) { | ||
const pipe = pipeline(opts) | ||
pump(process.stdin, split(fastJsonParse), pipe) | ||
pipeline( | ||
process.stdin, | ||
split(fastJsonParse), | ||
processLogs(opts), | ||
...streamLogs(opts) | ||
) | ||
process.on('SIGINT', function () { process.exit(0) }) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const transformer = require('./transformer') | ||
const { stringify } = require('./utils') | ||
const { Transform } = require('readable-stream') | ||
|
||
module.exports = function processLogs (opts) { | ||
const transform = transformer(opts) | ||
const stringified = stringify(opts) | ||
|
||
return new Transform({ | ||
writableObjectMode: true, | ||
decodeStrings: false, | ||
transform: function (data, enc, cb) { | ||
if (data.value !== null) { | ||
this.push(stringified(transform(data.value))) | ||
} | ||
cb() | ||
}, | ||
construct (callback) { | ||
this.data = '' | ||
callback() | ||
}, | ||
flush (callback) { | ||
try { | ||
this.push('') | ||
} catch (err) { | ||
callback(err) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const Transport = require('./transport') | ||
const { Transform } = require('readable-stream') | ||
|
||
module.exports = function processLogs (opts) { | ||
const streams = [] | ||
if (opts.verbose) { | ||
streams.push(getVerbose()) | ||
} | ||
if (opts.transportToGraylog) { | ||
streams.push(getTransport(opts)) | ||
} | ||
return streams | ||
} | ||
|
||
function getVerbose () { | ||
return new Transform({ | ||
writableObjectMode: true, | ||
decodeStrings: false, | ||
transform: function (data, enc, cb) { | ||
setImmediate(function () { process.stdout.write(data + '\n') }) | ||
cb() | ||
} | ||
}) | ||
} | ||
|
||
function getTransport (opts) { | ||
console.log('transport is prepared') | ||
const transport = new Transport(opts) | ||
return new Transform({ | ||
writableObjectMode: true, | ||
decodeStrings: false, | ||
transform: function (data, enc, cb) { | ||
setImmediate(function () { | ||
transport.emit('log', data) | ||
}) | ||
cb() | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
const get = require('lodash.get') | ||
|
||
module.exports = function (data, customSchema) { | ||
return Object.entries(customSchema.properties) | ||
.reduce((acc, entry) => { | ||
const sourcePath = entry[1].source ? entry[1].source : entry[0] | ||
acc[entry[0]] = get(data, sourcePath, undefined) | ||
return acc | ||
}, {}) | ||
module.exports = function customGelf (properties) { | ||
return function (data) { | ||
const _data = {} | ||
for (const property in properties) { | ||
_data[property] = get(data, properties[property].source, data[property]) | ||
} | ||
return _data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.