Skip to content

Commit cda758d

Browse files
committed
feat: update kep 3288
Note down why we decide not to support the combination of `Stream` and `TailLines`. Signed-off-by: Jian Zeng <[email protected]>
1 parent e6475c7 commit cda758d

File tree

1 file changed

+50
-6
lines changed
  • keps/sig-node/3288-separate-stdout-from-stderr

1 file changed

+50
-6
lines changed

keps/sig-node/3288-separate-stdout-from-stderr/README.md

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ Add a new field `Stream` to `PodLogOptions` to allow users to indicate which log
189189
they want to retrieve. To maintain backward compatibility, if this field is not set,
190190
the combined stdout and stderr from the container will be returned to users.
191191

192+
Users are enabled to fetch the stderr log stream of a given container using kubectl as following:
193+
```bash
194+
kubectl logs --stream=stderr -c container pod
195+
```
196+
192197
### User Stories
193198

194199
Bob runs a service "foo" that continuously prints informational messages to stdout,
@@ -201,12 +206,51 @@ This problem could be resolved if Bob is able to specify that he only wants stde
201206

202207
### Notes/Constraints/Caveats (Optional)
203208

204-
<!--
205-
What are the caveats to the proposal?
206-
What are some important details that didn't come across above?
207-
Go in to as much detail as necessary here.
208-
This might be a good place to talk about core concepts and how they relate.
209-
-->
209+
It can be tricky when `Stream` and `TailLines` of `PodLogOptions` are both specified.
210+
211+
For instance, users might want to fetch the last 10 lines of the stderr log stream for a container, but
212+
this is prohibitively expensive to implement from kubelet's perspective:
213+
214+
At present, container's logs are stored in an encoded format, either "json-file" or "cri" format:
215+
216+
```
217+
# json-file
218+
{"log":"out1\n","stream":"stdout","time":"2024-08-20T09:31:37.985370552Z"}
219+
{"log":"err1\n","stream":"stderr","time":"2024-08-20T09:31:37.985370552Z"}
220+
221+
# cri
222+
2016-10-06T00:17:09.669794202Z stdout F out1
223+
2016-10-06T00:17:09.669794202Z stderr F err1
224+
```
225+
226+
Please note that the log stream is encoded in each log line. Let's see what will happen if kubelet needs to return
227+
the last 10 lines of the stderr log stream:
228+
1. Kubelet has to decode each line of the log file from the bottom to determine whether it is from the stderr stream or not,
229+
which is a CPU-intensive operation in practice.
230+
2. What's worse, once kubelet identifies that a line is from the stderr stream, it must keep track of the matched lines
231+
until a specified number of lines are found. This can be time-consuming, especially when only few lines of stderr logs
232+
amidst a large number of stdout logs.
233+
234+
In conclusion, it is not practical for kubelet to return the last N lines of a specific log stream.
235+
236+
Alternatively, kubelet could return logs that match the given stream within the last N lines. For example, consider the following logs:
237+
```
238+
{"log":"out1\n","stream":"stdout","time":"2024-08-20T09:31:37.985370552Z"}
239+
{"log":"err1\n","stream":"stderr","time":"2024-08-20T09:31:37.985370552Z"}
240+
{"log":"out2\n","stream":"stdout","time":"2024-08-20T09:31:37.985370552Z"}
241+
{"log":"err2\n","stream":"stderr","time":"2024-08-20T09:31:37.985370552Z"}
242+
```
243+
244+
If users run `kubectl logs --stream=stderr --tail=2 pod`, kubelet would only return the following:
245+
```
246+
err2
247+
```
248+
249+
This approach is more efficient, as kubelet only needs to parse a deterministic number of lines of log lines once
250+
rather than potentially all of them. However, this may go against users' expectations and could lead to confusion.
251+
252+
Taking all these considerations into account, I propose that we do not support the combination of `Stream` and `TailLines`
253+
in the first iteration.
210254

211255
### Risks and Mitigations
212256

0 commit comments

Comments
 (0)