Skip to content

Commit

Permalink
chore: Updating Python Requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
edx-requirements-bot authored and mumarkhan999 committed Jan 7, 2025
1 parent a2b493d commit 077f04c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 45 deletions.
9 changes: 2 additions & 7 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]+))$
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
77 changes: 50 additions & 27 deletions scripts/aws/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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": '
Expand Down

0 comments on commit 077f04c

Please sign in to comment.