Skip to content

Commit

Permalink
Use debug instead of error log for skipped events for internal task/c…
Browse files Browse the repository at this point in the history
…ontainer
  • Loading branch information
yinyic committed Feb 7, 2023
1 parent 7e24522 commit 81034b1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
14 changes: 10 additions & 4 deletions agent/api/statechange.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,20 @@ type AttachmentStateChange struct {
Attachment *apieni.ENIAttachment
}

type ErrShouldNotSendEvent struct {
resourceId string
}

func (e ErrShouldNotSendEvent) Error() string {
return fmt.Sprintf("should not send events for internal tasks or containers: %s", e.resourceId)
}

// NewTaskStateChangeEvent creates a new task state change event
// returns error if the state change doesn't need to be sent to the ECS backend.
func NewTaskStateChangeEvent(task *apitask.Task, reason string) (TaskStateChange, error) {
var event TaskStateChange
if task.IsInternal {
return event, errors.Errorf("skip creating task stage change event for internal task %v", task.Arn)
return event, ErrShouldNotSendEvent{task.Arn}
}
taskKnownStatus := task.GetKnownStatus()
if !taskKnownStatus.BackendRecognized() {
Expand Down Expand Up @@ -160,9 +168,7 @@ func NewContainerStateChangeEvent(task *apitask.Task, cont *apicontainer.Contain
func newUncheckedContainerStateChangeEvent(task *apitask.Task, cont *apicontainer.Container, reason string) (ContainerStateChange, error) {
var event ContainerStateChange
if cont.IsInternal() {
return event, errors.Errorf(
"create container state change event api: internal container: %s",
cont.Name)
return event, ErrShouldNotSendEvent{cont.Name}
}
portBindings := cont.GetKnownPortBindings()
if task.IsServiceConnectEnabled() && task.IsNetworkModeBridge() {
Expand Down
12 changes: 8 additions & 4 deletions agent/engine/docker_task_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,14 @@ func (engine *DockerTaskEngine) deleteTask(task *apitask.Task) {
func (engine *DockerTaskEngine) emitTaskEvent(task *apitask.Task, reason string) {
event, err := api.NewTaskStateChangeEvent(task, reason)
if err != nil {
logger.Error("Unable to create task state change event", logger.Fields{
field.TaskID: task.GetID(),
field.Error: err,
})
if _, ok := err.(api.ErrShouldNotSendEvent); ok {
logger.Debug(err.Error())
} else {
logger.Error("Unable to create task state change event", logger.Fields{
field.TaskID: task.GetID(),
field.Error: err,
})
}
return
}
logger.Info("Preparing to send change event", logger.Fields{
Expand Down
28 changes: 18 additions & 10 deletions agent/engine/task_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,15 @@ func (mtask *managedTask) emitTaskEvent(task *apitask.Task, reason string) {
}
event, err := api.NewTaskStateChangeEvent(task, reason)
if err != nil {
logger.Error("Skipping emitting event for task due to error", logger.Fields{
field.TaskID: mtask.GetID(),
field.Reason: reason,
field.Error: err,
})
if _, ok := err.(api.ErrShouldNotSendEvent); ok {
logger.Debug(err.Error())
} else {
logger.Error("Skipping emitting event for task due to error", logger.Fields{
field.TaskID: mtask.GetID(),
field.Reason: reason,
field.Error: err,
})
}
return
}
logger.Debug("Sending task change event", logger.Fields{
Expand Down Expand Up @@ -680,11 +684,15 @@ func (mtask *managedTask) emitManagedAgentEvent(task *apitask.Task, cont *apicon
func (mtask *managedTask) emitContainerEvent(task *apitask.Task, cont *apicontainer.Container, reason string) {
event, err := api.NewContainerStateChangeEvent(task, cont, reason)
if err != nil {
logger.Debug("Skipping emitting event for container", logger.Fields{
field.TaskID: mtask.GetID(),
field.Container: cont.Name,
field.Error: err,
})
if _, ok := err.(api.ErrShouldNotSendEvent); ok {
logger.Debug(err.Error())
} else {
logger.Error("Skipping emitting event for container due to error", logger.Fields{
field.TaskID: mtask.GetID(),
field.Container: cont.Name,
field.Error: err,
})
}
return
}
mtask.doEmitContainerEvent(event)
Expand Down

0 comments on commit 81034b1

Please sign in to comment.