Skip to content

pkg/assets/create: Replace Verbose and StdErr with Logger#225

Closed
wking wants to merge 2 commits intoopenshift:masterfrom
wking:logging-interface
Closed

pkg/assets/create: Replace Verbose and StdErr with Logger#225
wking wants to merge 2 commits intoopenshift:masterfrom
wking:logging-interface

Conversation

@wking
Copy link
Copy Markdown
Member

@wking wking commented Feb 5, 2019

To allow consumers to plug in their preferred logger instead of requring an output stream. I'm using go-log/log as an unopinionated interface, which callers can feed with the stdlib's log package, logrus, etc. depending on their logging preferences.

CC @mfojtik, @sttts

wking added 2 commits February 5, 2019 10:00
To allow consumers to plug in their preferred logger instead of
requring an output stream.  I'm using go-log/log [1] as an
unopinionated interface, which callers can feed with the stdlib's log
package, logrus, etc. depending on their logging preferences.

[1]: https://github.com/go-log/log
Generated with:

  $ alpha-build-machinery/scripts/update-deps.sh

Also bring in stretchr/testify/assert for convenient test assertion.

The the bumps to the other libraries are because Glide.yaml is
floating them at master or their indirect dependencies.
@openshift-merge-robot
Copy link
Copy Markdown
Contributor

/retest

@mfojtik
Copy link
Copy Markdown
Contributor

mfojtik commented Feb 6, 2019

We should not import new package here, instead we can create the interface here and plug whatever we need there (the interfaces are exchangeable). I would just copy https://github.com/go-log/log/blob/master/log.go#L5 at the top of the create.go


if options.Verbose && options.StdErr == nil {
options.StdErr = os.Stderr
if options.Logger == nil {
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.

If the options.Logger is not set, just don't log anything or create some dummy implementation of Logger interface?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If the options.Logger is not set, just don't log anything or create some dummy implementation of Logger interface?

The default I'm plugging in in this block is a no-op logger unless the user set that package-level global.

@tnozicka
Copy link
Copy Markdown
Contributor

tnozicka commented Feb 6, 2019

/hold

The whole org uses glog for very clear reason, because the whole k8s apimachinery and client-go is tightly coupled to it. Using more then 1 logger is a lost of time and will not work given the hardcoded glog in k8s. You just don't use 2 loggers in 1 project.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 6, 2019
@tnozicka
Copy link
Copy Markdown
Contributor

tnozicka commented Feb 6, 2019

/cc @deads2k

@sttts
Copy link
Copy Markdown
Contributor

sttts commented Feb 6, 2019

Decoupling the code from glog is fine, but not by pulling in another package. Let's just abstract with a local interface and every consumer can plug a wrapper in for his/her favourite logger.

@tnozicka
Copy link
Copy Markdown
Contributor

tnozicka commented Feb 6, 2019

Making more loggers configurable is work that could have been better spent on important things, same goes for reviews.

In the end the same statement applies for logging in the end component, if it doesn't use glog.

(note: I personally don't like glog at all, but I understand the necessity of using it implied by being hardcoded in k8s.)

@wking
Copy link
Copy Markdown
Member Author

wking commented Feb 6, 2019

The whole org uses glog for very clear reason...

The installer inherited logrus. I don't see it consuming this code directly, but I also don't see a need for opinionated logging in libraries. However, I can reroll to take glog (or klog?) types if folks don't like the interface approach.

We should not import new package here, instead we can create the interface here and plug whatever we need there (the interfaces are exchangeable).

Why copy/paste this (and the no-op implementation), when they're already written and can be vendored? Seems easier to maintain that way, and if your vendor tooling pruned unused packages it would be about the same amount of code either way.

@wking
Copy link
Copy Markdown
Member Author

wking commented Feb 6, 2019

Also, lots of Kubernetes library log handling discussion in kubernetes/kubernetes#61006, where interface-based approaches were raised but not accepted (although I'm still not clear on why not).

@soltysh
Copy link
Copy Markdown

soltysh commented Feb 6, 2019

The installer inherited logrus. I don't see it consuming this code directly, but I also don't see a need for opinionated logging in libraries. However, I can reroll to take glog (or klog?) types if folks don't like the interface approach.

Klog will be brought up with 1.13 kubernetes, so I wouldn't bother with that, yet.

Also, lots of Kubernetes library log handling discussion in kubernetes/kubernetes#61006, where interface-based approaches were raised but not accepted (although I'm still not clear on why not).

That's one of the reasons klog happened, it might be a road towards just that, we'll see.

"time"

"github.com/ghodss/yaml"
"github.com/go-log/log"
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.

no new logging dep. Project standard is glog and we'll switch to klog with kube.

if options.Verbose {
fmt.Fprintf(options.StdErr, "[#%d] failed to fetch discovery: %s\n", retryCount, err)
}
options.Logger.Logf("[#%d] failed to fetch discovery: %s", retryCount, err)
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.

project standard upstream and downstream is fmt.printf for CLI and glog for everything else. The previous code is in keeping.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

project standard upstream and downstream is fmt.printf for CLI and glog for everything else. The previous code is in keeping.

But this is library code, so I'd expect glog over fmt, 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.

@wking depends on the caller of this code. So far it is cluster-bootstrap which is a command we run during the bootstrap (so it is CLI ;-). I'm fine switching this to glog, was trying to avoid importing glog because I know that some components/cli have problem with parsing glog flags (so wanted to avoid that if not necessary).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

depends on the caller of this code. So far it is cluster-bootstrap which is a command we run during the bootstrap (so it is CLI ;-).

I don't think code in library-go should have API choices hinge on "we know all of our consumers, and they're not libraries themselves". Is there a reason that approach is not as brittle as it seems?

I'm fine switching this to glog, was trying to avoid importing glog because I know that some components/cli have problem with parsing glog flags (so wanted to avoid that if not necessary).

Like openshift/installer#1181. This is exactly why I prefer logging interfaces, but it sounds like that's a no-go?

@deads2k
Copy link
Copy Markdown
Contributor

deads2k commented Feb 6, 2019

/hold

@wking
Copy link
Copy Markdown
Member Author

wking commented Feb 7, 2019

Hrm. I went to reroll this to use glog as requested by @tnozicka here @deads2k here. But I'm stuck with collecting the logs for unit tests. Should I drop those tests? Should I have init code set -log_dir and collect the test logs there? Should I add an interface after all so the test suite can plug in a capture implementation (but with copies to local code, and not the vendored capture implementation I'm currently using as of 673e3d3?)?

@openshift-ci-robot
Copy link
Copy Markdown

@wking: PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@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 9, 2019
@openshift-ci-robot
Copy link
Copy Markdown

@wking: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/verify-deps 673e3d3 link /test verify-deps

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-bot
Copy link
Copy Markdown

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci-robot openshift-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 24, 2020
@openshift-bot
Copy link
Copy Markdown

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

@openshift-ci-robot openshift-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 25, 2020
@openshift-bot
Copy link
Copy Markdown

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-ci-robot
Copy link
Copy Markdown

@openshift-bot: Closed this PR.

Details

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.

9 participants