Skip to content

Commit 2bc9e3f

Browse files
Add Docker ID of containers to logs
1 parent 18552fb commit 2bc9e3f

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

agent/engine/docker_task_engine.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ func getFirelensLogConfig(task *apitask.Task, container *apicontainer.Container,
11001100
}
11011101

11021102
func (engine *DockerTaskEngine) startContainer(task *apitask.Task, container *apicontainer.Container) dockerapi.DockerContainerMetadata {
1103-
seelog.Infof("Task engine [%s]: starting container: %s", task.Arn, container.Name)
1103+
seelog.Infof("Task engine [%s]: starting container: %s (Docker ID: %s)", task.Arn, container.Name, container.RuntimeID)
11041104
client := engine.client
11051105
if container.DockerConfig.Version != nil {
11061106
client = client.WithVersion(dockerclient.DockerVersion(*container.DockerConfig.Version))
@@ -1392,11 +1392,11 @@ func (engine *DockerTaskEngine) applyContainerState(task *apitask.Task, containe
13921392
}
13931393
metadata := transitionFunction(task, container)
13941394
if metadata.Error != nil {
1395-
seelog.Infof("Task engine [%s]: error transitioning container [%s] to [%s]: %v",
1396-
task.Arn, container.Name, nextState.String(), metadata.Error)
1395+
seelog.Infof("Task engine [%s]: error transitioning container [%s (Docker ID: %s)] to [%s]: %v",
1396+
task.Arn, container.Name, container.RuntimeID, nextState.String(), metadata.Error)
13971397
} else {
1398-
seelog.Debugf("Task engine [%s]: transitioned container [%s] to [%s]",
1399-
task.Arn, container.Name, nextState.String())
1398+
seelog.Debugf("Task engine [%s]: transitioned container [%s (Docker ID: %s)] to [%s]",
1399+
task.Arn, container.Name, container.RuntimeID, nextState.String())
14001400
engine.saver.Save()
14011401
}
14021402
return metadata

agent/engine/task_manager.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ func (mtask *managedTask) waitEvent(stopWaiting <-chan struct{}) bool {
345345
mtask.handleDesiredStatusChange(acsTransition.desiredStatus, acsTransition.seqnum)
346346
return false
347347
case dockerChange := <-mtask.dockerMessages:
348-
seelog.Infof("Managed task [%s]: got container [%s] event: [%s]",
349-
mtask.Arn, dockerChange.container.Name, dockerChange.event.Status.String())
348+
seelog.Infof("Managed task [%s]: got container [%s (Docker ID: %s)] event: [%s]",
349+
mtask.Arn, dockerChange.container.Name, dockerChange.container.RuntimeID, dockerChange.event.Status.String())
350350
mtask.handleContainerChange(dockerChange)
351351
return false
352352
case resChange := <-mtask.resourceStateChangeEvent:
@@ -399,8 +399,8 @@ func (mtask *managedTask) handleContainerChange(containerChange dockerContainerC
399399
}
400400

401401
event := containerChange.event
402-
seelog.Infof("Managed task [%s]: handling container change [%v] for container [%s]",
403-
mtask.Arn, event, container.Name)
402+
seelog.Infof("Managed task [%s]: handling container change [%v] for container [%s (Docker ID: %s)]",
403+
mtask.Arn, event, container.Name, container.RuntimeID)
404404

405405
// If this is a backwards transition stopped->running, the first time set it
406406
// to be known running so it will be stopped. Subsequently ignore these backward transitions
@@ -440,8 +440,8 @@ func (mtask *managedTask) handleContainerChange(containerChange dockerContainerC
440440

441441
mtask.emitContainerEvent(mtask.Task, container, "")
442442
if mtask.UpdateStatus() {
443-
seelog.Infof("Managed task [%s]: container change also resulted in task change [%s]: [%s]",
444-
mtask.Arn, container.Name, mtask.GetDesiredStatus().String())
443+
seelog.Infof("Managed task [%s]: container change also resulted in task change [%s (Docker ID: %s)]: [%s]",
444+
mtask.Arn, container.Name, event.DockerID, mtask.GetDesiredStatus().String())
445445
// If knownStatus changed, let it be known
446446
var taskStateChangeReason string
447447
if mtask.GetKnownStatus().Terminal() {
@@ -644,8 +644,8 @@ func (mtask *managedTask) handleEventError(containerChange dockerContainerChange
644644
// the task fail here, will let create container handle it instead.
645645
// If the agent pull behavior is default, use local image cache directly,
646646
// assuming it exists.
647-
seelog.Errorf("Managed task [%s]: error while pulling container %s and image %s, will try to run anyway: %v",
648-
mtask.Arn, container.Name, container.Image, event.Error)
647+
seelog.Errorf("Managed task [%s]: error while pulling container %s (Docker ID: %s) and image %s, will try to run anyway: %v",
648+
mtask.Arn, container.Name, container.RuntimeID, container.Image, event.Error)
649649
// proceed anyway
650650
return true
651651
case apicontainerstatus.ContainerStopped:
@@ -655,16 +655,16 @@ func (mtask *managedTask) handleEventError(containerChange dockerContainerChange
655655
fallthrough
656656
case apicontainerstatus.ContainerCreated:
657657
// No need to explicitly stop containers if this is a * -> NONE/CREATED transition
658-
seelog.Warnf("Managed task [%s]: error creating container [%s]; marking its desired status as STOPPED: %v",
659-
mtask.Arn, container.Name, event.Error)
658+
seelog.Warnf("Managed task [%s]: error creating container [%s (Docker ID: %s)]; marking its desired status as STOPPED: %v",
659+
mtask.Arn, container.Name, container.RuntimeID, event.Error)
660660
container.SetKnownStatus(currentKnownStatus)
661661
container.SetDesiredStatus(apicontainerstatus.ContainerStopped)
662662
return false
663663
default:
664664
// If this is a * -> RUNNING / RESOURCES_PROVISIONED transition, we need to stop
665665
// the container.
666-
seelog.Warnf("Managed task [%s]: error starting/provisioning container[%s]; marking its desired status as STOPPED: %v",
667-
mtask.Arn, container.Name, event.Error)
666+
seelog.Warnf("Managed task [%s]: error starting/provisioning container[%s (Docker ID: %s)]; marking its desired status as STOPPED: %v",
667+
mtask.Arn, container.Name, container.RuntimeID, event.Error)
668668
container.SetKnownStatus(currentKnownStatus)
669669
container.SetDesiredStatus(apicontainerstatus.ContainerStopped)
670670
errorName := event.Error.ErrorName()
@@ -682,8 +682,8 @@ func (mtask *managedTask) handleEventError(containerChange dockerContainerChange
682682
}
683683

684684
if shouldForceStop {
685-
seelog.Warnf("Managed task [%s]: forcing container [%s] to stop",
686-
mtask.Arn, container.Name)
685+
seelog.Warnf("Managed task [%s]: forcing container [%s (Docker ID: %s)] to stop",
686+
mtask.Arn, container.Name, container.RuntimeID)
687687
go mtask.engine.transitionContainer(mtask.Task, container, apicontainerstatus.ContainerStopped)
688688
}
689689
// Container known status not changed, no need for further processing
@@ -705,17 +705,17 @@ func (mtask *managedTask) handleContainerStoppedTransitionError(event dockerapi.
705705
// could also trigger the progress and have another go at stopping the
706706
// container
707707
if event.Error.ErrorName() == dockerapi.DockerTimeoutErrorName {
708-
seelog.Infof("Managed task [%s]: '%s' error stopping container [%s]. Ignoring state change: %v",
709-
mtask.Arn, dockerapi.DockerTimeoutErrorName, container.Name, event.Error.Error())
708+
seelog.Infof("Managed task [%s]: '%s' error stopping container [%s (Docker ID: %s)]. Ignoring state change: %v",
709+
mtask.Arn, dockerapi.DockerTimeoutErrorName, container.Name, container.RuntimeID, event.Error.Error())
710710
container.SetKnownStatus(currentKnownStatus)
711711
return false
712712
}
713713
// If docker returned a transient error while trying to stop a container,
714714
// reset the known status to the current status and return
715715
cannotStopContainerError, ok := event.Error.(cannotStopContainerError)
716716
if ok && cannotStopContainerError.IsRetriableError() {
717-
seelog.Infof("Managed task [%s]: error stopping the container [%s]. Ignoring state change: %v",
718-
mtask.Arn, container.Name, cannotStopContainerError.Error())
717+
seelog.Infof("Managed task [%s]: error stopping the container [%s (Docker ID: %s)]. Ignoring state change: %v",
718+
mtask.Arn, container.Name, container.RuntimeID, cannotStopContainerError.Error())
719719
container.SetKnownStatus(currentKnownStatus)
720720
return false
721721
}
@@ -981,8 +981,8 @@ func (mtask *managedTask) containerNextState(container *apicontainer.Container)
981981
containerDesiredStatus := container.GetDesiredStatus()
982982

983983
if containerKnownStatus == containerDesiredStatus {
984-
seelog.Debugf("Managed task [%s]: container [%s] at desired status: %s",
985-
mtask.Arn, container.Name, containerDesiredStatus.String())
984+
seelog.Debugf("Managed task [%s]: container [%s (Docker ID: %s)] at desired status: %s",
985+
mtask.Arn, container.Name, container.RuntimeID, containerDesiredStatus.String())
986986
return &containerTransition{
987987
nextState: apicontainerstatus.ContainerStatusNone,
988988
actionRequired: false,
@@ -991,8 +991,8 @@ func (mtask *managedTask) containerNextState(container *apicontainer.Container)
991991
}
992992

993993
if containerKnownStatus > containerDesiredStatus {
994-
seelog.Debugf("Managed task [%s]: container [%s] has already transitioned beyond desired status(%s): %s",
995-
mtask.Arn, container.Name, containerKnownStatus.String(), containerDesiredStatus.String())
994+
seelog.Debugf("Managed task [%s]: container [%s (Docker ID: %s)] has already transitioned beyond desired status(%s): %s",
995+
mtask.Arn, container.Name, container.RuntimeID, containerKnownStatus.String(), containerDesiredStatus.String())
996996
return &containerTransition{
997997
nextState: apicontainerstatus.ContainerStatusNone,
998998
actionRequired: false,
@@ -1001,8 +1001,8 @@ func (mtask *managedTask) containerNextState(container *apicontainer.Container)
10011001
}
10021002
if blocked, err := dependencygraph.DependenciesAreResolved(container, mtask.Containers,
10031003
mtask.Task.GetExecutionCredentialsID(), mtask.credentialsManager, mtask.GetResources()); err != nil {
1004-
seelog.Debugf("Managed task [%s]: can't apply state to container [%s] yet due to unresolved dependencies: %v",
1005-
mtask.Arn, container.Name, err)
1004+
seelog.Debugf("Managed task [%s]: can't apply state to container [%s (Docker ID: %s)] yet due to unresolved dependencies: %v",
1005+
mtask.Arn, container.Name, container.RuntimeID, err)
10061006
return &containerTransition{
10071007
nextState: apicontainerstatus.ContainerStatusNone,
10081008
actionRequired: false,

0 commit comments

Comments
 (0)