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

feat(dynamodb): add new check dynamodb_table_autoscaling_enabled #5129

Conversation

danibarranqueroo
Copy link
Member

@danibarranqueroo danibarranqueroo commented Sep 20, 2024

Context

This new check verifies that Amazon DynamoDB tables are configured to automatically scale their capacity based on demand. The control fails if the table does not use on-demand capacity mode or provisioned mode is used without auto scaling enabled.
Auto scaling helps ensure that DynamoDB tables adjust their read and write capacity dynamically in response to traffic patterns, which prevents throttling exceptions and maintains application availability. Tables in on-demand mode automatically adjust capacity to handle varying workloads, while provisioned mode with auto scaling adjusts based on predefined parameters.

As we can see here, the billing mode of the table set if the capacity is adjust to on-demand or provisioned:

BillingMode (string) –
Controls how you are charged for read and write throughput and how you manage capacity. This setting can be changed later.
PROVISIONED - Sets the read/write capacity mode to PROVISIONED. We recommend using PROVISIONED for predictable workloads.
PAY_PER_REQUEST - Sets the read/write capacity mode to PAY_PER_REQUEST. We recommend using PAY_PER_REQUEST for unpredictable workloads.

And then, if the table is set as PROVISIONED, you can choose to have or not enabled read/write capacity to auto-scaling. This can be verify using the ApplicationAutoScaling service of AWS.

Description

Added new check dynamodb_table_autoscaling_enabled, modified the service and added unit tests.

Checklist

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the provider/aws Issues/PRs related with the AWS provider label Sep 20, 2024
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 97.22222% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.10%. Comparing base (a08cc76) to head (4a38d19).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...rs/aws/services/autoscaling/autoscaling_service.py 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5129      +/-   ##
==========================================
- Coverage   89.10%   89.10%   -0.01%     
==========================================
  Files         993      995       +2     
  Lines       30509    30581      +72     
==========================================
+ Hits        27186    27249      +63     
- Misses       3323     3332       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danibarranqueroo danibarranqueroo added the no-merge Please, DO NOT MERGE this PR. label Sep 24, 2024
@danibarranqueroo danibarranqueroo removed the no-merge Please, DO NOT MERGE this PR. label Sep 25, 2024
Comment on lines 126 to 156
def _describe_autoscaling(self):
logger.info("DynamoDB - Describing Auto Scaling...")
try:
for table in self.tables.values():
if table.billing_mode == "PROVISIONED":
application_autoscaling_client = self.session.client(
"application-autoscaling", region_name=table.region
)
read_response = (
application_autoscaling_client.describe_scalable_targets(
ServiceNamespace="dynamodb",
ResourceIds=[f"table/{table.name}"],
ScalableDimension="dynamodb:table:ReadCapacityUnits",
)
)
if read_response["ScalableTargets"]:
table.read_autoscaling = True
write_response = (
application_autoscaling_client.describe_scalable_targets(
ServiceNamespace="dynamodb",
ResourceIds=[f"table/{table.name}"],
ScalableDimension="dynamodb:table:WriteCapacityUnits",
)
)
if write_response["ScalableTargets"]:
table.write_autoscaling = True
except Exception as error:
logger.error(
f"{error.__class__.__name__}:{error.__traceback__.tb_lineno} -- {error}"
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, as you are using another client, put this function in the autoscaling service in a new class.

@sergargar sergargar self-requested a review September 30, 2024 13:44
@sergargar sergargar merged commit 2c2dd82 into master Oct 2, 2024
10 of 11 checks passed
@sergargar sergargar deleted the PRWLR-4477-ensure-dynamo-db-tables-automatically-scale-capacity-with-demand branch October 2, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider/aws Issues/PRs related with the AWS provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants