Skip to content

Changes made in wacth.py to print Empty newlines that are skipped when watching pod logs. #2372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 21, 2025

Conversation

p172913
Copy link
Contributor

@p172913 p172913 commented Mar 9, 2025

What type of PR is this?
/kind bug

What this PR does / why we need it:
This PRs print Empty newlines that are skipped when watching pod logs. Changed yield login in stream to print only single empty line between the logs.

Which issue(s) this PR fixes:
Fixes #2358

Special notes for your reviewer:
This is my first time contributing, so please let me know if I made the change successfully!

Does this PR introduce a user-facing change?
None

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
None

Changes made in wacth.py to print Empty newlines that are skipped when watching pod logs.
@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 9, 2025
Copy link

linux-foundation-easycla bot commented Mar 9, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Mar 9, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @p172913!

It looks like this is your first PR to kubernetes-client/python 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/python has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot requested review from fabianvf and yliaog March 9, 2025 05:45
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 9, 2025
@p172913
Copy link
Contributor Author

p172913 commented Mar 9, 2025

@yliaog, @fabianvf Please review my PR and approve.

@yliaog
Copy link
Contributor

yliaog commented Mar 12, 2025

how did you test it? please add a test to this PR

@p172913
Copy link
Contributor Author

p172913 commented Mar 12, 2025

@yliaog I installed the kubernetes client in editable mode on local, made changes that are mentioned in PR and ran the code given in the issue as an test. It was working fine. And I am seeing output as expected. If needed I can add the test I did in tests...
Here is the screenshot of the output:
image

This file is to test whether empty line are printed when watch function in the kubernetes python client is used.
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 13, 2025
@p172913
Copy link
Contributor Author

p172913 commented Mar 14, 2025

@yliaog As per your request I commited a test case. Please review and approve my PR.

@yliaog
Copy link
Contributor

yliaog commented Mar 16, 2025

thanks for the PR, could you add a unit test in kubernetes/base/watch/watch_test.py ?

@p172913
Copy link
Contributor Author

p172913 commented Mar 17, 2025

@yliaog I added it in kubernetes/test/test_pod_logs.py. If i is needed in kubernetes/base/watch/watch_test.py. I can add it there.

@yliaog
Copy link
Contributor

yliaog commented Mar 17, 2025

please add a test in kubernetes/base/watch/watch_test.py

Added a unit test name test_pod_log_empty_lines to check if watch is printing empty lines. And made changes in test_watch_with_interspersed_newlines as the watch is also printing empty line. Added a condition to check for empty lines in ogs to avoid the errors.
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 18, 2025
Deleting file with tests added in test/test_pod_los.py
@p172913
Copy link
Contributor Author

p172913 commented Mar 18, 2025

@yliaog added unit test in kubernetes/base/watch/watch_test.py with name test_pod_log_empty_lines. And made changes in test_watch_with_interspersed_newlines test case to avoid empty line exception.

yield line # Normal non-empty line
last_was_empty = False
elif not last_was_empty:
yield '/n' # Only yield one empty line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be '\n' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it has to be '' (an empty string) if yield an empty string. We need to change unmarshal_event function also. If needed I can change '/n' to '' and will change unmarshal_event function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace '/n' with '' (empty string) and adjusted unmarshal_event function in watch.py

Changes made in unmarshal_event for not having issues with empty lines.

def test_pod_log_empty_lines(self):
pod_name = "demo-bug"
# Manifest with busybax to keep pod engaged for sometiem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: sometiem ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will adjust

def test_pod_log_empty_lines(self):
pod_name = "demo-bug"
# Manifest with busybax to keep pod engaged for sometiem
pod_manifest = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is pod_manifest used?

Copy link
Contributor Author

@p172913 p172913 Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used minikube before replacing it with mock function. After checking locally forgot to delete it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just deleted pod_manifest from watch_test.py.

Removed pod_manifest from watch_test.py.
# Print outputs
print(f"Captured logs: {log_output}")
# self.assertTrue(any("Hello from Docker" in line for line in log_output))
self.assertTrue(any(line.strip() == "" for line in log_output), "No empty lines found in logs")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add an assertion that ensures the log_output has exactly what is expected, the whole log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed assertive statement to make sure entire output logs are verified.

Changes made to check whether entire log is printed or not.
#Mock logs used for this test
w.stream = Mock(return_value=[
"Hello from Docker",
"", # Empty line
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add another empty line here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added few empty lines to the test case.

p172913 added 2 commits March 20, 2025 11:21
Changes made in watch.py to print multiple empty line if necessary.
As per request added few empty lines to test case in watch_test.py
@yliaog
Copy link
Contributor

yliaog commented Mar 21, 2025

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 21, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: p172913, yliaog

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

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 21, 2025
@yliaog
Copy link
Contributor

yliaog commented Mar 21, 2025

/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 21, 2025
@k8s-ci-robot k8s-ci-robot merged commit bd32360 into kubernetes-client:master Mar 21, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty newlines skipped when watching pod logs
3 participants