Files
floci/docs
Mario Toffia 1b15299228 feat(ecs): publish Container Insights task counts (#6054)
* feat(ecs): publish Container Insights task counts

A service on a cluster whose containerInsights setting is enabled or enhanced publishes RunningTaskCount, PendingTaskCount and DesiredTaskCount to ECS/ContainerInsights once a minute, with ClusterName and ServiceName dimensions, while it has a running task. The AWS::ECS::Cluster provisioner applies ClusterSettings and restores the prior settings when a stack update rolls back.

* fix(ecs): resolve ClusterSettings as a whole before reading it

A ClusterSettings list wrapped in Fn::If was iterated unresolved and stored a setting with no name or value. Resolve the property node first, as the provisioner does for its other list properties.

* fix(ecs): resolve ClusterSettings before creating the cluster

A ClusterSettings value that failed to resolve left a cluster the stack did not track. Resolve first, and skip an entry that resolved to AWS::NoValue.

* fix(ecs): date Container Insights counts by the minute they were observed

* fix(ecs): count Container Insights tasks when they are published

The task counts came from the service's cached runningCount, which the
reconcile sets before it scales the service in or out, and from a
pendingCount nothing ever sets. They are now counted from the service's
own tasks after the tick has started and stopped them, so a scale-in is
reported in the tick that stops the task and a PENDING task is counted.

A committed in-place cluster update now drops its settings snapshot in
completeUpdate: the engine only calls clearUpdate after a replacement,
so the snapshot outlived the update it belonged to.

* docs(ecs): note that removing ClusterSettings keeps the cluster's settings

* test(ecs): cover restoring null cluster settings and read the latest metric bucket

A stack update that adds ClusterSettings to a cluster created without any rolls back to null settings, through the JSON null in the snapshot; the rollback test now covers that case alongside a prior disabled setting.

The scale-in test reads the latest one-minute bucket, so a minute rollover between its two reconciles no longer splits the samples into two buckets and fails the test.

* fix(ecs): log a failed Container Insights write as a warning

The publish ran inside the reconcile's catch, which logs only the message at debug level, so a failed metric write left the minute's sample missing without a trace. It now has its own try and logs the exception at warn.

* perf(ecs): write a Container Insights sample only when a count changes

The reconciler ticks every five seconds and wrote all three counts each time, and a persistent metric store rewrites its file on every put. The last sample written per account and service is kept, and the minute's sample is written again only when a count changes. A reset clears it, since it wipes the samples too.

* fix(cloudformation): restore ECS cluster settings when their own update fails

A failed provision puts back the resource the stack held before the attempt, which never carried the settings snapshot, so the rollback walker skipped it and the new settings stayed. The provisioner now restores the snapshot itself, as the other in-place provisioners do, and records a restore that fails as a rollback failure. The physical id is set before the settings call, so the restore and a create rollback both find the cluster.

* fix(ecs): repeat a Container Insights write that failed partway

The last sample written was kept until the next one replaced it, so when one count landed and the next write failed, and the counts then went back to the ones last written, the next tick skipped the minute and left the partial value in place. The record is now dropped before writing and set again only once all three counts are written.

* fix(cloudformation): keep an ECS settings snapshot whose restore failed

When a cluster's settings update and its own restore both failed, the snapshot stayed on the attempted resource, and the engine put back the prior resource without it. The first rollback reported the failure, and ContinueUpdateRollback then found no snapshot and reported the rollback complete with the new settings still live. The snapshot is now carried onto the restored resource, so the continuation retries the restore.

* fix(cloudformation): create an ECS cluster with its settings

A new cluster was created and then given its ClusterSettings in a second call. When that call failed, on a stack create or a rename, nothing tracked the cluster: the create rollback skips a CREATE_FAILED resource it does not own, and a rename never reached the replacement record. The settings now go into CreateCluster itself, so a new cluster is never left without them. A cluster the idempotent create returned, which the stack did not create, still has them applied separately and is not deleted when that fails.

* fix(cloudformation): set an ECS cluster's id only once its settings apply

The physical id was set before the settings call. When an update added a cluster under the name of one created outside the stack, the idempotent create returned that cluster, and if its settings then failed, the update rollback deleted the added resource and with it a cluster the stack never created. The id is set after the settings again; an update of the resource's own cluster already carries its prior id for the restore.

* fix(cloudformation): restore the settings of an ECS cluster the stack found

Only a resource's own cluster had its prior settings put back when the settings call failed. A cluster the idempotent create returned for a resource the stack creates or adds kept whatever a failed call left on it, while the rollback, which drops the resource, reported a clean finish. A cluster whose settings still differ after CreateCluster existed before, so its prior settings are now captured and restored either way; the snapshot attribute for the rollback walker stays on the resource's own cluster only.

* test(ecs): date Container Insights samples by a clock the test pins

publishContainerInsights read the minute from the wall clock, so the test of an unchanged sample skipped itself when the minute rolled over between its ticks. The minute now comes from a Clock given to a package-private constructor, which the injected one calls with Clock.systemUTC(); the test pins it and asserts the sample is dated by it.

* test(ecs): drive the reconciler instead of waiting on its ticks

The CloudFormation integration test waited up to 30 seconds for the background reconciler to launch the task and publish its count. It now calls reconcileServices twice, as the other ECS integration tests do.
2026-10-21 06:59:33 -04:00
..
2026-03-15 17:43:56 -05:00