Include log chunk when task runner sees log update, clarify if we can pull logs from same line or next line

This commit is contained in:
Frostebite 2023-09-25 18:26:32 +01:00
parent f563b8c810
commit 534c94e159
5 changed files with 31 additions and 8 deletions

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -43,13 +43,13 @@ class KubernetesTaskRunner {
CloudRunnerLogger.log(`Log Start found in logs`); CloudRunnerLogger.log(`Log Start found in logs`);
} }
if (chunk.includes(`LOGHASH:`)) { if (chunk.includes(`LOGHASH:`)) {
RemoteClientLogger.HandleLogChunkLine(chunk); RemoteClientLogger.HandleLogHash(chunk);
CloudRunnerLogger.log(`Loghash found`); CloudRunnerLogger.log(`Loghash found`);
} }
if (chunk.includes(`LOGS:`)) { if (chunk.includes(`LOGS:`)) {
// remove "LOGS: " and decode base64 remaining // remove "LOGS: " and decode base64 remaining
const unpacked = Buffer.from(chunk.split(`LOGS: `)[1], 'base64').toString('ascii'); const unpacked = Buffer.from(chunk.split(`LOGS: `)[1], 'base64').toString('ascii');
const result = RemoteClientLogger.HandleLogChunkLine(unpacked); const result = RemoteClientLogger.HandleLogFull(unpacked);
CloudRunnerLogger.log(`Logs found HandleLogChunkLineResult:${result}`); CloudRunnerLogger.log(`Logs found HandleLogChunkLineResult:${result}`);
} }
} }
@ -73,13 +73,19 @@ class KubernetesTaskRunner {
const splitLogs = logs.split(`\n`); const splitLogs = logs.split(`\n`);
for (const chunk of splitLogs) { for (const chunk of splitLogs) {
const message = CloudRunner.buildParameters.cloudRunnerDebug ? chunk : chunk.split(`Z `)[1]; const message = CloudRunner.buildParameters.cloudRunnerDebug ? chunk : chunk.split(`Z `)[1];
// if line contains "LOGS: " then stop
if (message.includes(`LOGS:`)) {
CloudRunnerLogger.log(`LOGS: found`);
break;
}
({ shouldReadLogs, shouldCleanup, output } = FollowLogStreamService.handleIteration( ({ shouldReadLogs, shouldCleanup, output } = FollowLogStreamService.handleIteration(
message, message,
shouldReadLogs, shouldReadLogs,
shouldCleanup, shouldCleanup,
output, output,
)); ));
const result = RemoteClientLogger.HandleLogChunkLine(message); const result = RemoteClientLogger.HandleLog(message);
if (result) { if (result) {
FollowLogStreamService.DidReceiveEndOfTransmission = true; FollowLogStreamService.DidReceiveEndOfTransmission = true;
} }

View File

@ -68,10 +68,9 @@ export class RemoteClientLogger {
await new Promise((resolve) => setTimeout(resolve, 15000)); await new Promise((resolve) => setTimeout(resolve, 15000));
} }
} }
public static HandleLogChunkLine(message: string): boolean { public static HandleLog(message: string): boolean {
if (message.includes('LOGHASH: ')) { if (message.includes('LOGHASH: ')) {
RemoteClientLogger.md5 = message.split(`LOGHASH: `)[1]; RemoteClientLogger.HandleLogHash(message);
CloudRunnerLogger.log(`LOGHASH: ${RemoteClientLogger.md5}`);
} else { } else {
if (RemoteClientLogger.value !== '') { if (RemoteClientLogger.value !== '') {
RemoteClientLogger.value += `\n`; RemoteClientLogger.value += `\n`;
@ -88,6 +87,24 @@ export class RemoteClientLogger {
return false; return false;
} }
public static HandleLogHash(message: string) {
if (message.includes('LOGHASH: ')) {
RemoteClientLogger.md5 = message.split(`LOGHASH: `)[1];
CloudRunnerLogger.log(`LOGHASH: ${RemoteClientLogger.md5}`);
} else {
throw new Error(`LOGHASH: not found`);
}
}
public static HandleLogFull(message: string): boolean {
const hashedValue = md5(message);
if (RemoteClientLogger.md5 === hashedValue) {
CloudRunnerLogger.log(`LOG COMPLETE`);
return true;
}
return false;
}
static value: string = ''; static value: string = '';
static md5: any; static md5: any;
} }

View File

@ -9,10 +9,10 @@ describe('Cloud Runner Remote Client', () => {
const testLogStream = 'Test \n Log \n Stream'; const testLogStream = 'Test \n Log \n Stream';
const splitLogStream = testLogStream.split('\n'); const splitLogStream = testLogStream.split('\n');
RemoteClientLogger.HandleLogChunkLine(`LOGHASH: ${md5(testLogStream)}`); RemoteClientLogger.HandleLog(`LOGHASH: ${md5(testLogStream)}`);
let completed = false; let completed = false;
for (const element of splitLogStream) { for (const element of splitLogStream) {
completed = RemoteClientLogger.HandleLogChunkLine(element); completed = RemoteClientLogger.HandleLog(element);
} }
expect(completed).toBeTruthy(); expect(completed).toBeTruthy();
}, 1_000_000_000); }, 1_000_000_000);