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

Refactor logging configuration #1699

Merged
merged 3 commits into from
Sep 11, 2019
Merged

Conversation

charith-elastic
Copy link
Contributor

This change does the following:

  • Allow logging verbosity levels to be configured from the command-line (log.V(2) etc. should actually work as intended now)
  • Output the timestamp in ISO8601 format (Operator logs in unix epoch timestamps but would prefer iso8601/rfc3339 #1587)
  • Change log message key to message (StackDriver logging can render logs nicely if this key exists)
  • Change timestamp key to @timestamp
  • Add the ver key to report operator version in log lines
  • Propagate log verbosity to E2E tests

As we are currently on controller-runtime v0.1, log.InitLogger is much more complicated than it needs to be. When we migrate to controller-runtime v0.2 it can be simplified.

The suggestion in #1587 to be compatible with ECS logging format by renaming logger to log.level and level to log.level didn't seem to add much benefit at this point so I have left the shorter keys in place to aid readability.

Fixes #1587

@charith-elastic charith-elastic added >enhancement Enhancement of existing functionality v1.0.0-beta1 >refactoring labels Sep 9, 2019
}
}

func getVersionString() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the pkg/controller/common/version package might be what you want here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC the version package only contains functions for parsing a version string into constituent parts. I am just trying to concatenate the version string with the build hash here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah my bad I was translating hash to label in my head

@anyasabo
Copy link
Contributor

anyasabo commented Sep 9, 2019

Allow logging verbosity levels to be configured from the command-line (log.V(2) etc. should actually work as intended now)

Do we want to do this? I thought in #305 we had decided that we only wanted two levels of logging (debug/info), so wonder if I missed a discussion somewhere.

Change log message key to message (StackDriver logging can render logs nicely if this key exists)

👍

Change timestamp key to @timestamp

Can you clarify the reasoning for this one? Is it just so it's rather than ts?

When we migrate to controller-runtime v0.2 it can be simplified.

This might be worth waiting a week to make the change on the kubebuilder v2 feature branch IMO.

@charith-elastic
Copy link
Contributor Author

Allow logging verbosity levels to be configured from the command-line (log.V(2) etc. should actually work as intended now)

Do we want to do this? I thought in #305 we had decided that we only wanted two levels of logging (debug/info), so wonder if I missed a discussion somewhere.

I wasn't aware of the that discussion, thanks for pointing it out. On several occasions I found myself wanting to output things that didn't quite fit the V(1) debug category because they were only useful for development purposes. Having a V(2) would help because then even if those log statements were left in the code accidentally, they wouldn't pollute the log output and it would be obvious to the code readers that those lines can be removed at any time.

Whether the team wants to use levels above 1 or not, I don't think there's any harm in being able to configure the output level from a flag though. WDYT?

Change timestamp key to @timestamp

Can you clarify the reasoning for this one? Is it just so it's rather than ts?

Yes, because @timestamp is a fairly well-known timestamp key than ts and some log processing systems can probably make use of it automatically without user intervention.

When we migrate to controller-runtime v0.2 it can be simplified.

This might be worth waiting a week to make the change on the kubebuilder v2 feature branch IMO.

This will continue to work on v2 it's just that it will have more configuration functions that we can use. Happy to wait if you feel this would add additional complexity to the migration.

pkg/utils/log/log.go Outdated Show resolved Hide resolved
var opts []zap.Option
if dev.Enabled {
encoderConf := zap.NewDevelopmentEncoderConfig()
encoderConf.EncodeLevel = zapcore.CapitalColorLevelEncoder
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to have colors :)

pkg/utils/log/log.go Outdated Show resolved Hide resolved
pkg/utils/log/log.go Outdated Show resolved Hide resolved
pkg/utils/log/log.go Outdated Show resolved Hide resolved
@charith-elastic
Copy link
Contributor Author

Docs build is failing due to this change: elastic/docs#1172
I'll raise a separate issue to fix it.

@sebgl
Copy link
Contributor

sebgl commented Sep 10, 2019

On several occasions I found myself wanting to output things that didn't quite fit the V(1) debug category because they were only useful for development purposes. Having a V(2) would help because then even if those log statements were left in the code accidentally, they wouldn't pollute the log output and it would be obvious to the code readers that those lines can be removed at any time.
Whether the team wants to use levels above 1 or not, I don't think there's any harm in being able to configure the output level from a flag though. WDYT?

+1 with that, I also find myself wanting a V(2) in some situations. Mostly for logs that are pure debugging (sometimes JSON dumps), which I consider different from V(1) that reports what's going on.
Also agree on how having V(2) available does not prevent us from using V(1) in most situations.

Copy link
Contributor

@sebgl sebgl left a comment

Choose a reason for hiding this comment

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

LGTM 👍
Looking forward to the reconciliation with controller-runtime v0.2.

Copy link
Contributor

@david-kow david-kow left a comment

Choose a reason for hiding this comment

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

One question, LGTM otherwise.


var (
verbosity = flag.Int("log-verbosity", 0, "Verbosity level of logs (-2=Error, -1=Warn, 0=Info, >0=Debug)")
enableDebugLogs = flag.Bool("enable-debug-logs", false, "Enable debug logs")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still needed? It seems to only be used to enable the same behavior as verbosity flag does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mainly kept it for backward compatibility as we have documented it in the troubleshooting docs and it's much more obvious to a casual user what enable-debug-logs would do compared to log-verbosity=1

Copy link
Contributor

@anyasabo anyasabo Sep 10, 2019

Choose a reason for hiding this comment

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

Agreed, we probably don't want multiple ways to do the same thing. But I could definitely be missing a use case

encoderConf := zap.NewProductionEncoderConfig()
encoderConf.MessageKey = "message"
encoderConf.TimeKey = "@timestamp"
encoderConf.EncodeTime = zapcore.ISO8601TimeEncoder
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

@@ -76,7 +79,7 @@ dep:

dep-vendor-only:
# don't attempt to upgrade Gopkg.lock
dep ensure --vendor-only
dep ensure --vendor-only
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@anyasabo
Copy link
Contributor

Having a V(2) would help because then even if those log statements were left in the code accidentally, they wouldn't pollute the log output and it would be obvious to the code readers that those lines can be removed at any time.

I don't really run into this much personally. I think if we do want this we will probably want to update the troubleshooting or development docs to make it clear what the difference is between log levels and how to use them.

@anyasabo
Copy link
Contributor

This will continue to work on v2 it's just that it will have more configuration functions that we can use. Happy to wait if you feel this would add additional complexity to the migration.

Ah cool, the initialization code is getting heavily reworked atm but it looks like it should just be adding a flag so I think we're good from that perspective

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement Enhancement of existing functionality >refactoring v1.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Operator logs in unix epoch timestamps but would prefer iso8601/rfc3339
5 participants