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

fix(k8s/log): correct line breaks in logs #324

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

# These are backup files generated by rustfmt
**/*.rs.bk

/test/bin/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package-install:

test/bin/kind:
mkdir -p test/bin
curl -Lo test/bin/kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64
curl -Lo test/bin/kind https://kind.sigs.k8s.io/dl/v0.19.0/kind-linux-amd64
chmod +x test/bin/kind

create-kind: test/bin/kind
Expand Down
19 changes: 16 additions & 3 deletions src/event/kubernetes/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,17 +828,30 @@ impl Worker for FetchLogStream {

let mut logs = self.pod_api.log_stream(&self.pod_name, &lp).await?.boxed();

while let Some(line) = logs.try_next().await? {
while let Some(bytes) = logs.try_next().await? {
let mut buf = self.buf.write().await;
buf.push(format!("{}{}", prefix, String::from_utf8_lossy(&line)));

let logs = String::from_utf8_lossy(&bytes);

logger!(
debug,
"Container log stream [{}:{}] - {}",
self.pod_name,
self.container_name,
String::from_utf8_lossy(&line)
logs
);

for line in logs.lines() {
buf.push(format!("{}{}", prefix, line));

logger!(
debug,
"Container log stream [{}:{}] - {}",
self.pod_name,
self.container_name,
line
);
}
}

logger!(
Expand Down
Binary file removed test/bin/kind
Binary file not shown.