Skip to content

Resume from the last log line when it retries #229

@tksm

Description

@tksm

What would you like to be added:

I would like to resume from the last log line when it retries. Here is what I would expect.

$ stern counter
+ counter › c
counter c line 1
counter c line 2
counter c line 3
counter c line 4
counter c line 5
- counter › c
failed to tail: unexpected EOF, will retry
+ counter › c
counter c line 6
counter c line 7
counter c line 8
counter c line 9
counter c line 10
- counter › c
failed to tail: unexpected EOF, will retry
+ counter › c
counter c line 11
counter c line 12
counter c line 13
counter c line 14
counter c line 15

Why is this needed:

Currently, stern shows logs from the beginning when it retries as follows, so it isn't easy to read if containers have many log lines. Retrying occurs in some environments often since load balancers or firewalls might disconnect when there are no logs for a while.

$ stern counter
+ counter › c
counter c line 1
counter c line 2
counter c line 3
counter c line 4
counter c line 5
unexpected error: unexpected EOF
- counter › c
+ counter › c
counter c line 1
counter c line 2
counter c line 3
counter c line 4
counter c line 5
counter c line 6
counter c line 7
counter c line 8
counter c line 9
counter c line 10
unexpected error: unexpected EOF
- counter › c
+ counter › c
counter c line 1
counter c line 2
counter c line 3
counter c line 4
counter c line 5
counter c line 6
counter c line 7
counter c line 8
counter c line 9
counter c line 10
counter c line 11
counter c line 12
counter c line 13
counter c line 14
counter c line 15
apiVersion: v1
kind: Pod
metadata:
  name: counter
spec:
  terminationGracePeriodSeconds: 0
  containers:
  - name: c
    command:
    - /bin/sh
    - -c
    - |
      N=1
      while true; do
        for _ in $(seq 5); do
          echo "line $N"
          N=$((N+1))
        done
        sleep 150
      done
    image: busybox:1.36.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions