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

Refactors Logging to use the zapr implementation of go-logr/logr #126

Merged
merged 2 commits into from
Feb 22, 2019

Conversation

danehans
Copy link
Contributor

The current logging implementation (Logrus), does not implement the logr interface used by controller-runtime. This PR refactors logging to use the zapr implementation of logr so cluster-ingress-operator logging is compatible with controller-runtime logging.

@openshift-ci-robot openshift-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 18, 2019
Copy link
Contributor

@ironcladlou ironcladlou 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 pretty cool, few things:

  1. Please split the dependency changes (vendor/, Gopkg.*) into a separate commit
  2. Is it okay to use spaces in key names, like zone id? Any benefit in starting some convention around names there (e.g. alpha, -, _ only)?
  3. I don't see where you've introduced a controller-runtime SetLogger call, which is needed to get the framework logs flowing

@danehans
Copy link
Contributor Author

@ironcladlou thank you for the feedback. I'll split the dep changes to a separate commit.

Is it okay to use spaces in key names, like zone id? Any benefit in starting some convention around names there (e.g. alpha, -, _ only)?

The interface doc states nothing about the use of spaces in key names. The zapr example uses a space in the key name. I also found the controller-runtime uses a space in the following key name:

log.Info("Starting workers", "controller", c.Name, "worker count", c.MaxConcurrentReconciles)

I don't see where you've introduced a controller-runtime SetLogger call, which is needed to get the framework logs flowing

I'll update the PR with the controller-runtime SetLogger introduced.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 18, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 18, 2019
pkg/log/log.go Outdated

// Set a concrete logging implementation for all
// controller-runtime deferred Loggers.
log.SetLogger(Logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of a nit, but init() can be difficult to reason about. Alternative is to extract SetLogger() out to the entrypoint in main.go... as it stands, controller-runtime logging will only be wired if you happen to import our internal logging package, and if you wanted to reconfigure controller-runtime logging in a different context (e.g. tests) you would have to be careful about package loading order relative to your own SetLogger call which will compete with package init.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your feedback. I'm working on refactoring using a slightly different approach that you suggestion. I look forward to seeing what you have to say.

@danehans danehans force-pushed the zapr branch 2 times, most recently from b53b322 to 3c6a52d Compare February 19, 2019 19:31
@@ -38,6 +37,13 @@ const (
ClusterIngressFinalizer = "ingress.openshift.io/default-cluster-ingress"
)

var log = logf.Logger.WithName("cluster-ingress-controller")

func init() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to shift the problem around. Use case: we decide to add a new controller in a sibling package (we actually want to do this for status calc). Either we duplicate the init boilerplate in the new controller package (unnecessary and conflicting calls to SetRuntimeLogger), or contexts in which it would make sense to use just one of the controllers (a test) would have to import this other controller's package to enable logging (confusing).

If logging is wired at a layer above the controller-runtime consumers (e.g. controllers), say at the entrypoint, or maybe the operator package, then we can freely add new controller-runtime consumers without having to deal with package-scoped wiring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah... that makes sense. I thought I would have to call SetLogger in the controller pkg too, but I was wrong.

@danehans
Copy link
Contributor Author

/test e2e-aws-operator

@danehans
Copy link
Contributor Author

/retest

@ironcladlou
Copy link
Contributor

Thanks for making such quick work of this! Can tweak in followups (e.g. the weird filename logging quirk).

/approve
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 21, 2019
@ironcladlou
Copy link
Contributor

/retest

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danehans, ironcladlou

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 21, 2019
@danehans
Copy link
Contributor Author

@ironcladlou here are the zapr logs with the calling function's file name and line number removed from messages.

@ironcladlou
Copy link
Contributor

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants