amazon-ecs-agent icon indicating copy to clipboard operation
amazon-ecs-agent copied to clipboard

Tasks are not retained long enough in the ECS history

Open ryanwalls opened this issue 10 years ago • 10 comments

I don't know of a better place to put bugs like this, but "stopped tasks" in the amazon ECS UI does not show tasks that are more than just a few minutes old (don't know the exact time.)

When I query the ecs api using ListTasks, it returns nothing as well.

What is the retainment period for tasks? For debugging purposes I feel at least 30 days would be reasonable.

ryanwalls avatar Apr 08 '16 16:04 ryanwalls

By default, ListTasks will only show RUNNING tasks. However, you can pass a desiredStatus of STOPPED to see stopped tasks. STOPPED tasks are removed after some time (but are retained longer than just a few minutes).

Note that the best place to report issues or feature requests related to ECS as a whole and not just the agent are the AWS Forums or AWS Support.

samuelkarp avatar Apr 08 '16 17:04 samuelkarp

@samuelkarp Even with specifying "stopped" we cannot see a task that is 15 hours old.

So whatever the retainment period is, is too short for our purposes.

ryanwalls avatar Apr 08 '16 17:04 ryanwalls

@samuelkarp Think that retaining stopped tasks longer is something that could be put on the roadmap?

ryanwalls avatar Apr 14 '16 19:04 ryanwalls

@ryanwalls I can record this as a feature request. If you have any additional details on your use case, that can certainly help us prioritize.

In the meantime, there are a few places you can get additional debugging information:

  • The agent reports state to ECS by calling the SubmitContainerStateChange and SubmitTaskStateChange APIs, which are recorded in AWS CloudTrail.
  • On the instance, the agent logs record information about why tasks stopped, including the exit code. You may need to enable debug logging to get full details.
  • By default, containers are preserved on the instance for 3 hours after they exit (either exiting on their own or being stopped by the agent). This behavior can be tuned by adjusting the ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION environment variable.

samuelkarp avatar Apr 14 '16 20:04 samuelkarp

We use ECS along with auto-scaling, so our servers are rarely around for very long, which means the agents aren't around long either. So we lose a lot of data when the task history goes away.

We use --log-driver=syslog when running the agent container. Will it send debug logs to stdout (and therefore to syslog)?

ryanwalls avatar Apr 14 '16 22:04 ryanwalls

If you set ECS_LOGLEVEL=debug, yes.

samuelkarp avatar Apr 14 '16 22:04 samuelkarp

@ryanwalls Let us know if there's anything else we can help you with on this issue, otherwise I'll go ahead and close this issue in a few days.

juanrhenals avatar Apr 22 '16 16:04 juanrhenals

@juanrhenals I still would like to have it as a feature request. Would rather not close until it is implemented, but that's up to you guys.

ryanwalls avatar Apr 22 '16 20:04 ryanwalls

@ryanwalls Today we announced that ECS sends state changes to CloudWatch Events, which you can use to keep track of tasks that are interesting to you. For more information please see the documentation.

samuelkarp avatar Nov 22 '16 01:11 samuelkarp

In case anyone comes across this issue, we have implemented the following solution to store ECS stopped tasks in CloudWatch Logs.

https://github.com/aws-samples/amazon-ecs-stopped-tasks-cwlogs

fjromerom avatar Jun 18 '20 18:06 fjromerom