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

logger interface package #31403

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
6 participants
@mjibson
Member

mjibson commented Oct 15, 2018

No description provided.

@mjibson mjibson requested review from benesch and tschottdorf Oct 15, 2018

@mjibson mjibson requested review from cockroachdb/cli-prs as code owners Oct 15, 2018

@cockroach-teamcity

This comment has been minimized.

Show comment
Hide comment
@cockroach-teamcity

cockroach-teamcity Oct 15, 2018

Member

This change is Reviewable

Member

cockroach-teamcity commented Oct 15, 2018

This change is Reviewable

@mjibson mjibson requested review from cockroachdb/sql-ccl-prs as code owners Oct 15, 2018

@benesch

:lgtm_strong: but please wait for at least @tschottdorf's review, and maybe @bdarnell's too?

Reviewed 2 of 2 files at r1, 56 of 56 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained


pkg/util/log/logger/logger.go, line 35 at r1 (raw file):

	SetExitFunc(hideStack bool, f func(int))
	// Warningf logs to the WARNING and INFO logs.
	Warningf(ctx context.Context, format string, args ...interface{})

Seems worth including Errorf and Infof, because we'll definitely need those soon.

I also think we should exclude ResetExitFunc() and SetExitFunc(...). Those are hideous functions. In the HLC tests that need them, I think you should create a concrete logger, and just call SetExitFunc on that custom logger. Eventually we won't even need either of these functions, since we can just install the exit function when we create the logger. Hooray for testable code without global mutable state!


pkg/util/log/logger/logger.go, line 20 at r2 (raw file):

import "context"

// Log defines a logger.

nit: wrong commit

@danhhz

This comment has been minimized.

Show comment
Hide comment
@danhhz

danhhz Oct 15, 2018

Contributor

Is that plan that we'll migrate every usage of log to this at some point? If so, in the spirit of ben's recent refactor email, I'd love to hold off merging until cdc is no longer actively cherrypicking literally every commit.

Contributor

danhhz commented Oct 15, 2018

Is that plan that we'll migrate every usage of log to this at some point? If so, in the spirit of ben's recent refactor email, I'd love to hold off merging until cdc is no longer actively cherrypicking literally every commit.

@bdarnell

This comment has been minimized.

Show comment
Hide comment
@bdarnell

bdarnell Oct 15, 2018

Member

What's the motivation for this? How far will it go? If this is going to turn into another round of adding a parameter to every method (as there was for context.Context), it needs a very strong justification. I don't mind it for isolated cases like this, but I don't like the idea of it spreading to everything that logs.

Member

bdarnell commented Oct 15, 2018

What's the motivation for this? How far will it go? If this is going to turn into another round of adding a parameter to every method (as there was for context.Context), it needs a very strong justification. I don't mind it for isolated cases like this, but I don't like the idea of it spreading to everything that logs.

@petermattis

This comment has been minimized.

Show comment
Hide comment
@petermattis

petermattis Oct 15, 2018

Contributor
Contributor

petermattis commented Oct 15, 2018

@benesch

This comment has been minimized.

Show comment
Hide comment
@benesch

benesch Oct 15, 2018

Member

There was some discussion in #engineering. The justification is twofold. The first reason is that forcing a dependency on util/log forces downstream clients to take a dependency on a logging package they probably don't want to use. util/hlc is actually likely to be quite useful outside of Cockroach. I think you could probably solve this problem with a per-package logger.

The second reason is that we can't run Go tests within a package in parallel right now because every in-process test server shares the same logger. We feel this most acutely in the acceptance package, which has a bunch of tests that are not at all resource intensive but are slow because of Docker. (See #21724 for more context.) I don't think you can solve this particular problem without plumbing a logger to every caller that needs it.

Member

benesch commented Oct 15, 2018

There was some discussion in #engineering. The justification is twofold. The first reason is that forcing a dependency on util/log forces downstream clients to take a dependency on a logging package they probably don't want to use. util/hlc is actually likely to be quite useful outside of Cockroach. I think you could probably solve this problem with a per-package logger.

The second reason is that we can't run Go tests within a package in parallel right now because every in-process test server shares the same logger. We feel this most acutely in the acceptance package, which has a bunch of tests that are not at all resource intensive but are slow because of Docker. (See #21724 for more context.) I don't think you can solve this particular problem without plumbing a logger to every caller that needs it.

@bdarnell

This comment has been minimized.

Show comment
Hide comment
@bdarnell

bdarnell Oct 15, 2018

Member

I'm fine with this change for HLC to make it exportable.

Why exactly does the log singleton prevent you from running tests in parallel? Is it just that the intermingled logs are unintelligible? Parallelizing tests by running child processes might be better than allowing multiple loggers within one process.

Member

bdarnell commented Oct 15, 2018

I'm fine with this change for HLC to make it exportable.

Why exactly does the log singleton prevent you from running tests in parallel? Is it just that the intermingled logs are unintelligible? Parallelizing tests by running child processes might be better than allowing multiple loggers within one process.

@benesch

This comment has been minimized.

Show comment
Hide comment
@benesch

benesch Oct 15, 2018

Member

Why exactly does the log singleton prevent you from running tests in parallel? Is it just that the intermingled logs are unintelligible?

Yes, precisely.

Parallelizing tests by running child processes might be better than allowing multiple loggers within one process.

Yeah, I think this works as long as the only thing under test is the cockroach binary, and everything else in the test is careful to never use util/log. That's not the case today, though: the acceptance test infrastructure itself uses util/log. I guess we could unsingletonize that section of the logging code.

Anyway, it sounds like there is consensus building around doing this for util/hlc and then evaluating future unsingletonization on a case-by-case basis.

Member

benesch commented Oct 15, 2018

Why exactly does the log singleton prevent you from running tests in parallel? Is it just that the intermingled logs are unintelligible?

Yes, precisely.

Parallelizing tests by running child processes might be better than allowing multiple loggers within one process.

Yeah, I think this works as long as the only thing under test is the cockroach binary, and everything else in the test is careful to never use util/log. That's not the case today, though: the acceptance test infrastructure itself uses util/log. I guess we could unsingletonize that section of the logging code.

Anyway, it sounds like there is consensus building around doing this for util/hlc and then evaluating future unsingletonization on a case-by-case basis.

mjibson added some commits Oct 15, 2018

log: add a new logger interface package
The current log package uses global state and depends on the build
package with compiles C. In order to reduce dependencies and also allow
for more than one logger during multi server testing, make a new logger
interface package with common needed logging functions. The hlc package
is the first to gain support for this, so the interface is currently
just what that package needs.

This is done in a way that can be incrementally rolled out to packages
as they need support for it. To do this we have a wrapper around the
global functions.

Release note: None
hlc: require a log.Logger in NewClock
This removes the dependency from hlc on util/log, reducing the number
of dependencies from 212 to 40 (and now only 5 packages outside of
the stdlib).

Release note: None
@mjibson

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained


pkg/util/log/logger/logger.go, line 35 at r1 (raw file):

Previously, benesch (Nikhil Benesch) wrote…

Seems worth including Errorf and Infof, because we'll definitely need those soon.

I also think we should exclude ResetExitFunc() and SetExitFunc(...). Those are hideous functions. In the HLC tests that need them, I think you should create a concrete logger, and just call SetExitFunc on that custom logger. Eventually we won't even need either of these functions, since we can just install the exit function when we create the logger. Hooray for testable code without global mutable state!

Added Errorf and Infof and removed ResetExitFunc and SetExitFunc (which I erroneously included because hlc_test.go used them).

@benesch

Reviewed 57 of 57 files at r3, 55 of 55 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained


pkg/util/log/logger/logger.go, line 31 at r3 (raw file):

	Infof(ctx context.Context, format string, args ...interface{})
	// Warningf logs to the WARNING and INFO logs.
	Warningf(ctx context.Context, format string, args ...interface{})

This is super clean. I love it.

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