Skip to content

Commit af297ab

Browse files
authored
Merge pull request #346 from code-dot-org/ben/fix-throttling-alarms
Fix throttling alarms
2 parents 497aac5 + bab3cf4 commit af297ab

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -963,14 +963,14 @@ Resources:
963963
Type: AWS::CloudWatch::Alarm
964964
Properties:
965965
AlarmName: !Sub "${SubDomainName}_high_users_blocked"
966-
AlarmDescription: Unusually high number of users being blocked by our throttling
966+
AlarmDescription: Unusually high number of users being newly blocked by our throttling
967967
thresholds.
968968
ActionsEnabled: true
969969
OKActions: []
970970
AlarmActions:
971971
- !If [SilenceAlertsCondition, !Ref AWS::NoValue, !Sub "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:javabuilder-high-throttling"]
972972
InsufficientDataActions: []
973-
MetricName: UserBlocked
973+
MetricName: NewUserBlocked
974974
Namespace: Javabuilder
975975
Statistic: Sum
976976
Dimensions:
@@ -987,14 +987,14 @@ Resources:
987987
Type: AWS::CloudWatch::Alarm
988988
Properties:
989989
AlarmName: !Sub "${SubDomainName}_high_classrooms_blocked"
990-
AlarmDescription: Unusually high number of classrooms being blocked by our throttling
990+
AlarmDescription: Unusually high number of classrooms being newly blocked by our throttling
991991
thresholds.
992992
ActionsEnabled: true
993993
OKActions: []
994994
AlarmActions:
995995
- !If [SilenceAlertsCondition, !Ref AWS::NoValue, !Sub "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:javabuilder-high-throttling"]
996996
InsufficientDataActions: []
997-
MetricName: ClassroomBlocked
997+
MetricName: NewClassroomBlocked
998998
Namespace: Javabuilder
999999
Statistic: Sum
10001000
Dimensions:

javabuilder-authorizer/metrics_reporter.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ def initialize(context)
1111

1212
def log_token_error(status, error_message)
1313
puts error_message
14+
metric_name = TOKEN_STATUS_METRIC_NAMES[status]
15+
log(metric_name)
16+
end
17+
18+
def log(metric_name)
1419
metric_data = {
15-
metric_name: TOKEN_STATUS_METRIC_NAMES[status],
20+
metric_name: metric_name,
1621
dimensions: [
1722
{
1823
name: "functionName",

javabuilder-authorizer/token_status.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ module TokenStatus
4040
NOT_VETTED => 'TokenNotVetted',
4141
TOKEN_USED => 'TokenUsed'
4242
}.freeze
43+
44+
NEW_USER_BLOCKED = 'NewUserBlocked'.freeze
45+
NEW_CLASSROOM_BLOCKED = 'NewClassroomBlocked'.freeze
4346
end

javabuilder-authorizer/token_validator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def teachers_over_hourly_limit?
136136
},
137137
condition_expression: 'attribute_not_exists(user_id)'
138138
)
139+
@metrics_reporter.log(NEW_CLASSROOM_BLOCKED)
139140
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException
140141
# Do nothing if this teacher has already been added to blocked table
141142
# (possible if throttling limit was reached by a user on another lambda simultaneously)
@@ -244,6 +245,7 @@ def user_over_limit?(query_response, limit, logging_message)
244245
},
245246
condition_expression: 'attribute_not_exists(user_id)'
246247
)
248+
@metrics_reporter.log(NEW_USER_BLOCKED)
247249
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException
248250
# Do nothing if this user has already been added to blocked table
249251
# (possible if throttling limit was reached by the same user executing code on another lambda simultaneously)

0 commit comments

Comments
 (0)