Skip to content

fix(trainer): yield log lines from ContainerBackend.get_job_logs - #940

Open
prabindersinghh wants to merge 1 commit into
kubeflow:mainfrom
prabindersinghh:fix/container-logs-by-line
Open

prabindersinghh wants to merge 1 commit into
kubeflow:mainfrom
prabindersinghh:fix/container-logs-by-line

Conversation

@prabindersinghh

@prabindersinghh prabindersinghh commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

get_job_logs is documented to return an iterator of log lines, and the Kubernetes backend yields one line per item. The container backend passed through whatever the Docker or Podman adapter returned: the whole log as one string without follow, and raw stream frames with follow, which can split a line across items or merge several into one.

This buffers the chunks in ContainerBackend.get_job_logs and yields complete lines without the line terminator, so iterating over logs behaves the same on every backend. The change sits in the backend rather than the adapters, so Docker and Podman both get it.

Error handling in this method (the "Error getting logs: ..." line) is unchanged here and can be looked at separately.

Regression coverage (test_get_job_logs_yields_lines, for both follow=False and follow=True):

  • whole log in one chunk
  • a line split across chunks
  • CRLF endings, including split across chunks
  • no trailing newline
  • blank lines
  • empty chunks

Validation:

  • uv run pytest -q kubeflow/trainer/backends/container/backend_test.py: 52 passed
  • new tests fail on main and pass with the fix
  • make verify: passed
  • uv run pytest -q kubeflow: 723 passed

Which issue(s) this PR fixes (optional, in Fixes #<issue number>, #<issue number>, ... format, will close the issue(s) when PR gets merged):

Fixes #938

Checklist:

  • Docs included if any changes are user facing

Docs are not needed: this makes the container backend match the behaviour get_job_logs already documents.

AI usage:

Claude was used to help implement the fix and the regression tests. I reviewed the changes, confirmed the new tests fail on main and pass with the fix, and ran the validation above. The commit carries an Assisted-by trailer.

…ob_logs

get_job_logs is documented to return an iterator of log lines, and the
Kubernetes backend yields one line per item. The container backend passed
through whatever the Docker or Podman adapter returned: the whole log as a
single string without follow, and raw stream frames with follow, which can
split one line across items or merge several into one.

Buffer the chunks and yield complete lines without the line terminator, so
iterating over the logs behaves the same on every backend.

Assisted-by: Claude
Signed-off-by: Prabinder Singh <prabindersinghh@gmail.com>
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign andreyvelich for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Ready to Merge

Development

Successfully merging this pull request may close these issues.

ContainerBackend.get_job_logs() yields raw Docker/Podman chunks instead of log lines

1 participant