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

add support for iso8601 timestamps #1529

Conversation

ironmike-au
Copy link
Contributor

Description of the change:
This change adds a new zap flag to enable the user to specify the timeformat to be used in the operator log output. By default this is "unix" and left unchanged, but the user can now specify --zap-timeformat=iso8601 and the zap encoder will be configured to output in the more human-friendly time format.

Motivation for the change:
During development, I wanted to be able to look at the logs output by operator and immediately understand the time that each log occurred. Having logs in unix format means that I couldn't do this, so I created this PR which will allow the user to specify their timeformat choice by flag.

@openshift-ci-robot openshift-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 7, 2019
@openshift-ci-robot
Copy link

Hi @otakumike. Thanks for your PR.

I'm waiting for a operator-framework or openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@openshift-ci-robot openshift-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 7, 2019
@lilic
Copy link
Member

lilic commented Jun 7, 2019

/ok-to-test

@openshift-ci-robot openshift-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 7, 2019
@lilic
Copy link
Member

lilic commented Jun 7, 2019

I can't seem to find this in any zap docs, the zap-timeformat, can you link the docs here thanks! :)

pkg/log/zap/flags.go Outdated Show resolved Hide resolved
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

Does this flag work in conjuction with the --zap-encoder flag?

Since we call jsonEncoder() and consoleEncoder() in the encoderValue.Set function, it seems like there could be a situation where we set the encoder before we set the time format.

If so, maybe we could change encoderValue to have a function that returns the encoder:

type encoderValue struct {
	set     bool
	getEncoder func(zapcore.TimeEncoder) zapcore.Encoder
	str     string
}

Then in getConfig() we can actually call that function and pass in timeformatVal.timeEncoder

WDYT?

pkg/log/zap/flags.go Outdated Show resolved Hide resolved
pkg/log/zap/flags.go Outdated Show resolved Hide resolved
@joelanford joelanford self-assigned this Jun 10, 2019
@joelanford
Copy link
Member

@otakumike Just following up to see if you think you'll be able to address the PR comments?

@ironmike-au
Copy link
Contributor Author

Yes, I plan to have a look at it this week. I wasn't expecting anyone to come to me so quickly :)

@joelanford
Copy link
Member

@otakumike Sounds good! No worries. This looks like a nice feature addition, so I just wanted to pop it to the top of the stack so we don't lose track of it.

@ironmike-au
Copy link
Contributor Author

I can't seem to find this in any zap docs, the zap-timeformat, can you link the docs here thanks! :)

As far as I can tell it isn't documented anywhere. I've only been able to figure out the little bit I have by reviewing the undocumented timeformat stuff in their code.

@ironmike-au
Copy link
Contributor Author

Thank you very much for all your feedback. I think everything is all set to go now, but please let me know if I can do anything else?

pkg/log/zap/flags.go Show resolved Hide resolved
doc/user/logging.md Outdated Show resolved Hide resolved
pkg/log/zap/flags.go Outdated Show resolved Hide resolved
ironmike-au and others added 2 commits June 13, 2019 14:26
Co-Authored-By: Joe Lanford <joe.lanford@gmail.com>
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 13, 2019
Co-Authored-By: Joe Lanford <joe.lanford@gmail.com>
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

This is shaping up very nicely. Thanks for taking this on!

pkg/log/zap/logger.go Show resolved Hide resolved
pkg/log/zap/flags.go Show resolved Hide resolved
pkg/log/zap/logger_test.go Show resolved Hide resolved
pkg/log/zap/flags.go Outdated Show resolved Hide resolved
pkg/log/zap/flags.go Outdated Show resolved Hide resolved
pkg/log/zap/flags.go Outdated Show resolved Hide resolved
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 18, 2019
@joelanford
Copy link
Member

I haven't had time to look at the most recent round of updates, but I should be able to later this week. I'll review the current tests to see if I see an easy way to incorporate testing of this new flag.

If there isn't one, another team member or I could build on your existing PR to refactor the tests, or we could add some TODOs in the existing tests and come back around to them in a separate PR.

@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 25, 2019
@ironmike-au
Copy link
Contributor Author

Hey @joelanford just wondering if there's anything more I can do on this one?

@joelanford
Copy link
Member

@otakumike Sorry for the delay on this. I've been on vacation and travelling basically all of this month. Let me take another look and get back to you. Hopefully I'll actually have time this week 🤞

@joelanford
Copy link
Member

@otakumike I just pushed some updates to your PR that adds the extra encoder tests (and makes a couple of other minor improvements I ran across while I was at it). Thanks for the tip on using the encoders to actually encode an entry as part of the test. That seems to do the trick.

Let me know what you think. If it looks good to you, I'll ping some other folks on the team to get more reviews, but this should be very close now. Thanks again for the patience!

Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

LGTM as soon as CI passes

@ironmike-au
Copy link
Contributor Author

@joelanford LGTM. Hope you had a good holiday :)

Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/lgtm

@otakumike thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants