Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Realmonia committed Jul 7, 2023
1 parent f966ccb commit b695ba9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions agent/stats/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const (
// Default websocket client disconnection timeout initiated by agent
defaultDisconnectionTimeout = 15 * time.Minute
defaultDisconnectionJitter = 30 * time.Minute
backoffMin = 1 * time.Second
backoffMax = 1 * time.Minute
jitterMultiple = 0.2
multiple = 2
)

type DockerTelemetrySession struct {
Expand Down Expand Up @@ -107,22 +111,25 @@ func NewDockerTelemetrySession(
// discoverTelemetryEndpoint and tcshandler.TelemetrySession's StartTelemetrySession errors are handled
// (retryWithBackoff or return) in a combined manner
func (session *DockerTelemetrySession) Start(ctx context.Context) error {
backoff := retry.NewExponentialBackoff(time.Second, 1*time.Minute, 0.2, 2)
backoff := retry.NewExponentialBackoff(backoffMin, backoffMax, jitterMultiple, multiple)
for {
select {
case <-ctx.Done():
logger.Info("TCS session exited cleanly.")
logger.Info("ECS Telemetry service (TCS) session exited cleanly.")
return nil
default:
}
endpoint, tcsError := discoverPollEndpoint(session.containerInstanceArn, session.ecsClient)
if tcsError == nil {
// returning from StartTelemetrySession indicates a disconnection, need to reconnect.
tcsError = session.s.StartTelemetrySession(ctx, endpoint)
}
if tcsError == nil || tcsError == io.EOF {
// reset backoff when TCS closed for a valid reason, such as connection expiring due to inactivity
logger.Info("TCS Websocket connection closed for a valid reason")
backoff.Reset()
} else {
// backoff when there is unexpected error, such as invalid frame sent through connection.
logger.Error("Error: lost websocket connection with ECS Telemetry service (TCS)", logger.Fields{
field.Error: tcsError,
})
Expand Down

0 comments on commit b695ba9

Please sign in to comment.