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

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

Closed
wjam opened this issue Apr 26, 2024 · 1 comment · Fixed by #300
Closed

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

wjam opened this issue Apr 26, 2024 · 1 comment · Fixed by #300
Assignees
Labels
kind/bug Something isn't working

Comments

@wjam
Copy link
Contributor

wjam commented Apr 26, 2024

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:
@wjam wjam added the kind/bug Something isn't working label Apr 26, 2024
@tksm tksm self-assigned this May 2, 2024
@tksm
Copy link
Contributor

tksm commented May 2, 2024

Hi,

I'm going to address the issue with the PR #300.
Thank you for reporting!

@tksm tksm closed this as completed in #300 May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants