From 16df46e19ac3fc26683c6b1441b4c99f412c170f Mon Sep 17 00:00:00 2001 From: sunface Date: Thu, 9 May 2019 17:32:04 +0800 Subject: [PATCH] add recon --- agent/service/collector.go | 13 ++++++++++--- agent/service/network.go | 6 +++--- collector/collector.yaml | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/agent/service/collector.go b/agent/service/collector.go index 037beb80a..02e0dc1c1 100644 --- a/agent/service/collector.go +++ b/agent/service/collector.go @@ -45,8 +45,8 @@ func (c *Collector) add(key, addr string) error { } c.RUnlock() // 新链接启动 - go newClient.init(addr) - + go newClient.init() + logger.Info("new Conn", zap.String("addr", newClient.addr), zap.String("key", ruleKey)) // 保存key c.key = ruleKey } @@ -68,9 +68,16 @@ func (c *Collector) add(key, addr string) error { } c.RUnlock() - go newClient.init(addr) + go newClient.init() + logger.Info("new Conn", zap.String("addr", newClient.addr), zap.String("key", ruleKey)) // 保存key c.key = ruleKey + } else { + // 重连 + if !newClient.isStart { + go newClient.init() + logger.Info("client reConn", zap.String("addr", newClient.addr), zap.String("key", ruleKey)) + } } return nil diff --git a/agent/service/network.go b/agent/service/network.go index 2f7807cda..046b49a99 100644 --- a/agent/service/network.go +++ b/agent/service/network.go @@ -30,7 +30,7 @@ func newtcpClient(addr string) *tcpClient { } // init 初始化链接 -func (t *tcpClient) init(addr string) error { +func (t *tcpClient) init() error { var err error quitC := make(chan bool, 1) // 定时器 @@ -51,9 +51,9 @@ func (t *tcpClient) init(addr string) error { ticker.Stop() }() - t.conn, err = net.Dial("tcp", addr) + t.conn, err = net.Dial("tcp", t.addr) if err != nil { - logger.Warn("tcp connect", zap.String("err", err.Error()), zap.String("addr", addr)) + logger.Warn("tcp connect", zap.String("err", err.Error()), zap.String("addr", t.addr)) return err } diff --git a/collector/collector.yaml b/collector/collector.yaml index ec2908414..64160062f 100644 --- a/collector/collector.yaml +++ b/collector/collector.yaml @@ -4,7 +4,7 @@ common: admintoken: "tracing.dev" collector: - addr: "127.0.0.1:8081" + addr: "127.0.0.1:8082" # addr: "10.77.0.125:8082" # addr: "10.50.14.236:8082" timeout: 30