From 3fc270b6e8410996798a9aaaa7ae3199ca45cb2c Mon Sep 17 00:00:00 2001 From: zjhuber Date: Wed, 13 Oct 2021 15:23:43 -0700 Subject: [PATCH 1/3] feat(dot/telemetry): Added connection retry --- dot/telemetry/telemetry.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/dot/telemetry/telemetry.go b/dot/telemetry/telemetry.go index 873ed4273a..659401c22d 100644 --- a/dot/telemetry/telemetry.go +++ b/dot/telemetry/telemetry.go @@ -91,20 +91,27 @@ func (h *Handler) Initialise(e bool) { }) } +var maxRetries = 5 +var retryDelay = time.Millisecond * 100 + // AddConnections adds the given telemetry endpoint as listeners that will receive telemetry data func (h *Handler) AddConnections(conns []*genesis.TelemetryEndpoint) { for _, v := range conns { - c, _, err := websocket.DefaultDialer.Dial(v.Endpoint, nil) - if err != nil { - // todo (ed) try reconnecting if there is an error connecting - h.log.Debug("issue adding telemetry connection", "error", err) - continue - } - tConn := &telemetryConnection{ - wsconn: c, - verbosity: v.Verbosity, + for connAttempts := 0; connAttempts < maxRetries; { + c, _, err := websocket.DefaultDialer.Dial(v.Endpoint, nil) + if err != nil { + h.log.Debug("issue adding telemetry connection", "error", err) + connAttempts++ + time.Sleep(retryDelay) + } else { + tConn := &telemetryConnection{ + wsconn: c, + verbosity: v.Verbosity, + } + h.connections = append(h.connections, tConn) + break + } } - h.connections = append(h.connections, tConn) } } From f38240a51b7ffe50adab060914e7b583a037feff Mon Sep 17 00:00:00 2001 From: zjhuber Date: Wed, 20 Oct 2021 21:56:39 -0700 Subject: [PATCH 2/3] Added new default constants. Used handler to pass in connection retry values. --- dot/telemetry/telemetry.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/dot/telemetry/telemetry.go b/dot/telemetry/telemetry.go index 659401c22d..71db21ac21 100644 --- a/dot/telemetry/telemetry.go +++ b/dot/telemetry/telemetry.go @@ -43,6 +43,8 @@ type Handler struct { connections []*telemetryConnection log log.Logger sendMessageTimeout time.Duration + maxRetries int + retryDelay time.Duration } // Instance interface that telemetry handler instance needs to implement @@ -61,7 +63,11 @@ var ( initilised sync.Once ) -const defaultMessageTimeout = time.Second +const ( + defaultMessageTimeout = time.Second + defaultMaxRetries = 5 + defaultRetryDelay = time.Millisecond * 100 +) // GetInstance singleton pattern to for accessing TelemetryHandler func GetInstance() Instance { @@ -72,6 +78,8 @@ func GetInstance() Instance { msg: make(chan Message, 256), log: log.New("pkg", "telemetry"), sendMessageTimeout: defaultMessageTimeout, + maxRetries: defaultMaxRetries, + retryDelay: defaultRetryDelay, } go handlerInstance.startListening() }) @@ -91,26 +99,21 @@ func (h *Handler) Initialise(e bool) { }) } -var maxRetries = 5 -var retryDelay = time.Millisecond * 100 - // AddConnections adds the given telemetry endpoint as listeners that will receive telemetry data func (h *Handler) AddConnections(conns []*genesis.TelemetryEndpoint) { for _, v := range conns { - for connAttempts := 0; connAttempts < maxRetries; { + for connAttempts := 0; connAttempts < h.maxRetries; connAttempts++ { c, _, err := websocket.DefaultDialer.Dial(v.Endpoint, nil) if err != nil { h.log.Debug("issue adding telemetry connection", "error", err) - connAttempts++ - time.Sleep(retryDelay) - } else { - tConn := &telemetryConnection{ - wsconn: c, - verbosity: v.Verbosity, - } - h.connections = append(h.connections, tConn) - break + time.Sleep(h.retryDelay) + continue } + h.connections = append(h.connections, &telemetryConnection{ + wsconn: c, + verbosity: v.Verbosity, + }) + break } } } From c4b940e74f3c5ca5b6f4b2fac4cedca21dfe020f Mon Sep 17 00:00:00 2001 From: zjhuber Date: Thu, 21 Oct 2021 07:45:41 -0700 Subject: [PATCH 3/3] Updated retryDelay --- dot/telemetry/telemetry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dot/telemetry/telemetry.go b/dot/telemetry/telemetry.go index 71db21ac21..af08860190 100644 --- a/dot/telemetry/telemetry.go +++ b/dot/telemetry/telemetry.go @@ -66,7 +66,7 @@ var ( const ( defaultMessageTimeout = time.Second defaultMaxRetries = 5 - defaultRetryDelay = time.Millisecond * 100 + defaultRetryDelay = time.Second * 15 ) // GetInstance singleton pattern to for accessing TelemetryHandler