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

Performance improvement: filter by DetachVolume event instead #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vikyol
Copy link

@vikyol vikyol commented Nov 6, 2019

Problem Statement
In this solution, CloudTrail events are filtered by ResourceType, which returns all API calls for EBS volumes. If this solution is run in an account with hundreds of instances and IGNORE_WINDOW is set to a large number, it takes a long time to process all CloudTrail events.

Sample execution times in one of my accounts:
IGNORE_WINDOW=30 -> 00:02:57
IGNORE_WINDOW=90 -> 00:09:16

Description of Changes:
We can reduce the execution times, if we change the logic to find aged volumes.

A volume is aged if:

  1. It has been detached before IGNORE_WINDOW.
    Change lookup_events filter to EventName=DetachVolume
    If a volume is detached within IGNORE_WINDOW, then it should not be removed.
  2. It has not been created within IGNORE_WINDOW.
    If a volume has been created but never been attached, the above filter fails to find it. To prevent this, we add this condition to include volumes which are created before IGNORE_WINDOW.

Sample execution times after this changes:
IGNORE_WINDOW=30 -> 00:00:08
IGNORE_WINDOW=90 -> 00:00:23

90-day window processed in just 23 seconds (vs. 556 seconds in original solution).

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

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.

1 participant