agent/app/agent.go
func (agent *ecsAgent) startAsyncRoutines(
	containerChangeEventStream *eventstream.EventStream,
	credentialsManager credentials.Manager,
	imageManager engine.ImageManager,
	taskEngine engine.TaskEngine,
	stateManager statemanager.StateManager,
	deregisterInstanceEventStream *eventstream.EventStream,
	client api.ECSClient,
	taskHandler *eventhandler.TaskHandler,
	state dockerstate.TaskEngineState) {

	// Start of the periodic image cleanup process
	if !agent.cfg.ImageCleanupDisabled {
		go imageManager.StartImageCleanupProcess(agent.ctx)
	}

	go agent.terminationHandler(stateManager, taskEngine)

	// Agent introspection api
	go handlers.ServeIntrospectionHTTPEndpoint(&agent.containerInstanceARN, taskEngine, agent.cfg)

	statsEngine := stats.NewDockerStatsEngine(agent.cfg, agent.dockerClient, containerChangeEventStream)

	// Start serving the endpoint to fetch IAM Role credentials and other task metadata
	if agent.cfg.TaskMetadataAZDisabled {
		// send empty availability zone
		go handlers.ServeTaskHTTPEndpoint(credentialsManager, state, client, agent.containerInstanceARN, agent.cfg, statsEngine, "")
	} else {
		go handlers.ServeTaskHTTPEndpoint(credentialsManager, state, client, agent.containerInstanceARN, agent.cfg, statsEngine, agent.availabilityZone)
	}

	// Start sending events to the backend
	go eventhandler.HandleEngineEvents(taskEngine, client, taskHandler)

	telemetrySessionParams := tcshandler.TelemetrySessionParams{
		Ctx:                           agent.ctx,
		CredentialProvider:            agent.credentialProvider,
		Cfg:                           agent.cfg,
		ContainerInstanceArn:          agent.containerInstanceARN,
		DeregisterInstanceEventStream: deregisterInstanceEventStream,
		ECSClient:                     client,
		TaskEngine:                    taskEngine,
		StatsEngine:                   statsEngine,
	}

	// Start metrics session in a go routine
	go tcshandler.StartMetricsSession(&telemetrySessionParams)
}
func (agent *ecsAgent) startAsyncRoutines(
	containerChangeEventStream *eventstream.EventStream,
	credentialsManager credentials.Manager,
	imageManager engine.ImageManager,
	taskEngine engine.TaskEngine,
	stateManager statemanager.StateManager,
	deregisterInstanceEventStream *eventstream.EventStream,
	client api.ECSClient,
	taskHandler *eventhandler.TaskHandler,
	state dockerstate.TaskEngineState) {

	// Start of the periodic image cleanup process
	if !agent.cfg.ImageCleanupDisabled {
		go imageManager.StartImageCleanupProcess(agent.ctx)
	}

	go agent.terminationHandler(stateManager, taskEngine)

	// Agent introspection api
	go handlers.ServeIntrospectionHTTPEndpoint(&agent.containerInstanceARN, taskEngine, agent.cfg)

	statsEngine := stats.NewDockerStatsEngine(agent.cfg, agent.dockerClient, containerChangeEventStream)

	// Start serving the endpoint to fetch IAM Role credentials and other task metadata
	if agent.cfg.TaskMetadataAZDisabled {
		// send empty availability zone
		go handlers.ServeTaskHTTPEndpoint(credentialsManager, state, client, agent.containerInstanceARN, agent.cfg, statsEngine, "")
	} else {
		go handlers.ServeTaskHTTPEndpoint(credentialsManager, state, client, agent.containerInstanceARN, agent.cfg, statsEngine, agent.availabilityZone)
	}

	// Start sending events to the backend
	go eventhandler.HandleEngineEvents(taskEngine, client, taskHandler)

	telemetrySessionParams := tcshandler.TelemetrySessionParams{
		Ctx:                           agent.ctx,
		CredentialProvider:            agent.credentialProvider,
		Cfg:                           agent.cfg,
		ContainerInstanceArn:          agent.containerInstanceARN,
		DeregisterInstanceEventStream: deregisterInstanceEventStream,
		ECSClient:                     client,
		TaskEngine:                    taskEngine,
		StatsEngine:                   statsEngine,
	}

	// Start metrics session in a go routine
	go tcshandler.StartMetricsSession(&telemetrySessionParams)
}
func ( agent * ecsAgent ) startAsyncRoutines ( containerChangeEventStream * eventstream . EventStream , credentialsManager credentials . Manager , imageManager engine . ImageManager , taskEngine engine . TaskEngine , stateManager statemanager . StateManager , deregisterInstanceEventStream * eventstream . EventStream , client api . ECSClient , taskHandler * eventhandler . TaskHandler , state dockerstate . TaskEngineState ) { // Start of the periodic image cleanup process if ! agent . cfg . ImageCleanupDisabled { go imageManager . StartImageCleanupProcess ( agent . ctx ) } go agent . terminationHandler ( stateManager , taskEngine ) // Agent introspection api go handlers . ServeIntrospectionHTTPEndpoint ( & agent . containerInstanceARN , taskEngine , agent . cfg ) statsEngine := stats . NewDockerStatsEngine ( agent . cfg , agent . dockerClient , containerChangeEventStream ) // Start serving the endpoint to fetch IAM Role credentials and other task metadata if agent . cfg . TaskMetadataAZDisabled { // send empty availability zone go handlers . ServeTaskHTTPEndpoint ( credentialsManager , state , client , agent . containerInstanceARN , agent . cfg , statsEngine , " " ) } else { go handlers . ServeTaskHTTPEndpoint ( credentialsManager , state , client , agent . containerInstanceARN , agent . cfg , statsEngine , agent . availabilityZone ) } // Start sending events to the backend go eventhandler . HandleEngineEvents ( taskEngine , client , taskHandler ) telemetrySessionParams := tcshandler . TelemetrySessionParams { Ctx : agent . ctx , CredentialProvider : agent . credentialProvider , Cfg : agent . cfg , ContainerInstanceArn : agent . containerInstanceARN , DeregisterInstanceEventStream : deregisterInstanceEventStream , ECSClient : client , TaskEngine : taskEngine , StatsEngine : statsEngine , } // Start metrics session in a go routine go tcshandler . StartMetricsSession ( & telemetrySessionParams ) }
// startAsyncRoutines starts all of the background methods
startAsyncRoutines starts all of the background methods