Logs time between sent_at and the provider callback into statsd

This commit is contained in:
Martyn Inglis
2016-09-13 13:04:44 +01:00
parent 8541f6adcd
commit 517cec173b
4 changed files with 95 additions and 53 deletions

View File

@@ -79,10 +79,11 @@ def process_ses_response():
try:
reference = ses_message['mail']['messageId']
if not notifications_dao.update_notification_status_by_reference(
reference,
notification_status
):
notification = notifications_dao.update_notification_status_by_reference(
reference,
notification_status
)
if not notification:
error = "SES callback failed: notification either not found or already updated " \
"from sending. Status {}".format(notification_status)
raise InvalidRequest(error, status_code=404)
@@ -96,6 +97,7 @@ def process_ses_response():
)
statsd_client.incr('callback.ses.{}'.format(notification_status))
statsd_client.timing('callback.ses.elapsed-time', (datetime.utcnow() - notification.sent_at))
return jsonify(
result="success", message="SES callback succeeded"
), 200
@@ -231,8 +233,8 @@ def send_notification(notification_type):
raise InvalidRequest(errors, status_code=400)
if (
template_object.template_type == SMS_TYPE and
template_object.replaced_content_count > current_app.config.get('SMS_CHAR_COUNT_LIMIT')
template_object.template_type == SMS_TYPE and
template_object.replaced_content_count > current_app.config.get('SMS_CHAR_COUNT_LIMIT')
):
char_count = current_app.config.get('SMS_CHAR_COUNT_LIMIT')
message = 'Content has a character count greater than the limit of {}'.format(char_count)
@@ -240,14 +242,14 @@ def send_notification(notification_type):
raise InvalidRequest(errors, status_code=400)
if all((
api_user.key_type != KEY_TYPE_TEST,
service.restricted or api_user.key_type == KEY_TYPE_TEAM,
not allowed_to_send_to(
notification['to'],
itertools.chain.from_iterable(
[user.mobile_number, user.email_address] for user in service.users
api_user.key_type != KEY_TYPE_TEST,
service.restricted or api_user.key_type == KEY_TYPE_TEAM,
not allowed_to_send_to(
notification['to'],
itertools.chain.from_iterable(
[user.mobile_number, user.email_address] for user in service.users
)
)
)
)):
if (api_user.key_type == KEY_TYPE_TEAM):
message = 'Cant send to this recipient using a team-only API key'