kestra-io / kestra-io/plugin-kubernetes-lib

LoggingOutputStream collapses runs of whitespace in pod log lines

Open
#20 0 comments 0 reactions 1 assignee Claimed by @Malaydewangan09 View on GitHub
area/backend area/plugin
Dominant language
Java
Stars
0
Forks
0
Avg merge
1d 17h
Merged PRs (30d)
10

Description

## What

`LoggingOutputStream.send()` collapses every run of whitespace in a pod log line, so a line the
container actually printed as

```
spaced out columns
```

reaches Kestra as

```
spaced out columns
```

## Why

`PodLogService` requests logs with `usingTimestamps()`, so every line arrives prefixed with an
RFC3339 timestamp that has to be stripped. `send()` does that by splitting the whole line on
`\s+` and rejoining the remainder with single spaces:

```java
ArrayList logs = new ArrayList<>(Arrays.asList(lineWithTimestamp.split("\\s+")));
...
logs.remove(0);
message = String.join(" ", logs);
```

Splitting on every whitespace run rather than just the first rewrites the message itself.

## Impact

Any command whose output relies on spacing loses it: column-aligned tables, `df`, `ls -l`,
ASCII art, indented stack traces. Tabs are unaffected (they survive as escaped characters in
practice), only literal runs of spaces collapse.

It gets worse for the EE Kubernetes runner's `monitoring.enabled` mode, where the log body
travels inside an OTLP JSON payload: the collapse then rewrites user log content carried as a
JSON string value.

## Reproduction

Verified on a kind cluster (k8s v1.34.0) through a real Kestra instance, with the runner's
monitoring both on and off, so this is not specific to that feature.

```yaml
tasks:
- id: shell
type: io.kestra.plugin.scripts.shell.Commands
taskRunner:
type: io.kestra.plugin.ee.kubernetes.runner.Kubernetes
namespace: default
commands:
- printf 'spaced out columns\n'
```

Observed: `spaced out columns`. Expected: `spaced out columns`.

## Fix

Split on the first whitespace run only and keep the remainder verbatim:

```java
String[] parts = lineWithTimestamp.split("\\s+", 2);
...
message = parts.length > 1 ? parts[1] : "";
```

I have this implemented locally with unit tests covering the timestamp strip, the preserved
spacing, an OTLP frame passing through intact, a line with no timestamp, a timestamp-only line,
and out-of-order timestamp tracking. Verified end to end on the cluster: before the fix
`spaced out columns`, after it `spaced out columns`. Happy to open the PR.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.