Skip to content

Draft: Fix job log collapsible sections

Michael Kozono requested to merge fix-job-log-collapsible-sections into main

Why is this marked Draft?

This would be one small part of making nested collapsible sections work. I don't know how the Runner change should be done, because collapsing behavior also depends heavily on the ANSI => JSON converter and the Vue code to render HTML and JS that works.

What does this MR do?

Attempts to fix job log collapsible sections.

gitlab#29766

Why was this MR needed?

I noticed that a nested collapsible section broke its parent GitLab Runner section's collapsibility. When I investigated the job log output, I found a discrepancy in our section output vs the docs.

The format is like:

\e[0Ksection_start:1560896352:my_first_section\r\e[0K
content
\e[0Ksection_end:1560896353:my_first_section\r\e[0K

but currently we output:

section_start:1560896352:my_first_section\r\e[0K
content
section_end:1560896353:my_first_section\r\e[0K

Interestingly, the collapsible sections mostly worked as-is. My hypothesis for why it worked is because:

  1. In general we are consistent about wrapping everything in sections, therefore only the first section_start is broken (since it does not have a leading CLEAR). After that, all subsequent sections appear to have a leading CLEAR which is actually the trailing CLEAR of the previous section_end.
  2. The collapsible section code is somewhat resilient to missing section_end and finalizes the previous section when a new one starts.

For example if I output two sections and replace the \rs with newline:

section_start:1560896352:my_first_section
\e[0Kthis line should be hidden when collapsed
section_end:1560896353:my_first_section
\e[0Ksection_start:1560896352:foo
\e[0Kthis line should be hidden when collapsed
section_end:1560896353:foo
\e[0K

Notice how the foo section_start appears to be formatted correctly.

See this real-life job log (there are extra, unrelated \e[0K characters because printLn outputs a leading one):

\e[0KRunning with gitlab-runner 16.1.0~beta.59.g83c66823 (83c66823)\e[0;m
\e[0K  on green-4.private.runners-manager.gitlab.com/gitlab.com/gitlab-org rpvz2FF9, system ID: s_d704414ba02a\e[0;m
\e[0K  feature flags: FF_NETWORK_PER_BUILD:true, FF_USE_IMPROVED_URL_MASKING:true\e[0;m
section_start:1690574547:resolve_secrets
\e[0K\e[0K\e[36;1mResolving secrets\e[0;m\e[0;m
section_end:1690574547:resolve_secrets
\e[0Ksection_start:1690574547:prepare_executor
\e[0K\e[0K\e[36;1mPreparing the "docker+machine" executor\e[0;m\e[0;m
\e[0KUsing Docker executor with image registry.gitlab.com/gitlab-org/gitlab-development-kit/asdf-bootstrapped-gdk-installed:improve-job-logs ...\e[0;m
\e[0KAuthenticating with credentials from job payload (GitLab Registry)\e[0;m
\e[0KPulling docker image registry.gitlab.com/gitlab-org/gitlab-development-kit/asdf-bootstrapped-gdk-installed:improve-job-logs ...\e[0;m
\e[0KUsing docker image sha256:f2c2c50623bce6397d28694db3dddfa5b5fad276d487a66f266c0bcef126bed3 for registry.gitlab.com/gitlab-org/gitlab-development-kit/asdf-bootstrapped-gdk-installed:improve-job-logs with digest registry.gitlab.com/gitlab-org/gitlab-development-kit/asdf-bootstrapped-gdk-installed@sha256:2205df62ac1f1e2c203c260eb87f0a51d2ac068a468d7e91f0240387588e3186 ...\e[0;m
section_end:1690574996:prepare_executor
\e[0Ksection_start:1690574996:prepare_script
\e[0K\e[0K\e[36;1mPreparing environment\e[0;m\e[0;m
Running on runner-rpvz2ff9-project-74823-concurrent-0 via runner-rpvz2ff9-private-1690569192-8c379ddf...
section_end:1690575002:prepare_script
\e[0Ksection_start:1690575002:get_sources
\e[0K\e[0K\e[36;1mGetting source from Git repository\e[0;m\e[0;m
\e[32;1mSkipping Git repository setup\e[0;m
\e[32;1mSkipping Git checkout\e[0;m
\e[32;1mSkipping Git submodules setup\e[0;m
section_end:1690575002:get_sources
\e[0Ksection_start:1690575002:step_script

What's the best way to test this MR?

I don't know.

What are the relevant issue numbers?

gitlab#29766

Edited by Michael Kozono

Merge request reports