Skip to content

Commit

Permalink
Interrupt k8s logs when logs found
Browse files Browse the repository at this point in the history
  • Loading branch information
frostebite committed Oct 2, 2023
1 parent 9cb8294 commit 4b07216
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 39 deletions.
23 changes: 7 additions & 16 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

36 changes: 14 additions & 22 deletions src/model/cloud-runner/providers/k8s/kubernetes-task-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class KubernetesTaskRunner {
? ` -f -c ${containerName}`
: ` --previous`;

let logs;
const callback = (outputChunk: string) => {
output += outputChunk;

Expand All @@ -47,15 +46,28 @@ class KubernetesTaskRunner {
CloudRunnerLogger.log(`Loghash found`);
}
if (chunk.includes(`LOGS:`)) {
CloudRunnerLogger.log(`LOGS: found`);

// remove "LOGS: " and decode base64 remaining
const unpacked = Buffer.from(chunk.split(`LOGS: `)[1], 'base64').toString('ascii');
const result = RemoteClientLogger.HandleLogFull(unpacked);
CloudRunnerLogger.log(`Logs found HandleLogChunkLineResult:${result}`);
if (result) {
FollowLogStreamService.DidReceiveEndOfTransmission = true;
}

return;
}
({ shouldReadLogs, shouldCleanup, output } = FollowLogStreamService.handleIteration(
chunk,
shouldReadLogs,
shouldCleanup,
output,
));
}
};
try {
logs = await CloudRunnerSystem.Run(`kubectl logs ${podName}${extraFlags}`, false, true, callback);
await CloudRunnerSystem.Run(`kubectl logs ${podName}${extraFlags}`, false, true, callback);
} catch (error: any) {
await new Promise((resolve) => setTimeout(resolve, 3000));
const continueStreaming = await KubernetesPods.IsPodRunning(podName, namespace, kubeClient);
Expand All @@ -70,26 +82,6 @@ class KubernetesTaskRunner {
}
throw error;
}
const splitLogs = logs.split(`\n`);
for (const chunk of splitLogs) {
const message = CloudRunner.buildParameters.cloudRunnerDebug ? chunk : chunk.split(`Z `)[1];

// if line contains "LOGS: " then stop
if (message.includes(`LOGS:`)) {
CloudRunnerLogger.log(`LOGS: found`);
continue;
}
({ shouldReadLogs, shouldCleanup, output } = FollowLogStreamService.handleIteration(
message,
shouldReadLogs,
shouldCleanup,
output,
));
const result = RemoteClientLogger.HandleLog(message);
if (result) {
FollowLogStreamService.DidReceiveEndOfTransmission = true;
}
}
if (FollowLogStreamService.DidReceiveEndOfTransmission) {
CloudRunnerLogger.log('end of log stream');
break;
Expand Down

0 comments on commit 4b07216

Please sign in to comment.