Skip to content

Conversation

tksm
Copy link
Contributor

@tksm tksm commented May 2, 2024

This commit adds support for UNIX time seconds with nanoseconds (e.g., 1136171056.02) to the following template functions:

  • toRFC3339Nano
  • toTUC
  • toTimestamp

As described in #297, the toUTC currently fails to parse a timestamp like 1580306777.04728, resulting in the incorrect date.

$ echo '{"ts":1580306777.04728,"msg":"Pod status updated"}' | ./stern --stdin=true --template '{{- with $msg := .Message | tryParseJSON -}}{{- toUTC $msg.ts -}}{{- " - " -}}{{- $msg.msg -}}{{- end -}}'
0001-01-01 00:00:00 +0000 UTC - Pod status updated

With this commit, the toUTC can correctly parse the timestamp with nanoseconds.

2020-01-29 14:06:17.04728 +0000 UTC - Pod status updated%

Fixes #297

Copy link
Member

@rkmathi rkmathi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🥳

@tksm tksm merged commit 0d580ff into stern:master May 2, 2024
@tksm tksm deleted the support-nanosec branch May 2, 2024 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

toUTC unable to parse Kubernetes controller-runtime log timestamps
2 participants