Skip to content

Commit

Permalink
Refine log when enable tls (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Apr 10, 2020
1 parent d527f38 commit 628ec84
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 54 deletions.
9 changes: 7 additions & 2 deletions drainer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
48 changes: 25 additions & 23 deletions drainer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 7 additions & 2 deletions pump/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
56 changes: 29 additions & 27 deletions pump/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 628ec84

Please sign in to comment.