Skip to content
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

container logs should be escaped when printed #2751

Merged
merged 3 commits into from
Aug 16, 2024

Conversation

wjiec
Copy link
Contributor

@wjiec wjiec commented Jun 19, 2024

this pr fixes #2746.

Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@wjiec Thank you for looking into this issue!

@@ -380,8 +381,8 @@ func readLogs(ctx context.Context, wg *sync.WaitGroup, stream io.ReadCloser, out
r := bufio.NewReader(stream)
for {
var item *LogItem
if bytes, err := r.ReadBytes('\n'); err == nil {
item = opts.ToLogItem(bytes)
if line, err := r.ReadString('\n'); err == nil {
Copy link
Owner

Choose a reason for hiding this comment

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

@wjiec Given we are dealing with logs, I think there will be additional allocations converting bytes->string->bytes. Perhaps we should regex directly the bytes vs hitting the extra allocations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@derailed I've thought about this, if regular expression matching is done directly on the bytes it would require copying the code out of the tview, which I think might be a bit repetitive, and could also leave a hidden problem if the tview updates this regular expression afterwards. I chose the safer out of the two possible methods.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks Jayson! I understand. We are however using a fork and we can control changes if they occurred but that would require a strategy change for region and color tags which is unlikely. On the other hand we're dealing with lots of gc pressure. I think we could perhaps intro a one liner tview.EscapeBytes in the fork?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@derailed Thank you for your reply, indeed, it is the best way!

@derailed derailed added the needs-tlc Pr needs additional updates label Aug 16, 2024
Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@wjiec Awesome! Thank you Jayson!!

@derailed derailed merged commit 66f57be into derailed:master Aug 16, 2024
2 checks passed
@wjiec wjiec deleted the bugfix/escape-log branch August 16, 2024 16:47
@wjiec
Copy link
Contributor Author

wjiec commented Aug 16, 2024

@derailed Oops, I'm having problems with the implementation in tview.EscapeBytes! The problem wasn't actually fixed, my bad! 🙁

uozalp pushed a commit to uozalp/k9s that referenced this pull request Sep 2, 2024
* container logs should be escaped when printed

* reduce additional memory allocation

* upgrade deps and move escape to tview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-tlc Pr needs additional updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

k9s does not display "[::]" string in its logs
2 participants