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

Commit

Permalink
change etcd level
Browse files Browse the repository at this point in the history
  • Loading branch information
GMHDBJD committed Sep 4, 2020
1 parent 7de7bb4 commit d653065
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions dm/master/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,21 @@ 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" {
logger.Logger = logger.WithOptions(zap.IncreaseLevel(zap.WarnLevel))
}

cfg.ZapLoggerBuilder = embed.NewZapCoreLoggerBuilder(logger.Logger, logger.Core(), log.Props().Syncer) // use global app props.
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

0 comments on commit d653065

Please sign in to comment.