Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve worker logs #1090

Merged
merged 6 commits into from
Jan 13, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions core/worker/lib/algorithm-logging/logging-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,38 @@ class LoggingProxy {
}

_getLogMessage(rawLine) {
try {
const logParsed = JSON.parse(rawLine);
if (logParsed?.log) {
try {
const internalLog = JSON.parse(logParsed.log);
const { log: logMessage, stream, ...parsedLogWithoutLogMessage } = internalLog;
return { logMessage, stream, parsedLogWithoutLogMessage };
}
catch (error) {
const { log: logMessage, stream, ...parsedLogWithoutLogMessage } = logParsed;
return { logMessage, stream, parsedLogWithoutLogMessage };
}
let stream;
let internalLog;
let logMessage = rawLine;
const logParsed = this._jsonTryParse(rawLine);

if (logParsed?.log) {
const internalParsed = this._jsonTryParse(logParsed.log);
let logObject = logParsed;
if (internalParsed?.log) {
logObject = internalParsed;
}
else {
return { logMessage: rawLine };
const { log: logStr, stream: streamLog, ...rest } = logObject;
logMessage = logStr;
stream = streamLog;
internalLog = rest;
}
return { logMessage, stream, internalLog };
}

_jsonTryParse(str) {
let result;
try {
if (typeof str === 'string') {
result = JSON.parse(str);
return result;
}
return str;
}
catch (error) {
return { logMessage: rawLine };
result = str;
}
return result;
}

_startWatch() {
Expand All @@ -98,12 +110,12 @@ class LoggingProxy {
try {
this._tail = new Tail(this._algorunnerLogFilePath, { fromBeginning: true });
this._tail.on('line', (line) => {
const { logMessage, stream, parsedLogWithoutLogMessage } = this._getLogMessage(line);
const { logMessage, stream, internalLog } = this._getLogMessage(line);
if (stream === 'stderr') {
log.info(logMessage, { component, ...parsedLogWithoutLogMessage });
log.info(logMessage, { component, ...internalLog });
}
else {
log.info(logMessage, { component, ...parsedLogWithoutLogMessage });
log.info(logMessage, { component, ...internalLog });
}
});
this._tail.on('error', (error) => {
Expand Down