Skip to content

Commit 940a8ce

Browse files
committed
Log when user or classroom blocked for first time
1 parent 1106d59 commit 940a8ce

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

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)