Skip to content

Commit ad65d40

Browse files
authored
Re-enable classroom limits and update alerts and metrics (#371)
* update threshold and alarm * add logs * update log * update log * remove debug help and update config * update name
1 parent 0b12f67 commit ad65d40

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

cicd/3-app/javabuilder/config/production.config.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"Parameters": {
33
"BaseDomainName": "code.org",
44
"BaseDomainNameHostedZonedID": "Z2LCOI49SCXUGU",
5-
"ProvisionedConcurrentExecutions": "150",
6-
"ReservedConcurrentExecutions": "1650",
5+
"ProvisionedConcurrentExecutions": "50",
6+
"ReservedConcurrentExecutions": "500",
77
"LimitPerHour": "1000",
88
"LimitPerDay": "5000",
9-
"SilenceAlerts": "false"
9+
"SilenceAlerts": "false",
10+
"TeacherLimitPerHour": "25000"
1011
},
1112
"Tags" : {
1213
"EnvType" : "production"

cicd/3-app/javabuilder/template.yml.erb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,12 +1012,11 @@ Resources:
10121012
ComparisonOperator: GreaterThanThreshold
10131013
TreatMissingData: notBreaching
10141014

1015-
HighClassroomsBlockedAlarm:
1015+
ClassroomBlockedAlarm:
10161016
Type: AWS::CloudWatch::Alarm
10171017
Properties:
1018-
AlarmName: !Sub "${SubDomainName}_high_classrooms_blocked"
1019-
AlarmDescription: Unusually high number of classrooms being newly blocked by our throttling
1020-
thresholds.
1018+
AlarmName: !Sub "${SubDomainName}_classroom_blocked"
1019+
AlarmDescription: A classroom was newly blocked by our threshold. Investigate if this is classroom should be blocked.
10211020
ActionsEnabled: true
10221021
OKActions: []
10231022
AlarmActions:
@@ -1032,8 +1031,8 @@ Resources:
10321031
Period: 60
10331032
EvaluationPeriods: 1
10341033
DatapointsToAlarm: 1
1035-
Threshold: 10
1036-
ComparisonOperator: GreaterThanThreshold
1034+
Threshold: 1
1035+
ComparisonOperator: GreaterThanOrEqualToThreshold
10371036
TreatMissingData: notBreaching
10381037

10391038
HighUnknownTokensAlarm:

javabuilder-authorizer/metrics_reporter.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ def log(metric_name)
3131
@client.put_metric_data({namespace: "Javabuilder", metric_data: [metric_data]})
3232
end
3333

34+
def log_count_with_value(metric_name, value)
35+
metric_data = {
36+
metric_name: metric_name,
37+
dimensions: [
38+
{
39+
name: "functionName",
40+
value: function_name
41+
}
42+
],
43+
unit: "Count",
44+
value: value
45+
}
46+
47+
@client.put_metric_data({namespace: "Javabuilder", metric_data: [metric_data]})
48+
end
49+
50+
3451
private
3552

3653
# ARN is of the format arn:aws:lambda:{region}:{account_id}:function:{lambda_name}

javabuilder-authorizer/token_status.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ module TokenStatus
4343

4444
NEW_USER_BLOCKED = 'NewUserBlocked'.freeze
4545
NEW_CLASSROOM_BLOCKED = 'NewClassroomBlocked'.freeze
46+
CLASSROOM_HOURLY_REQUEST_COUNT = 'ClassroomHourlyRequestCount'.freeze
4647
end

javabuilder-authorizer/token_validator.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,11 @@ def validate
2626
# TODO: uncomment other throttling thresholds once we have fine-tuned those limits
2727
return error(TOKEN_USED) unless log_token
2828
return error(USER_BLOCKED) if user_blocked?
29-
# return error(CLASSROOM_BLOCKED) if teachers_blocked?
29+
return error(CLASSROOM_BLOCKED) if teachers_blocked?
3030
hourly_usage_response = user_usage(ONE_HOUR_SECONDS)
3131
return error(USER_BLOCKED) if user_over_hourly_limit?(hourly_usage_response)
3232
# return error(USER_BLOCKED) if user_over_daily_limit?
33-
# return error(CLASSROOM_BLOCKED) if teachers_over_hourly_limit?
34-
35-
# for now, check and log if the teacher is over the hourly limit, but still
36-
# allow those users through until we fine tune the limit
37-
teachers_over_hourly_limit?
38-
33+
return error(CLASSROOM_BLOCKED) if teachers_over_hourly_limit?
3934

4035
near_limit_detail = get_user_near_hourly_limit_detail(hourly_usage_response.count)
4136
log_requests
@@ -130,6 +125,10 @@ def teachers_over_hourly_limit?
130125
puts "teacher_associated_requests query has paginated responses. user_id #{@user_id} teacher_id #{teacher_id}"
131126
end
132127

128+
# Log the count of requests per hour to a metric. We are logging this for now so we can determine if we
129+
# have set a good threshold for blocking classrooms.
130+
@metrics_reporter.log_count_with_value(CLASSROOM_HOURLY_REQUEST_COUNT, response.count)
131+
133132
if response.count > ENV['teacher_limit_per_hour'].to_i
134133
begin
135134
@dynamodb_client.put_item(

0 commit comments

Comments
 (0)