Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect request limits when cleaning EC2 #20

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Dropping a requirement of a major version of a dependency is a new contract.

### Fixed
- Tag security groups atomically when created.
- Respect AWS request size limits in `TerminationBatchingEc2` and `TerminationPollingEc2`.

## [1.14.0] - 2024-01-04
[1.14.0]: https://github.com/atlassian-labs/aws-resources/compare/release-1.13.0...release-1.14.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TerminationBatchingEc2(
logger.trace("No instances to terminate")
return
}
val instanceIds = terminations.keys
val instanceIds = terminations.keys.take(1000)
logger.debug("Starting batch termination of $instanceIds")
ec2.terminateInstances(TerminateInstancesRequest().withInstanceIds(instanceIds))
instanceIds.forEach { instanceId ->
Expand All @@ -64,4 +64,4 @@ class TerminationBatchingEc2(
.thenAccept { terminatedId -> terminations.remove(terminatedId)?.complete(terminatedId) }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class TerminationPollingEc2(
logger.debug("No instances to poll")
return
}
val instanceIds = polls.keys.toList()
val instanceIds = polls.keys.take(200)
logger.debug("Polling $instanceIds")
val foundInstanceIds = mutableListOf<String>()
val foundInstanceIds = mutableSetOf<String>()
scrollingEc2.scrollThroughInstances(
Filter("instance-id", instanceIds)
) { instanceBatch ->
Expand All @@ -83,4 +83,4 @@ class TerminationPollingEc2(
.remove(instanceId)
?.complete(instanceId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ConcurrentHousekeeping(
val securityGroups = aws.ec2.describeSecurityGroups().securityGroups.map { securityGroup ->
Ec2SecurityGroup(securityGroup, aws.ec2)
}.filter { it.isExpired() }
waitUntilReleased(securityGroups)
waitUntilReleased(securityGroups, Duration.ofMinutes(3))

Cloudformation(aws, aws.cloudformation).consumeExpiredStacks(Consumer { stacks ->
waitUntilReleased(stacks, stackTimeout)
Expand Down
Loading