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

create DefaultFieldsFormatter and inject component into all prow messages #6850

Merged
merged 1 commit into from
Feb 15, 2018

Conversation

BenTheElder
Copy link
Member

I had this idea when working on the bazel remote cache server: Wrap the logrus formatter with one that injects default fields so we can use the logrus.Fields{"component": "tide"} pattern across all log messages within a binary.

I've created a small package implementing this and migrated all of the prow components to use it and standardized the logging a bit.

/area prow

@k8s-ci-robot k8s-ci-robot added area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 15, 2018
@BenTheElder
Copy link
Member Author

This also eliminates most of the *logrus.Entry passing since we were only using it in effect to do this with the side effect of applying it to more messages.

@BenTheElder
Copy link
Member Author

/assign @cjwagner @Kargakis @stevekuznetsov

*/

// Package logrusutil implements some helpers for using logrus
package logrusutil
Copy link
Member Author

Choose a reason for hiding this comment

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

the interesting part is in this package, the rest is just migrating everything to it.

@BenTheElder
Copy link
Member Author

Side note: I've deployed this for the bazel cache experiment (not prow) because it also fixes a bug in the DefaultFormatter... 😬

Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

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

/lgtm
/hold
Feel free to ignore my nit. This change is great!

@@ -79,7 +84,7 @@ func main() {
kubeClients[alias] = kubeClient(client)
}
c := controller{
logger: logger,
logger: logrus.WithFields(logrus.Fields{}),
Copy link
Member

Choose a reason for hiding this comment

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

logrus.NewEntry(logrus.StandardLogger())

Copy link
Member Author

Choose a reason for hiding this comment

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

done 👍

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Feb 15, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BenTheElder, cjwagner

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:
  • OWNERS [BenTheElder,cjwagner]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

// DefaultFields into each Format() call, existing fields are preserved
// if they have the same key
type DefaultFieldsFormatter struct {
WrappedFormatter logrus.Formatter
Copy link
Member

Choose a reason for hiding this comment

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

We could make this default to the JSON formatter if it is nil.

Copy link
Member Author

@BenTheElder BenTheElder Feb 15, 2018

Choose a reason for hiding this comment

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

OK how about we have NewDefaultFieldsFormatter(wrapped logrus.Formatter, defaultFields logrus.Fields) and default to json if wrapped is nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

done, switched to this everywhere

@BenTheElder
Copy link
Member Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 15, 2018
@k8s-ci-robot k8s-ci-robot merged commit 62f4e28 into kubernetes:master Feb 15, 2018
@BenTheElder BenTheElder deleted the default-logrus branch February 15, 2018 23:37
@cjwagner cjwagner mentioned this pull request Feb 16, 2018
@stevekuznetsov
Copy link
Contributor

Cool!

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. area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

5 participants