-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ACS heartbeat message handling
- Loading branch information
Showing
7 changed files
with
165 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/heartbeat_responder.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/logger/field/constants.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
package session | ||
|
||
import ( | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/acs/model/ecsacs" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/doctor" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/logger" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/logger/field" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/wsclient" | ||
"github.com/aws/aws-sdk-go/aws" | ||
) | ||
|
||
// heartbeatResponder implements the wsclient.RequestResponder interface for responding | ||
// to ecsacs.HeartbeatMessage type. | ||
type heartbeatResponder struct { | ||
doctor *doctor.Doctor | ||
respond wsclient.RespondFunc | ||
} | ||
|
||
// NewHeartbeatResponder returns an instance of the heartbeatResponder struct. | ||
func NewHeartbeatResponder(doctor *doctor.Doctor) wsclient.RequestResponder { | ||
return &heartbeatResponder{ | ||
doctor: doctor, | ||
} | ||
} | ||
|
||
func (*heartbeatResponder) Name() string { | ||
return "heartbeat message responder" | ||
} | ||
|
||
func (r *heartbeatResponder) RegisterResponder(respond wsclient.RespondFunc) { | ||
r.respond = respond | ||
} | ||
|
||
func (r *heartbeatResponder) HandlerFunc() wsclient.RequestHandler { | ||
return r.processHeartbeatMessage | ||
} | ||
|
||
// processHeartbeatMessage processes an ACS heartbeat message. | ||
// This function is meant to be called from the ACS dispatcher and as such | ||
// should not block in any way to prevent starvation of the message handler. | ||
func (r *heartbeatResponder) processHeartbeatMessage(message *ecsacs.HeartbeatMessage) { | ||
// Agent will run container instance healthchecks. They are triggered by ACS heartbeat. | ||
// Results of healthchecks will be sent on to TACS. | ||
go r.doctor.RunHealthchecks() | ||
|
||
// Agent will send simple ack | ||
ack := &ecsacs.HeartbeatAckRequest{ | ||
MessageId: message.MessageId, | ||
} | ||
go func() { | ||
err := r.respond(ack) | ||
if err != nil { | ||
logger.Warn("Error acknowledging server heartbeat", logger.Fields{ | ||
field.MessageID: aws.StringValue(ack.MessageId), | ||
field.Error: err, | ||
}) | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters