Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use debug instead of error log for skipped events for internal task/container #3559

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
yinyic marked this conversation as resolved.
Show resolved Hide resolved
}
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