Skip to content

Parses job log logs when lines gets split in chunks

What does this MR do and why?

This fix allows the log viewer to preserve correct spacing when rendering lines that have split across chunks when logs are longer.

Changelog: fixed

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Before After
image image

How to set up and validate locally

We can create a long log (especially one with long lines) to force the lines to be split.

stages:
  - build

long-job:
  stage: build
  script:
    - for i in {1..5000}; do echo "This is the very very very very very very very very very very very very very very very very very very very long line"; done

After that we can modify the code to indicate in the console where to look for breaks in the code (we can also simply scroll to check there's not splits, but that's not a very reliable check):

diff --git a/app/assets/javascripts/ci/job_log_viewer/lib/generate_stream.js b/app/assets/javascripts/ci/job_log_viewer/lib/generate_stream.js
index 9fed250ee426..d47649e42ed5 100644
--- a/app/assets/javascripts/ci/job_log_viewer/lib/generate_stream.js
+++ b/app/assets/javascripts/ci/job_log_viewer/lib/generate_stream.js
@@ -26,8 +26,11 @@ async function* getLogStreamLines(stream) {
   const textDecoder = new TextDecoder();
 
   let chunkRemainder = '';
+  let i = 0;
 
   for await (const chunk of stream) {
+    console.log(`chunk split at the ${i}th line`);
+
     const decodedChunk = textDecoder.decode(chunk);
     const lines = decodedChunk.split('\n');
 
@@ -35,6 +38,7 @@ async function* getLogStreamLines(stream) {
     chunkRemainder = lines.pop() || '';
 
     for (const line of lines) {
+      i++;
       if (line.trim() !== '') {
         yield {
           text: line,

We can look for where the log got split and check the line is correct:

image

Related to #455588 (closed)

Edited by Miguel Rincon

Merge request reports