From b2307322d705e71960fc9a9bf6f7d54bae182102 Mon Sep 17 00:00:00 2001 From: ohsoo Date: Thu, 20 Jul 2023 20:43:08 +0000 Subject: [PATCH] Add task stop verification ack to ecs-agent module --- .../session/task_stop_verification_ack_responder.go | 9 ++++----- .../amazon-ecs-agent/ecs-agent/metrics/constants.go | 8 ++++++++ .../session/task_stop_verification_ack_responder.go | 12 +++++++----- ecs-agent/metrics/constants.go | 8 ++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) rename ecs-agent/acs/session/task_stop_verification_ack => agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/task_stop_verification_ack_responder.go (91%) rename agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/task_stop_verification_ack => ecs-agent/acs/session/task_stop_verification_ack_responder.go (90%) diff --git a/ecs-agent/acs/session/task_stop_verification_ack b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/task_stop_verification_ack_responder.go similarity index 91% rename from ecs-agent/acs/session/task_stop_verification_ack rename to agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/task_stop_verification_ack_responder.go index bb0ce99b901..bc4a31608ac 100644 --- a/ecs-agent/acs/session/task_stop_verification_ack +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/task_stop_verification_ack_responder.go @@ -70,14 +70,13 @@ func (r *taskStopVerificationACKResponder) handleTaskStopVerificationACK(message tasksToStop := message.StopTasks for _, task := range tasksToStop { taskARN := aws.StringValue(task.TaskArn) - metricFields := map[string]interface{}{ - "MessageID": aws.StringValue(message.MessageId), - "TaskARN": taskARN, + metricFields := logger.Fields{ + field.MessageID: aws.StringValue(message.MessageId), + field.TaskARN: taskARN, } r.metricsFactory.New(metrics.TaskStoppedMetricName).WithFields(metricFields).Done(nil) - // Send request to the task stopper to stop the task this will be executed asynchronously - // in the context of the task stopper's message channel. + // Send request to the task stopper to stop the task. logger.Info("Sending message to task stopper to stop task", logger.Fields{ field.TaskARN: taskARN, }) diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/metrics/constants.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/metrics/constants.go index d3ada8cee85..4979940c335 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/metrics/constants.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/metrics/constants.go @@ -26,4 +26,12 @@ const ( // AttachResourceResponder attachResourceResponderNamespace = "ResourceAttachment" ResourceValidationMetricName = attachResourceResponderNamespace + ".Validation" + + // TaskManifestResponder + taskManifestResponderNamespace = "TaskManifestResponder" + TaskManifestHandlingDuration = taskManifestResponderNamespace + ".Duration" + + // TaskStopVerificationACKResponder + taskStopVerificationACKResponderNamespace = "TaskStopVeificationACKResponder" + TaskStoppedMetricName = taskStopVerificationACKResponderNamespace + ".TaskStopped" ) diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/task_stop_verification_ack b/ecs-agent/acs/session/task_stop_verification_ack_responder.go similarity index 90% rename from agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/task_stop_verification_ack rename to ecs-agent/acs/session/task_stop_verification_ack_responder.go index 34103869a60..bc4a31608ac 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/task_stop_verification_ack +++ b/ecs-agent/acs/session/task_stop_verification_ack_responder.go @@ -63,18 +63,20 @@ func (r *taskStopVerificationACKResponder) handleTaskStopVerificationACK(message return errors.New("Invalid messageID received: " + ackMessageID + " Manifest Message ID: " + manifestMessageID) } + // Reset the message id so that the message with same message id is not processed twice. + r.messageIDAccessor.SetMessageID("") + // Loop through all tasks in the verified stop list and set the desired status of each one to STOPPED. tasksToStop := message.StopTasks for _, task := range tasksToStop { taskARN := aws.StringValue(task.TaskArn) - metricFields := map[string]interface{}{ - "MessageID": aws.StringValue(message.MessageId), - "TaskARN": taskARN, + metricFields := logger.Fields{ + field.MessageID: aws.StringValue(message.MessageId), + field.TaskARN: taskARN, } r.metricsFactory.New(metrics.TaskStoppedMetricName).WithFields(metricFields).Done(nil) - // Send request to the task stopper to stop the task this will be executed asynchronously - // in the context of the task stopper's message channel. + // Send request to the task stopper to stop the task. logger.Info("Sending message to task stopper to stop task", logger.Fields{ field.TaskARN: taskARN, }) diff --git a/ecs-agent/metrics/constants.go b/ecs-agent/metrics/constants.go index d3ada8cee85..4979940c335 100644 --- a/ecs-agent/metrics/constants.go +++ b/ecs-agent/metrics/constants.go @@ -26,4 +26,12 @@ const ( // AttachResourceResponder attachResourceResponderNamespace = "ResourceAttachment" ResourceValidationMetricName = attachResourceResponderNamespace + ".Validation" + + // TaskManifestResponder + taskManifestResponderNamespace = "TaskManifestResponder" + TaskManifestHandlingDuration = taskManifestResponderNamespace + ".Duration" + + // TaskStopVerificationACKResponder + taskStopVerificationACKResponderNamespace = "TaskStopVeificationACKResponder" + TaskStoppedMetricName = taskStopVerificationACKResponderNamespace + ".TaskStopped" )