Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dot/telemetry): Added connection retry #1904

Merged
merged 7 commits into from
Oct 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions dot/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -61,7 +63,11 @@ var (
initilised sync.Once
)

const defaultMessageTimeout = time.Second
const (
defaultMessageTimeout = time.Second
defaultMaxRetries = 5
defaultRetryDelay = time.Second * 15
)

// GetInstance singleton pattern to for accessing TelemetryHandler
func GetInstance() Instance {
Expand All @@ -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()
})
Expand All @@ -94,17 +102,19 @@ func (h *Handler) Initialise(e bool) {
// 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: try reconnecting if there is an error connecting (#1862)
h.log.Debug("issue adding telemetry connection", "error", err)
continue
}
tConn := &telemetryConnection{
wsconn: c,
verbosity: v.Verbosity,
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)
time.Sleep(h.retryDelay)
continue
}
h.connections = append(h.connections, &telemetryConnection{
wsconn: c,
verbosity: v.Verbosity,
})
break
}
h.connections = append(h.connections, tConn)
}
}

Expand Down