Skip to content

toUTC unable to parse Kubernetes controller-runtime log timestamps #297

@wjam

Description

@wjam

What happened:

Attempting to format the timestamp from the JSON structured logs of a Go-based Kubernetes controller (specifically external-secrets, but this shows the relevant format - https://kubernetes.io/blog/2020/09/04/kubernetes-1-19-introducing-structured-logs/#using-structured-logs) results in the incorrect date

What you expected to happen:

The timestamp, which is seconds past epoch but with milliseconds (?) after the decimal point, to be parsed by toUTC correctly

How to reproduce it (as minimally and precisely as possible):

GOBIN=$(pwd) go install github.com/stern/stern@c1649ca9f88f9183467dadda7cd8c0ffd16943e8
echo '{"ts":1580306777.04728,"msg":"Pod status updated"}' | ./stern --stdin=true --template '{{- with $msg := .Message | tryParseJSON -}}{{- toUTC $msg.ts -}}{{- " - " -}}{{- $msg.msg -}}{{- end -}}'

Anything else we need to know?:
The underlying bug appears to be in github.com/spf13/cast which converts the json.Number into a time.Time by turning into a string before attempting to turn it into an int64 , which it assumes to be a whole number. Unfortunately, that repository has had much activity since February 2023.

Environment:

  • stern version (use stern --version): Built from HEAD (c1649ca9f88f9183467dadda7cd8c0ffd16943e8) to demo with stdin flag, but also present in 1.28.0
  • OS (e.g: cat /etc/os-release): Both macOS and Ubuntu 23.10
  • Install tools (e.g: Homebrew): Homebrew
  • Others:

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions