Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

log: support change the level of etcd for debugging #992

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions dm/master/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,22 @@ func parseURLs(s string) ([]url.URL, error) {
return urls, nil
}

func genEmbedEtcdConfigWithLogger() *embed.Config {
func genEmbedEtcdConfigWithLogger(logLevel string) *embed.Config {
cfg := embed.NewConfig()
cfg.EnableGRPCGateway = true // enable gRPC gateway for the internal etcd.

// use zap as the logger for embed etcd
// NOTE: `genEmbedEtcdConfig` can only be called after logger initialized.
// NOTE: if using zap logger for etcd, must build it before any concurrent gRPC calls,
// otherwise, DATA RACE occur in NewZapCoreLoggerBuilder and gRPC.
// NOTE: we can only increase the log level for the clone logger but not decrease.
logger := log.L().WithFields(zap.String("component", "embed etcd")).WithOptions(zap.IncreaseLevel(zap.ErrorLevel))
cfg.ZapLoggerBuilder = embed.NewZapCoreLoggerBuilder(logger, logger.Core(), log.Props().Syncer) // use global app props.
logger := log.L().WithFields(zap.String("component", "embed etcd"))
// if logLevel is info, set etcd log level to WARN to reduce log
if strings.ToLower(logLevel) == "info" {
log.L().Info("Set log level of etcd to `warn`, if you want to log more message about etcd, change log-level to `debug` in master configuration file")
logger.Logger = logger.WithOptions(zap.IncreaseLevel(zap.WarnLevel))
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's log this change to tell user. and "debug" maybe a level lower than "info"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add log in 6d12af4
user can use debug level to see more log about etcd.

}

cfg.ZapLoggerBuilder = embed.NewZapCoreLoggerBuilder(logger.Logger, logger.Core(), log.Props().Syncer) // use global app props.
Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure why change logger to logger.Logger

Copy link
Collaborator Author

@GMHDBJD GMHDBJD Sep 4, 2020

Choose a reason for hiding this comment

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

type of logger now is log.Logger after

logger := log.L().WithFields(zap.String("component", "embed etcd")).WithOptions(zap.IncreaseLevel(zap.ErrorLevel))
change. The type should be log.Logger.logger here.

cfg.Logger = "zap"

// TODO: we run ZapLoggerBuilder to set SetLoggerV2 before we do some etcd operations
Expand Down
6 changes: 3 additions & 3 deletions dm/master/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (t *testEtcdSuite) TestStartEtcdFail(c *check.C) {
c.Assert(cfgCluster.adjust(), check.IsNil)

// start an etcd cluster
cfgClusterEtcd := genEmbedEtcdConfigWithLogger()
cfgClusterEtcd := genEmbedEtcdConfigWithLogger("info")
cfgClusterEtcd, err := cfgCluster.genEmbedEtcdConfig(cfgClusterEtcd)
c.Assert(err, check.IsNil)
e, err := startEtcd(cfgClusterEtcd, nil, nil, 3*time.Second)
Expand All @@ -71,7 +71,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) {
cfgCluster.AdvertiseAddr = tempurl.Alloc()[len("http://"):]
cfgCluster.PeerUrls = tempurl.Alloc()
c.Assert(cfgCluster.adjust(), check.IsNil)
cfgClusterEtcd := genEmbedEtcdConfigWithLogger()
cfgClusterEtcd := genEmbedEtcdConfigWithLogger("info")
cfgClusterEtcd, err := cfgCluster.genEmbedEtcdConfig(cfgClusterEtcd)
c.Assert(err, check.IsNil)

Expand Down Expand Up @@ -178,7 +178,7 @@ func (t *testEtcdSuite) TestPrepareJoinEtcd(c *check.C) {
c.Assert(err, check.ErrorMatches, ".*fail to join embed etcd: there is a member that has not joined successfully, continue the join or remove it.*")

// start the joining etcd
cfgAfterEtcd := genEmbedEtcdConfigWithLogger()
cfgAfterEtcd := genEmbedEtcdConfigWithLogger("info")
cfgAfterEtcd, err = cfgAfter.genEmbedEtcdConfig(cfgAfterEtcd)
c.Assert(err, check.IsNil)
e2, err := startEtcd(cfgAfterEtcd, nil, nil, etcdStartTimeout)
Expand Down
2 changes: 1 addition & 1 deletion dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func NewServer(cfg *Config) *Server {

// Start starts to serving
func (s *Server) Start(ctx context.Context) (err error) {
etcdCfg := genEmbedEtcdConfigWithLogger()
etcdCfg := genEmbedEtcdConfigWithLogger(s.cfg.LogLevel)
// prepare config to join an existing cluster
err = prepareJoinEtcd(s.cfg)
if err != nil {
Expand Down