python icon indicating copy to clipboard operation
python copied to clipboard

When using follow=True option to read pod logs, the response stream sometimes returns many log lines at once

Open gjohnston9 opened this issue 5 months ago • 2 comments

What happened (please include outputs or screenshots): I'm using read_namespaced_pod_log, setting follow=True and _preload_content=False:

response = client.read_namespaced_pod_log(follow=True, ...)
for log in response.stream():
  ...

We expect each line to be valid JSON. However something changed recently, so that sometimes, a single item returned from the stream contains multiple log lines, so that we fail to parse it. When I run the exact same command but without setting follow=True, and call splitlines() on the whole response, each line is separated correctly.

With Follow=True: (removing a lot of details from these logs, keeping the structure and newlines)

> log_lines = get_logs_for_pods()
(Pdb) !l=next(log_lines)
(Pdb) p l
b'{"level":"info","ts":...,"caller":"...","msg":"...","rel":"...","tr":{"tid":"...","sid":"...","op":"..."}}\n{"level":"info","ts":...,"caller":"...","msg":"...","rel":"...","tr":{"tid":"...","sid":"...","op":"..."}}\n{"level":"info","ts":...,"caller":"...","msg":"...","rel":"snip","tr":{"tid":"...","sid":"...","op":"..."}}\n'

Without:

{"level":"info","ts":...,"caller":"...","msg":"...","rel":"...","tr":{"tid":"...","sid":"...","op":"..."}}

What you expected to happen: Each item from the stream would be a single log line.

I am not 100% sure if it's expected for the SDK to behave this way or not, based on the documentation. I can split the lines myself, but it would be a lot more intuitive if each item were a single log line.

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

  • Kubernetes version (kubectl version):
Client Version: v1.30.2
Server Version: v1.32.4-gke.1698000
  • OS (e.g., MacOS 10.13.6): Sequoia 15.5
  • Python version (python --version): python 3.8.13
  • Python client version (pip list | grep kubernetes): 20.13.0

gjohnston9 avatar Jul 27 '25 18:07 gjohnston9

/help

yliaog avatar Jul 30 '25 20:07 yliaog

@yliaog: This request has been marked as needing help from a contributor.

Guidelines

Please ensure that the issue body includes answers to the following questions:

  • Why are we solving this issue?
  • To address this issue, are there any code changes? If there are code changes, what needs to be done in the code and what places can the assignee treat as reference points?
  • How can the assignee reach out to you for help?

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-help command.

In response to this:

/help

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Jul 30 '25 20:07 k8s-ci-robot