From 628ec8472bc64acf1f84aca4a5d55e39d8500c85 Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Fri, 10 Apr 2020 20:45:03 +0800 Subject: [PATCH] Refine log when enable tls (#951) --- drainer/config.go | 9 ++++++-- drainer/server.go | 48 +++++++++++++++++++++------------------- pump/config.go | 9 ++++++-- pump/server.go | 56 ++++++++++++++++++++++++----------------------- 4 files changed, 68 insertions(+), 54 deletions(-) diff --git a/drainer/config.go b/drainer/config.go index 4b473726e..8eda0d31f 100644 --- a/drainer/config.go +++ b/drainer/config.go @@ -326,8 +326,13 @@ func (cfg *Config) adjustConfig() error { // adjust configuration util.AdjustString(&cfg.ListenAddr, util.DefaultListenAddr(8249)) util.AdjustString(&cfg.AdvertiseAddr, cfg.ListenAddr) - cfg.ListenAddr = "http://" + cfg.ListenAddr // add 'http:' scheme to facilitate parsing - cfg.AdvertiseAddr = "http://" + cfg.AdvertiseAddr // add 'http:' scheme to facilitate parsing + if cfg.tls != nil { + cfg.ListenAddr = "https://" + cfg.ListenAddr // add 'https:' scheme to facilitate parsing + cfg.AdvertiseAddr = "https://" + cfg.AdvertiseAddr // add 'https:' scheme to facilitate parsing + } else { + cfg.ListenAddr = "http://" + cfg.ListenAddr // add 'http:' scheme to facilitate parsing + cfg.AdvertiseAddr = "http://" + cfg.AdvertiseAddr // add 'http:' scheme to facilitate parsing + } util.AdjustString(&cfg.DataDir, defaultDataDir) util.AdjustInt(&cfg.DetectInterval, defaultDetectInterval) diff --git a/drainer/server.go b/drainer/server.go index 631537d77..c4f147f20 100644 --- a/drainer/server.go +++ b/drainer/server.go @@ -59,16 +59,17 @@ type Server struct { host string cfg *Config - collector *Collector - tcpAddr string - gs *grpc.Server - metrics *util.MetricClient - ctx context.Context - cancel context.CancelFunc - tg taskGroup - syncer *Syncer - cp checkpoint.CheckPoint - isClosed int32 + collector *Collector + tcpAddr string + advertiseAddr string + gs *grpc.Server + metrics *util.MetricClient + ctx context.Context + cancel context.CancelFunc + tg taskGroup + syncer *Syncer + cp checkpoint.CheckPoint + isClosed int32 statusMu sync.RWMutex status *node.Status @@ -171,18 +172,19 @@ func NewServer(cfg *Config) (*Server, error) { status := node.NewStatus(cfg.NodeID, advURL.Host, node.Online, 0, syncer.GetLatestCommitTS(), util.GetApproachTS(latestTS, latestTime)) return &Server{ - ID: cfg.NodeID, - host: advURL.Host, - cfg: cfg, - collector: c, - metrics: metrics, - tcpAddr: cfg.ListenAddr, - gs: grpc.NewServer(), - ctx: ctx, - cancel: cancel, - syncer: syncer, - cp: cp, - status: status, + ID: cfg.NodeID, + host: advURL.Host, + cfg: cfg, + collector: c, + metrics: metrics, + tcpAddr: cfg.ListenAddr, + advertiseAddr: cfg.AdvertiseAddr, + gs: grpc.NewServer(), + ctx: ctx, + cancel: cancel, + syncer: syncer, + cp: cp, + status: status, latestTS: latestTS, latestTime: latestTime, @@ -310,7 +312,7 @@ func (s *Server) Start() error { go http.Serve(httpL, nil) - log.Info("start to server request", zap.String("addr", s.tcpAddr)) + log.Info("start to server request", zap.String("addr", s.advertiseAddr)) if err := m.Serve(); !strings.Contains(err.Error(), "use of closed network connection") { return errors.Trace(err) } diff --git a/pump/config.go b/pump/config.go index cf7f7894a..9f8945b58 100644 --- a/pump/config.go +++ b/pump/config.go @@ -164,8 +164,13 @@ func (cfg *Config) Parse(arguments []string) error { util.AdjustString(&cfg.ListenAddr, defaultListenAddr) util.AdjustString(&cfg.AdvertiseAddr, cfg.ListenAddr) - cfg.ListenAddr = "http://" + cfg.ListenAddr // add 'http:' scheme to facilitate parsing - cfg.AdvertiseAddr = "http://" + cfg.AdvertiseAddr // add 'http:' scheme to facilitate parsing + if cfg.tls != nil { + cfg.ListenAddr = "https://" + cfg.ListenAddr // add 'https:' scheme to facilitate parsing + cfg.AdvertiseAddr = "https://" + cfg.AdvertiseAddr // add 'https:' scheme to facilitate parsing + } else { + cfg.ListenAddr = "http://" + cfg.ListenAddr // add 'http:' scheme to facilitate parsing + cfg.AdvertiseAddr = "http://" + cfg.AdvertiseAddr // add 'http:' scheme to facilitate parsing + } util.AdjustDuration(&cfg.EtcdDialTimeout, defaultEtcdDialTimeout) util.AdjustString(&cfg.DataDir, defaultDataDir) util.AdjustInt(&cfg.HeartbeatInterval, defaultHeartbeatInterval) diff --git a/pump/server.go b/pump/server.go index 22087a931..a244b60c8 100644 --- a/pump/server.go +++ b/pump/server.go @@ -73,16 +73,17 @@ type Server struct { // node maintains the status of this pump and interact with etcd registry node node.Node - tcpAddr string - unixAddr string - gs *grpc.Server - ctx context.Context - cancel context.CancelFunc - wg sync.WaitGroup - gcDuration time.Duration - triggerGC chan time.Time - pullClose chan struct{} - metrics *util.MetricClient + tcpAddr string + advertiseAddr string + unixAddr string + gs *grpc.Server + ctx context.Context + cancel context.CancelFunc + wg sync.WaitGroup + gcDuration time.Duration + triggerGC chan time.Time + pullClose chan struct{} + metrics *util.MetricClient // save the last time we write binlog to Storage // if long time not write, we can write a fake binlog lastWriteBinlogUnixNano int64 @@ -162,22 +163,23 @@ func NewServer(cfg *Config) (*Server, error) { } return &Server{ - dataDir: cfg.DataDir, - storage: storage, - clusterID: clusterID, - node: n, - unixAddr: cfg.Socket, - tcpAddr: cfg.ListenAddr, - gs: grpc.NewServer(grpcOpts...), - ctx: ctx, - cancel: cancel, - metrics: metrics, - tiStore: tiStore, - gcDuration: time.Duration(cfg.GC) * 24 * time.Hour, - pdCli: pdCli, - cfg: cfg, - triggerGC: make(chan time.Time), - pullClose: make(chan struct{}), + dataDir: cfg.DataDir, + storage: storage, + clusterID: clusterID, + node: n, + unixAddr: cfg.Socket, + tcpAddr: cfg.ListenAddr, + advertiseAddr: cfg.AdvertiseAddr, + gs: grpc.NewServer(grpcOpts...), + ctx: ctx, + cancel: cancel, + metrics: metrics, + tiStore: tiStore, + gcDuration: time.Duration(cfg.GC) * 24 * time.Hour, + pdCli: pdCli, + cfg: cfg, + triggerGC: make(chan time.Time), + pullClose: make(chan struct{}), }, nil } @@ -433,7 +435,7 @@ func (s *Server) Start() error { s.startHeartbeat() - log.Info("start to server request", zap.String("addr", s.tcpAddr)) + log.Info("start to server request", zap.String("addr", s.advertiseAddr)) err = m.Serve() if strings.Contains(err.Error(), "use of closed network connection") { err = nil