From 077f04cfa9fd0fc5a40e4df6f998aad94acd7548 Mon Sep 17 00:00:00 2001 From: edX requirements bot Date: Tue, 3 Dec 2024 22:18:59 -0500 Subject: [PATCH] chore: Updating Python Requirements --- .pylintrc | 9 ++--- requirements/base.txt | 4 +-- requirements/test.txt | 16 ++++----- scripts/aws/monitor.py | 77 +++++++++++++++++++++++++++--------------- 4 files changed, 61 insertions(+), 45 deletions(-) diff --git a/.pylintrc b/.pylintrc index 8e11283..d4b473a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -72,11 +72,6 @@ disable= # (visual studio) and html output-format=text -# Put messages in a separate file for each module / package specified on the -# command line instead of printing them on stdout. Reports (if any) will be -# written in a file name "pylint_global.[txt|html]". -files-output=no - # Tells whether to display a full report or only the messages reports=no @@ -120,7 +115,7 @@ generated-members= [BASIC] # List of builtins function names that should not be used, separated by a comma -bad-functions=map,filter,apply,input +bad-names=map,filter,apply,input # Regular expression which should only match correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ @@ -240,7 +235,7 @@ max-locals=15 max-returns=6 # Maximum number of branch for function / method body -max-branchs=12 +max-branches=12 # Maximum number of statements in function / method body max-statements=50 diff --git a/requirements/base.txt b/requirements/base.txt index 2093e5d..bbf821c 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -6,9 +6,9 @@ # boto==2.49.0 # via google-compute-engine -boto3==1.35.73 +boto3==1.35.74 # via -r requirements/base.in -botocore==1.35.73 +botocore==1.35.74 # via # -r requirements/base.in # boto3 diff --git a/requirements/test.txt b/requirements/test.txt index 39b0fc1..25bb6ad 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -6,7 +6,7 @@ # annotated-types==0.7.0 # via pydantic -astroid==3.2.4 +astroid==3.3.5 # via pylint attrs==24.2.0 # via @@ -20,12 +20,12 @@ boto==2.49.0 # via # -r requirements/base.txt # google-compute-engine -boto3==1.35.73 +boto3==1.35.74 # via # -r requirements/base.txt # aws-sam-translator # moto -botocore==1.35.73 +botocore==1.35.74 # via # -r requirements/base.txt # aws-xray-sdk @@ -129,14 +129,12 @@ pycparser==2.22 # via cffi pycurl==7.45.3 # via pyresttest -pydantic==2.10.2 +pydantic==2.10.3 # via aws-sam-translator pydantic-core==2.27.1 # via pydantic -pylint==3.2.6 - # via - # -c requirements/constraints.txt - # -r requirements/test.in +pylint==3.3.2 + # via -r requirements/test.in pyparsing==3.2.0 # via moto pyresttest==1.7.1 @@ -173,7 +171,7 @@ responses==0.25.3 # via moto rfc3339-validator==0.1.4 # via openapi-schema-validator -rpds-py==0.22.0 +rpds-py==0.22.1 # via # jsonschema # referencing diff --git a/scripts/aws/monitor.py b/scripts/aws/monitor.py index bad139b..c29c6cb 100755 --- a/scripts/aws/monitor.py +++ b/scripts/aws/monitor.py @@ -49,7 +49,7 @@ def get_api_id(client, api_base_domain): return (response['restApiId'], response['stage']) -def create_api_alarm(cw_session, alarm_name, metric, +def create_api_alarm(*, cw_session, alarm_name, metric, namespace, stat, comparison, description, threshold, period, eval_period, dimensions, topic): """Puts data to the metric, then creates the alarm for appropriate metric in API Gateway""" @@ -92,7 +92,7 @@ def create_lambda_function_zip(jinja_env, temp_dir, splunk_host, splunk_token, l return zip_file -def get_lambda_exec_policy(jinja_env, temp_dir, region, acct_id, func_name, kms_key): +def get_lambda_exec_policy(*, jinja_env, temp_dir, region, acct_id, func_name, kms_key): """updates the policy json and returns it""" resource_values = { 'region': region, @@ -165,7 +165,7 @@ def create_role_with_managed_policy(iam, role_name, assume_role_policy_document, return response['Role']['Arn'] -def create_lambda_function(client, function_name, runtime, role, +def create_lambda_function(*, client, function_name, runtime, role, handler, zip_file, description, timeout, mem_size, vpc): """Creates a lambda function to pull data from cloudwatch event. It only works works in VPC""" @@ -274,30 +274,53 @@ def add_cloudwatchlog_role_to_apigateway(client, role_arn): sns_client = session.create_client('sns', args.aws_region) cw = session.create_client('cloudwatch', args.aws_region) - create_api_alarm(cw, 'api-gateway-count', 'Count', 'ApiGateway', - 'Average', 'GreaterThanOrEqualToThreshold', - 'Average API count for a period of 5 min', 50, 300, 1, - [{'Name': 'ApiName', 'Value': api_gateway_name}, - {'Name': 'Stage', 'Value': api_stage}, {'Name': 'ApiId', 'Value': api_id}], - get_topic_arn(sns_client, 'aws-non-critical-alert')) - - create_api_alarm(cw, 'api-gateway-latency', 'Latency', 'ApiGateway', 'Average', - 'GreaterThanOrEqualToThreshold', 'Average API Latency for a period of 5 min', 3, 300, 1, - [{'Name': 'ApiName', 'Value': api_gateway_name}, - {'Name': 'Stage', 'Value': api_stage}, {'Name': 'ApiId', 'Value': api_id}], - get_topic_arn(sns_client, 'aws-non-critical-alert')) - - create_api_alarm(cw, 'api-gateway-errors-4xx', '4XXError', 'ApiGateway', 'Average', - 'GreaterThanOrEqualToThreshold', 'Average 4XX errors for a period of 5 min', 4, 300, 1, - [{'Name': 'ApiName', 'Value': api_gateway_name}, - {'Name': 'Stage', 'Value': api_stage}, {'Name': 'ApiId', 'Value': api_id}], - get_topic_arn(sns_client, 'aws-non-critical-alert')) - - create_api_alarm(cw, 'api-gateway-errors-5xx', '5XXError', 'ApiGateway', 'Average', - 'GreaterThanOrEqualToThreshold', 'Average 5XX errors for a period of 5 min', 4, 300, 1, - [{'Name': 'ApiName', 'Value': api_gateway_name}, - {'Name': 'Stage', 'Value': api_stage}, {'Name': 'ApiId', 'Value': api_id}], - get_topic_arn(sns_client, 'aws-non-critical-alert')) + create_api_alarm( + cw_session=cw, alarm_name='api-gateway-count', metric='Count', namespace='ApiGateway', stat='Average', + comparison='GreaterThanOrEqualToThreshold', description='Average API count for a period of 5 min', + threshold=50, period=300, eval_period=1, + dimensions=[ + {'Name': 'ApiName', 'Value': api_gateway_name}, + {'Name': 'Stage', 'Value': api_stage}, + {'Name': 'ApiId', 'Value': api_id} + ], + topic=get_topic_arn(sns_client, 'aws-non-critical-alert') + ) + + create_api_alarm( + cw_session=cw, alarm_name='api-gateway-latency', metric='Latency', namespace='ApiGateway', stat='Average', + comparison='GreaterThanOrEqualToThreshold', description='Average API Latency for a period of 5 min', + threshold=3, period=300, eval_period=1, + dimensions=[ + {'Name': 'ApiName', 'Value': api_gateway_name}, + {'Name': 'Stage', 'Value': api_stage}, + {'Name': 'ApiId', 'Value': api_id} + ], + topic=get_topic_arn(sns_client, 'aws-non-critical-alert') + ) + + create_api_alarm( + cw_session=cw, alarm_name='api-gateway-errors-4xx', metric='4XXError', namespace='ApiGateway', stat='Average', + comparison='GreaterThanOrEqualToThreshold', description='Average 4XX errors for a period of 5 min', + threshold=4, period=300, eval_period=1, + dimensions=[ + {'Name': 'ApiName', 'Value': api_gateway_name}, + {'Name': 'Stage', 'Value': api_stage}, + {'Name': 'ApiId', 'Value': api_id} + ], + topic=get_topic_arn(sns_client, 'aws-non-critical-alert') + ) + + create_api_alarm( + cw_session=cw, alarm_name='api-gateway-errors-5xx', metric='5XXError', namespace='ApiGateway', stat='Average', + comparison='GreaterThanOrEqualToThreshold', description='Average 5XX errors for a period of 5 min', + threshold=4, period=300, eval_period=1, + dimensions=[ + {'Name': 'ApiName', 'Value': api_gateway_name}, + {'Name': 'Stage', 'Value': api_stage}, + {'Name': 'ApiId', 'Value': api_id} + ], + topic=get_topic_arn(sns_client, 'aws-non-critical-alert') + ) lambda_exec_role_arn = create_role_with_inline_policy(iam_client, lambda_role_name, '{"Version": "2012-10-17","Statement": '