Skip to content

Commit 9a2fa75

Browse files
author
Heming Han
committed
address comments
1 parent 1cdd56a commit 9a2fa75

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

agent/stats/reporter/reporter.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ const (
4141
// Default websocket client disconnection timeout initiated by agent
4242
defaultDisconnectionTimeout = 15 * time.Minute
4343
defaultDisconnectionJitter = 30 * time.Minute
44+
backoffMin = 1 * time.Second
45+
backoffMax = 1 * time.Minute
46+
jitterMultiple = 0.2
47+
multiple = 2
4448
)
4549

4650
type DockerTelemetrySession struct {
@@ -107,22 +111,25 @@ func NewDockerTelemetrySession(
107111
// discoverTelemetryEndpoint and tcshandler.TelemetrySession's StartTelemetrySession errors are handled
108112
// (retryWithBackoff or return) in a combined manner
109113
func (session *DockerTelemetrySession) Start(ctx context.Context) error {
110-
backoff := retry.NewExponentialBackoff(time.Second, 1*time.Minute, 0.2, 2)
114+
backoff := retry.NewExponentialBackoff(backoffMin, backoffMax, jitterMultiple, multiple)
111115
for {
112116
select {
113117
case <-ctx.Done():
114-
logger.Info("TCS session exited cleanly.")
118+
logger.Info("ECS Telemetry service (TCS) session exited cleanly.")
115119
return nil
116120
default:
117121
}
118122
endpoint, tcsError := discoverPollEndpoint(session.containerInstanceArn, session.ecsClient)
119123
if tcsError == nil {
124+
// returning from StartTelemetrySession indicates a disconnection, need to reconnect.
120125
tcsError = session.s.StartTelemetrySession(ctx, endpoint)
121126
}
122127
if tcsError == nil || tcsError == io.EOF {
128+
// reset backoff when TCS closed for a valid reason, such as connection expiring due to inactivity
123129
logger.Info("TCS Websocket connection closed for a valid reason")
124130
backoff.Reset()
125131
} else {
132+
// backoff when there is unexpected error, such as invalid frame sent through connection.
126133
logger.Error("Error: lost websocket connection with ECS Telemetry service (TCS)", logger.Fields{
127134
field.Error: tcsError,
128135
})

0 commit comments

Comments
 (0)