Skip to content

fix: do not fail get_pod_logs on bytes that are not valid UTF-8 - #2207

Open
mayuriphad wants to merge 2 commits into
robusta-dev:masterfrom
mayuriphad:fix/pod-logs-invalid-utf8
Open

mayuriphad wants to merge 2 commits into
robusta-dev:masterfrom
mayuriphad:fix/pod-logs-invalid-utf8

Conversation

@mayuriphad

Copy link
Copy Markdown

get_pod_logs decoded the pod log bytes in strict UTF-8 mode and only caught ApiException. A single byte that is not valid UTF-8 (for example the raw 0xff jsoniter writes into its error messages) raised UnicodeDecodeError, which failed the whole action: the Log Viewer shows ACTION_UNEXPECTED_ERROR (Error code: 4700) and logs_enricher returns no logs, while kubectl logs prints the same pod fine.

The logs are now decoded with errors="replace", so the invalid byte becomes � and the rest of the logs are returned.

Fixes #2201

Added tests/test_pod_logs_decoding.py; the invalid-byte case fails with UnicodeDecodeError without the change.

Signed-off-by: mayuriphad <mayuriphad656@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 04:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e40908b8-4261-4ea0-aa3c-0cc8340ecef1
Commits

Reviewing files that changed from the base of the PR and between 630e2b0 and 76d7459.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eebbecc4-5245-4740-a77d-e18d1833fa64
📥 Commits

Reviewing files that changed from the base of the PR and between a254278 and 630e2b0.

📒 Files selected for processing: 2
  • src/robusta/integrations/kubernetes/api_client_utils.py
  • tests/test_pod_logs_decoding.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Walkthrough

get_pod_logs now replaces invalid UTF-8 bytes during decoding. New tests verify valid UTF-8 output and replacement of invalid bytes.

Changes

Pod log decoding

Layer / File(s) Summary
Decode pod logs and verify output
src/robusta/integrations/kubernetes/api_client_utils.py, tests/test_pod_logs_decoding.py
get_pod_logs replaces invalid UTF-8 bytes during decoding. Tests cover valid UTF-8 and replacement decoding for invalid bytes.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: djarv1337

Merge Risk: Minimal · previous review 630e2

This localized change addresses malformed pod-log bytes without an established merge-blocking risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing get_pod_logs from failing on invalid UTF-8 bytes.
Description check Passed The description directly explains the invalid UTF-8 failure, the errors="replace" fix, the affected behavior, and the added tests.
Linked Issues check Passed Issue #2201 requires get_pod_logs to return pod logs when bytes are invalid UTF-8. The PR changes the decode call to decode("utf-8", errors="replace"). The new tests cover valid UTF-8 and replacem…
Out of Scope Changes check Passed The PR changes only the get_pod_logs decoding behavior and adds focused tests for that behavior. Both changes directly support issue #2201 and the stated PR scope.
Full details: Linked Issues check

Explanation

Issue #2201 requires get_pod_logs to return pod logs when bytes are invalid UTF-8. The PR changes the decode call to decode("utf-8", errors="replace"). The new tests cover valid UTF-8 and replacement of raw 0xff with �. The optional follow-up for other decode sites is not a requirement for this issue target.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@mayuriphad

Copy link
Copy Markdown
Author

Hi, just a gentle ping on this PR. It's ready for review whenever you have time, and I'm happy to make any changes you'd like. Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log Viewer / logs_enricher fails with UnicodeDecodeError when pod logs contain invalid UTF-8 bytes (ACTION_UNEXPECTED_ERROR 4700)

2 participants