fix(snapshot ecs): handle clusters with zero services#966
Conversation
kosli snapshot ecs aborted when any scanned cluster had no services, because getFilteredECSServicesInCluster called DescribeServices with an empty Services list, which AWS rejects with InvalidParameterException: Services cannot be empty. Guard the empty case so an empty cluster contributes zero services instead of erroring. Introduce an ECSServicesAPI interface and a FakeECSClient (mirroring the existing Lambda pattern) so the behaviour is covered by unit tests without live AWS. Fixes #965
|
Claude finished @dangrondahl's task in 1m 41s —— View job Review: PR #966 — handle clusters with zero services
Verdict: LGTM. This is a tight, well-scoped regression fix with the right test coverage. Recommend merging. Static analysis
(Note: CorrectnessThe fix is exactly right. Testing — nicely done
Minor / non-blocking
|
|
Thanks for the review. Both notes are non-blocking and need no code change:
Leaving the code as-is. Ready to merge. |
Summary
kosli snapshot ecsaborted when any scanned cluster had no ECS services, failing with:This is a regression introduced in #556 (first in v2.11.26, present in v2.28.0).
getFilteredECSServicesInClustercalledDescribeServiceswith the service ARNs fromListServices; when a cluster has no services that list is empty, and the AWS ECS API rejects an emptyServiceslist. The pre-#556 code guarded the equivalent describe call with alen(...) > 0check; the rewrite dropped it.Fix
Guard the empty case so an empty cluster contributes zero services instead of erroring.
Testability
The repo had no mock layer for ECS, so this follows the existing Lambda pattern (
LambdaAPIinterface +fake_lambda.go):ECSServicesAPIinterface — the real*ecs.Clientsatisfies it implicitly;getFilteredECSServicesInClusternow takes the interface (no production behaviour change).fake_ecs.go—FakeECSClientwhoseDescribeServicesreproduces the real AWS contract (errors on an emptyServiceslist).ecs_services_test.go— empty-cluster regression test (reproduces the exact bug-report error) plus a happy-path test.These run via
go test ./internal/aws/with no Docker server and no AWS credentials.Verification
InvalidParameterException: Services cannot be empty, passes after.internal/awspackage green,go vetclean,golangci-lint0 issues,go build ./...succeeds.Closes #965