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 context to logs, set default log level to info #121

Merged
merged 6 commits into from
Jul 20, 2022

Conversation

mh013370
Copy link
Member

@mh013370 mh013370 commented Jul 18, 2022

Q A
Bug fix? no
New feature? no
API breaks? no
Deprecations? no
Related tickets partially #109
License Apache 2.0

What's in this PR?

This PR aims to begin refactoring nifikop logging to be much less verbose and more informational. Specifically, I attempted to do all of the following in this PR:

  • Convert all log.Info(fmt.Sprintf("...")) occurrences to log.Info("...", zap.String("...", var))
  • Add as much context as possible to each log message. For example, which NifiCluster the log is in relation to, nodeId, k8s object name or namespace, etc.
  • Set default log level to Info
  • Drop common logs that aren't crucial to be aware of to debug level

I've identified several other areas that warrant refactoring to clean up logs, but will leave these for later PRs to keep PR scope small.

For example, the below link refers to this RequeueWithError() method, which is called 500+ times as a result of an error but it logs all of the error messages at the Info level. There's no context for what the error was, so it's not possible to know what context should be added to the log. Callers right now provide a parameter that's formatted with fmt.Sprintf("..."), but we can make use of the zap lib to consistently log errors. Callers should log the context for the error and then requeue the request.

https://github.com/konpyutaika/nifikop/blob/v0.11.0-release/controllers/controller_common.go#L24-L28

Why?

This is a part of a larger effort to increase the quality of logs generated by nifikop.

Checklist

  • Implementation tested
  • Error handling code meets the guideline
  • Logging code meets the guideline
  • User guide and development docs updated (if needed)
  • Append changelog with changes

Copy link
Contributor

@r65535 r65535 left a comment

Choose a reason for hiding this comment

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

Tested locally, with a NifiCluster and NifiDataflow.
Log content is much better with the added context, and logLevels are more in line with what I expect when using an operator.

@erdrix erdrix merged commit 08b836e into konpyutaika:master Jul 20, 2022
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.

3 participants