Skip to content

chore(tests): add scheduled sweeper for leaked e2e infrastructure - #5599

Merged
dreamorosi merged 6 commits into
mainfrom
chore/e2e-stale-stack-sweeper
Aug 31, 2026
Merged

dreamorosi merged 6 commits into
mainfrom
chore/e2e-stale-stack-sweeper

Conversation

@dreamorosi

Copy link
Copy Markdown
Contributor

Summary

Adds a nightly GitHub Actions workflow that removes leaked e2e CloudFormation stacks from the test account, as a final safety net for the hourly-billed LMI capacity provider infrastructure introduced by #5465. Stacks become eligible 12 hours after creation when they carry the Service=Powertools-for-AWS-e2e-tests tag or an LmiShared-* name.

Changes

  • Add sweepStaleStacks to packages/testing (new e2e:sweep script): paginated discovery via DescribeStacks (root stacks only, 12-hour age gate, exact tag or LmiShared- prefix), all-or-nothing discovery, two dependency-ordered deletion passes (function stacks before shared capacity providers), concurrency capped at 5, 20-minute per-stack waits by stack id, no force deletion
  • Enforce an internal 50-minute time budget so the report is always emitted before the 60-minute job cap; leftover stacks are reported unresolved
  • Skip and report stacks with operations in progress; REVIEW_IN_PROGRESS is terminal and holds no resources, so those are deleted
  • Emit a sanitized single-line JSON report (account ids and ARNs redacted) on stdout, exit nonzero when stacks remain unresolved
  • Add sweep-stale-e2e-stacks.yml: nightly cron plus manual dispatch defaulting to dry run (discovery only, job summary, no issue); reuses the existing e2e-tests OIDC environment; workflow concurrency group prevents overlapping sweeps
  • Add report_e2e_sweep.js: on failed real runs, creates or comments on a single incident issue deduplicated by exact title (no labels managed, no auto-close); issue bodies are truncated below GitHub's size limit; the same formatter renders the job summary
  • Apply the e2e service tag to caller-supplied TestStack stacks so the tag-based selector also covers the layer publisher stack; drop the now-redundant manual tag in sharedCapacityProviderStack
  • Add 49 mocked unit tests covering pagination, selection, age and status handling, dependency ordering, bounded concurrency, retries, time budget, dry run, and report sanitization

Issue number: closes #5519


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

Add a nightly GitHub Actions workflow that deletes stale e2e CloudFormation
stacks from the test account. Stacks become eligible 12 hours after creation
when they carry the e2e service tag or an LmiShared-* name. Deletion runs in
two dependency-ordered passes (function stacks before shared capacity
providers) with bounded concurrency and no force deletion; discovery must
complete before anything is deleted. Unresolved stacks open or update a single
sanitized incident issue and fail the run; a later clean sweep closes it.
Manual dispatch defaults to a dry run that only writes a job summary.

Also apply the e2e service tag to caller-supplied TestStack stacks so the
tag-based selector covers the layer publisher stack.

Refs #5519
Enforce a 50-minute wall-clock budget inside the sweeper so the report is
always emitted before the 60-minute job cap kills the process; remaining
stacks are reported unresolved instead of fabricating a discovery failure.
Treat REVIEW_IN_PROGRESS as deletable: it is a terminal status holding no
resources, and skipping it would fail every nightly run indefinitely.

Make the dispatch dry-run computation fail toward dry run, rename the input
to snake_case, add a workflow concurrency group, surface dry-run sweeper
errors, and drop the redundant build step. In the notification script,
consume report.ok, cap issue-body sections to avoid the 65k limit, guard the
label-creation race, and share the markdown formatter with the job summary.

Also align JSDoc and unit tests with the repo rules and pin the concurrency
limit and time budget with mutation-verified tests.

Refs #5519
Create the incident issue without managing any labels and deduplicate by
exact title instead of a label lookup. Drop the auto-close path: a clean run
does nothing and the incident stays open until a maintainer closes it.

Refs #5519
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/XXL PRs with 1K+ LOC, largely documentation related label Aug 31, 2026
Describe purpose, triggers, failure behavior, and authentication at the top
of the workflow, matching the header style of make-release.yml.

Refs #5519
Comment thread .github/scripts/report_e2e_sweep.js
Comment thread packages/testing/src/e2e/sweepStaleStacks.ts Outdated
Comment thread packages/testing/src/e2e/sweepStaleStacks.ts Outdated
Comment thread packages/testing/tests/unit/sweepStaleStacks.test.ts Outdated
Use the SDK paginateDescribeStacks paginator instead of a hand-rolled
NextToken loop, inline the markUnresolved helper at its call sites, and
replace the duck-typed client cast in tests with aws-sdk-client-mock so the
paginator receives a real CloudFormationClient instance.

Refs #5519
@dreamorosi
dreamorosi marked this pull request as ready for review August 31, 2026 14:50
@dreamorosi
dreamorosi requested a review from svozza August 31, 2026 14:53
@dreamorosi
dreamorosi enabled auto-merge (squash) August 31, 2026 18:38
@dreamorosi
dreamorosi merged commit 7fea722 into main Aug 31, 2026
40 checks passed
@dreamorosi
dreamorosi deleted the chore/e2e-stale-stack-sweeper branch August 31, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XXL PRs with 1K+ LOC, largely documentation related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maintenance: Add a scheduled sweeper for leaked e2e infrastructure

2 participants