-
Notifications
You must be signed in to change notification settings - Fork 38.9k
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
Fix log timestamps to maintain a fixed width #91207
Fix log timestamps to maintain a fixed width #91207
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Welcome @iamchuckss! |
Hi @iamchuckss. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
0512910
to
40906e0
Compare
/assign @derekwaynecarr |
@iamchuckss Thank you for pushing this forward. Here is a bit extra for you to include if you choose:
|
We should probably update the KEP that says we will use the previous timestamp format. Since the CRI logging format is an API, I consider this to be an API change, although I can't tell if there will be any backwards-compatibility issues here. It would be helpful to describe what changes would be required for container runtimes (if any), and what changes would be required for log consumers (if any). /ok-to-test |
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
@dashpole Not exactly sure what you mean by "the KEP that says we will use the previous timestamp format". Do you mean this? I do not know where else the format is discussed. "RFC3339Nano" is mentioned is some of the documentation, but to be fair, it is not a real standard and Docker claims to output its logs in RFC3339Nano but is actually using the proposed RFC3339NanoFixed.
It would be a very odd piece of software that would be negatively affected by this change. The change consists of keeping rather than trimming/removing trailing zeros in log timestamps. What is currently this:
will become this:
To the extent any consumer is using timestamps, this increased consistency is likely to be solving problems and fixing hidden bugs rather than creating them. It is a bit hard for me to imagine a system relying on this current behavior. It is possible that a system that tries to compensate for this behavior might be tricked into overcompensating, but that strikes me as unlikely. @iamchuckss I do not understand the build failures, but am happy to help if my help is needed/wanted. These appear to be build failures, and since I do not understand the build system and have never been able to get it to work locally, I really do not understand what is going wrong. My best guess it that the builder is trying to build Add "//pkg/kubelet/types:go_default_library" to BUILD depsdiff --git a/pkg/kubelet/kuberuntime/logs/BUILD b/pkg/kubelet/kuberuntime/logs/BUILD
index 18b4c8ec45a..42cde17e300 100644
--- a/pkg/kubelet/kuberuntime/logs/BUILD
+++ b/pkg/kubelet/kuberuntime/logs/BUILD
@@ -6,6 +6,7 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/kubelet/kuberuntime/logs",
visibility = ["//visibility:public"],
deps = [
+ "//pkg/kubelet/types:go_default_library",
"//pkg/util/tail:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/cri-api/pkg/apis:go_default_library", |
I believe the proposal was implemented? #55922.
Great. That is what I was looking for. The example was helpful. |
@dashpole Sorry, I was a bit confused. The document I referred to is a proposal...
While that proposal was partly implemented in #55922, it defines the log format output by the Container Runtime and parsed by kubelet (and fluentd and others). Our PR here does not modify that interface in any way. We have specifically created a separate Our PR only affects the Pod's Read Log API, and although it is documented to optionally add "an RFC3339 or RFC3339Nano timestamp at the beginning of every line of log output", the fact that RFC3339 and RFC3339Nano reference Go language formats is not made clear, so I think this change is not violating the spirit of the documentation. There is no option for choosing between RFC3339 or RFC3339Nano formats so it is already unclear what to expect. RFC 3339 (the standard, not the constant) allows any number of digits for the fractional second representation. Still, I think it is worth updating the documentation. @iamchuckss 3 more minor changes for you: Revise documentation of Read Log APIdiff --git a/pkg/apis/core/types.go b/pkg/apis/core/types.go
index 3944d5dcadc..9418a118eac 100644
--- a/pkg/apis/core/types.go
+++ b/pkg/apis/core/types.go
@@ -4252,7 +4252,7 @@ type PodLogOptions struct {
// If this value is in the future, no logs will be returned.
// Only one of sinceSeconds or sinceTime may be specified.
SinceTime *metav1.Time
- // If true, add an RFC3339 or RFC3339Nano timestamp at the beginning of every line
+ // If true, add an RFC 3339 timestamp with 9 digits of fractional seconds at the beginning of every line
// of log output.
Timestamps bool
// If set, the number of lines from the end of the logs to show. If not specified, Revise documentation of format variables APIdiff --git a/pkg/kubelet/kuberuntime/logs/logs.go b/pkg/kubelet/kuberuntime/logs/logs.go
index 07f8782d594..e06709e3696 100644
--- a/pkg/kubelet/kuberuntime/logs/logs.go
+++ b/pkg/kubelet/kuberuntime/logs/logs.go
@@ -48,8 +48,9 @@ import (
// TODO(random-liu): Support log rotation.
const (
- // timeFormatOut and timeFormatIn are time formats used in the log.
+ // timeFormatOut is the format for writing timestamps to output.
timeFormatOut = types.RFC3339NanoFixed
+ // timeFormatIn is the format for parsing timestamps from other logs.
timeFormatIn = types.RFC3339NanoLenient
// logForceCheckPeriod is the period to check for a new read Modify test to detect timestamp truncationdiff --git a/pkg/kubelet/kuberuntime/logs/logs_test.go b/pkg/kubelet/kuberuntime/logs/logs_test.go
index 25e3bd20e59..f53b93037e6 100644
--- a/pkg/kubelet/kuberuntime/logs/logs_test.go
+++ b/pkg/kubelet/kuberuntime/logs/logs_test.go
@@ -143,7 +143,7 @@ func TestParseLog(t *testing.T) {
}
func TestWriteLogs(t *testing.T) {
- timestamp := time.Unix(1234, 4321)
+ timestamp := time.Unix(1234, 43210)
log := "abcdefg\n"
for c, test := range []struct { |
24b3000
to
b5a02c4
Compare
@Nuru Done! |
/assign @thockin |
/assign @smarterclayton The robot assigned thockin but since this fixes a bug you opened (#72292), perhaps you would be interested in reviewing and approving it |
@dashpole Do you want anything more or can we get a LGTM from you? |
nope, thanks for the explanation. This isn't a CRI change, its a kubelet pod logs endpoint change. /lgtm |
I believe this change is within the spirit of our API guidelines - the precision was variable before, it is unlikely that anyone was successful at hardcoding precision, and while this may change parsing of ReadLog output, the format is broadly worded with no explicit guarantee. Standard timestamp processing would be no more or less impacted in general. I'm willing to chance a very small number of parsing scripts that were subtly wrong are impacted. /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: iamchuckss, smarterclayton The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@smarterclayton Thanks for the approval. What do you think about cherry-picking this back to currently supported releases? I know it is not a critical bug fix, but it is also small and low-risk. |
@iamchuckss Thanks for doing this PR. What do you think of proposing cherry-picks so we can see this sooner rather than later? |
@iamchuckss Thanks. Would you also please cherry pick to 1.17 and 1.16 (and 1.15 if that is still an option)? |
…1207-upstream-release-1.17 Automated cherry pick of #91207: Fix log timestamps to be displayed in fixed width
…1207-upstream-release-1.18 Automated cherry pick of #91207: Fix log timestamps to be displayed in fixed width
…1207-upstream-release-1.16 Automated cherry pick of #91207: Fix log timestamps to be displayed in fixed width
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #91186
Fixes #72292
Special notes for your reviewer:
Does this PR introduce a user-facing change?: