Skip to content

feat(clean): reap leaked AMP integ-test workspaces - #2233

Open
olowosulu wants to merge 3 commits into
aws:mainfrom
olowosulu:feat/clean-amp-workspaces
Open

feat(clean): reap leaked AMP integ-test workspaces#2233
olowosulu wants to merge 3 commits into
aws:mainfrom
olowosulu:feat/clean-amp-workspaces

Conversation

@olowosulu

Copy link
Copy Markdown

Problem

The integration tests create one AMP (Amazon Managed Service for Prometheus) workspace per /amp run (terraform/ec2/linux/main.tf, module "amp", workspace_alias = "cwagent-integ-test-<testing_id>") and destroy it with terraform destroy at the end of the run.

Workspaces left behind by cancelled/superseded or hard-killed jobs, whose Terraform state dies with the ephemeral runner, are never reclaimed: the if: cancelled() || failure() cleanup terraform destroy cannot delete a workspace whose state is gone. These orphans accumulate to the per-region 75-workspace service quota. Once the region is at the cap, every new run fails at CreateWorkspace:

Error: creating Prometheus Workspace: ... StatusCode: 402,
ServiceQuotaExceededException: Limit exceeded. Maximum workspaces per region: 75

terraform apply then exits 1 before the Go test binary runs, so al2:selinux_amp_test fails with a red check unrelated to the code under review. An audit of the test region found dozens of orphaned cwagent-integ-test-* workspaces, the oldest over a year old, none created in the last day (leaked, not in-flight).

Fix

Every other leaked resource type already has a cleaner under tool/clean/clean_* run daily by clean-aws-resources.yml; AMP was the gap. This adds:

  • tool/clean/clean_amp/clean_amp.go (modeled on clean_eks): lists AMP workspaces and deletes ACTIVE ones whose alias has the cwagent-integ-test- prefix and were created longer ago than clean.KeepDurationOneDay. Supports -dry-run.
  • a clean-amp-workspaces job in clean-aws-resources.yml, using the same OIDC role (vars.TERRAFORM_AWS_ASSUME_ROLE), region, and daily schedule as the sibling cleaners.

Verification

  • go build and go vet are clean for clean_amp (the only go vet ./... finding is pre-existing unreachable code in clean_security_group, which this PR does not touch).
  • -dry-run against the test account matches an independent audit: it targets only cwagent-integ-test-* workspaces older than a day and spares non-test workspaces.
  • Adding service/amp pulled an aligned aws-sdk-go-v2 core bump within the isolated tool/clean module; all sibling cleaners still vet.

Prerequisite

The clean OIDC role (vars.TERRAFORM_AWS_ASSUME_ROLE) needs amp:ListWorkspaces and amp:DeleteWorkspace for the scheduled job to run.

Integration tests create one AMP (Amazon Managed Service for Prometheus)
workspace per /amp run (alias cwagent-integ-test-<id>) and destroy it via
terraform. Workspaces left behind by cancelled or hard-killed jobs, whose
terraform state dies with the ephemeral runner, accumulate to the per-region
75-workspace quota. Once at the cap every new run fails at CreateWorkspace with
ServiceQuotaExceededException before the Go test binary runs (observed on the
al2:selinux_amp_test job). The existing if:cancelled()||failure() terraform
destroy step cannot reclaim them because their state is gone.

Add tool/clean/clean_amp/clean_amp.go (modeled on clean_eks): list AMP
workspaces and delete ACTIVE ones whose alias has the cwagent-integ-test-
prefix and were created longer ago than KeepDurationOneDay. Supports -dry-run.
Add a clean-amp-workspaces job to clean-aws-resources.yml using the same OIDC
role and daily schedule as the other cleaners.

Adding service/amp pulled an aligned aws-sdk-go-v2 core bump in the isolated
tool/clean module. Verified: go build and go vet are clean for clean_amp; a
dry-run against the test account matches an independent audit (targets only
cwagent-integ-test-* workspaces and spares non-test workspaces).

Note: the clean OIDC role (vars.TERRAFORM_AWS_ASSUME_ROLE) needs
amp:ListWorkspaces and amp:DeleteWorkspace permissions for the scheduled job.
Comment thread tool/clean/clean_amp/clean_amp.go
Comment thread tool/clean/clean_amp/clean_amp.go Outdated
Comment thread tool/clean/clean_amp/clean_amp.go Outdated
Comment thread tool/clean/clean_amp/clean_amp.go
musa-asad
musa-asad previously approved these changes Aug 6, 2026
- Collect delete errors with errors.Join and return them
- Negate KeepDurationOneDay in log message for readable display
- Sweep CREATION_FAILED workspaces (dead but hold quota)
- Skip empty prefix entries in aliasMatchesWorkspacesToClean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants