Skip to content

Create loggers in controllers main function.#303

Merged
google-prow-robot merged 13 commits into
knative:masterfrom
n3wscott:add_logging_config
Aug 2, 2018
Merged

Create loggers in controllers main function.#303
google-prow-robot merged 13 commits into
knative:masterfrom
n3wscott:add_logging_config

Conversation

@n3wscott
Copy link
Copy Markdown
Contributor

@n3wscott n3wscott commented Aug 1, 2018

There is a small amount of config that needs to be in our repo to integrate with knative/pkg/logging. This is that config.

Also creating the loggers (but not passing them to the controller impls.)

@google-prow-robot google-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 1, 2018
@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 1, 2018

/assign @mattmoor

Comment thread pkg/logging/config.go Outdated
// If configuration is empty, a fallback configuration is used.
// If configuration cannot be used to instantiate a logger,
// the same fallback configuration is used.
func NewLogger(configJSON string, levelOverride string) (*zap.SugaredLogger, zap.AtomicLevel) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why wrap these? Just to avoid repeating components...?

limitations under the License.
*/

package logkey
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about putting just this and the yaml in pkg/logconfig (and then callers would import knative/pkg/logging and knative/eventing/pkg/logconfig)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you may hate the new change more... Lets see. I moved the relevant keys to apis.

@evankanderson
Copy link
Copy Markdown
Member

/assign evankanderson
/unassign mattmoor

@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-go-coverage to run the coverage report again

File Old Coverage New Coverage Delta
pkg/logging/logger.go Do not exist 100.0%
pkg/logging/config.go Do not exist 80.0%

@n3wscott n3wscott changed the title Add logging config Create loggers in controllers. Aug 1, 2018
@n3wscott n3wscott changed the title Create loggers in controllers. Create loggers in controllers main function. Aug 1, 2018
@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 1, 2018

Ready. PTAL @evankanderson

@pmorie
Copy link
Copy Markdown
Contributor

pmorie commented Aug 1, 2018

/retest

Comment thread cmd/controller/main.go

// Watch the logging config map and dynamically update logging levels.
configMapWatcher := configmap.NewDefaultWatcher(kubeClient, system.Namespace)
configMapWatcher.Watch(logconfig.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, logconfig.Controller, logconfig.Controller))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That is very cool and will be extremely useful :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm glad you like it :)

Copy link
Copy Markdown
Contributor

@pmorie pmorie left a comment

Choose a reason for hiding this comment

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

LGTM, one thing I noticed

@@ -44,10 +56,46 @@ type ProvideFunc func(manager.Manager) (controller.Controller, error)

func main() {
flag.Parse()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not an issue w/ your PR, but we should consider renaming these binaries slightly; 'controller' runs the bus controllers and 'controller-manager' runs the flow, feed, etc controllers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll create an issue for this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have some code that combines these into a single deployment, but haven't PR'd it: master...grantr:combine-controllers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread cmd/controller-manager/main.go Outdated
if err != nil {
log.Fatalf("Error parsing logging configuration: %v", err)
}
logger, atomicLevel := logging.NewLoggerFromConfig(config, logconfig.ControllerManager)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

where do we use atomicLevel?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

configMapWatcher.Watch(logging.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, logLevelKey))


// Watch the logging config map and dynamically update logging levels.
configMapWatcher := configmap.NewDefaultWatcher(kubeClient, system.Namespace)
configMapWatcher.Watch(logconfig.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, logconfig.ControllerManager, logconfig.ControllerManager))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice to be able to encapsulate the 35 new lines in pkg/logging, but I think that's a follow-on PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree. Had the same thought as I was adding this.

Comment thread cmd/controller-manager/main.go Outdated

// Setup a Manager
mrg, err := manager.New(config.GetConfigOrDie(), manager.Options{})
mrg, err := manager.New(clientconfig.GetConfigOrDie(), manager.Options{})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I presume this rename is to distinguish from logconfig?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes but it could go back now...

Comment thread cmd/controller/main.go
defer cancel()
srv.Shutdown(ctx)

glog.Flush()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hah, I think you caught a bug here. Nice!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

💃


logger.Info("Starting the Controller Manager")

logf.SetLogger(logf.ZapLogger(false))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a comment that this doesn't do anything yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@grantr for details, this does nothing yet right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This tells controller-runtime to use zap to log internal messages. We could eventually use the https://github.com/go-logr/logr abstraction for controller logging also, but there's no need for it right now.

volumeMounts:
- name: config-logging
mountPath: /etc/config-logging
volumes:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like we're both mounting a ConfigMap, and using the k8s watcher on the ConfigMap object (because you're feeding in a k8s client). We should just be able to use inotify on the file:

https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#mounted-configmaps-are-updated-automatically

https://github.com/fsnotify/fsnotify looks promising.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The autoscaling group found that inotify on configmaps is very slow, normally taking 30+ seconds to propagate updates to volumes. I think we can probably drop the volume mount now that we have the configmap watch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

do tell more !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I vote make this an issue and do a followup pass. Having loggers is more valuable than optimizing i think

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this was intended to be a followup, not a blocker.

@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 2, 2018

/test pull-knative-eventing-integration-tests

@n3wscott
Copy link
Copy Markdown
Contributor Author

n3wscott commented Aug 2, 2018

Ready to go in @evankanderson PTAL?

Copy link
Copy Markdown
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

One minor nit, but it doesn't block getting this in.

log.Fatalf("Error parsing logging configuration: %v", err)
}
logger, atomicLevel := logging.NewLoggerFromConfig(config, logconfig.ControllerManager)
logger, atomicLevel := logging.NewLoggerFromConfig(cfg, logconfig.ControllerManager)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we use atomicLevel anywhere? If not, should we name it "_"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is used in the watch call

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 2, 2018
@google-prow-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, n3wscott

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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

@google-prow-robot google-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 2, 2018
@grantr
Copy link
Copy Markdown
Contributor

grantr commented Aug 2, 2018

/retest

@google-prow-robot google-prow-robot merged commit adc94e8 into knative:master Aug 2, 2018
@grantr grantr mentioned this pull request Aug 3, 2018
n3wscott added a commit to n3wscott/eventing that referenced this pull request Aug 3, 2018
* Starting to add webhook.

* Adding logging config for eventing to be used with knative/pkg/logging.

* Revert webhook change.

* Revert webhook change.

* Add a test to make sure happy path is happy for getting logger in eventing.

* Adding config-logging to the main config.

* Remove owners file.

* Moving to just use named loggers in the controllers.

* Use logging config for controller name.

* Add newlines to the yaml.

* Adding logging creation and config reading to the controllers now.

* Don't dep on glog in cmd.

* Cleanup based on review.
n3wscott added a commit to n3wscott/eventing that referenced this pull request Aug 3, 2018
* Starting to add webhook.

* Adding logging config for eventing to be used with knative/pkg/logging.

* Revert webhook change.

* Revert webhook change.

* Add a test to make sure happy path is happy for getting logger in eventing.

* Adding config-logging to the main config.

* Remove owners file.

* Moving to just use named loggers in the controllers.

* Use logging config for controller name.

* Add newlines to the yaml.

* Adding logging creation and config reading to the controllers now.

* Don't dep on glog in cmd.

* Cleanup based on review.
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.

7 participants