Log warning for SES send rate throttling rather than exception

We have hit throttling limits from SES approximately once a week during
a spike of traffic from GOV.UK. The rate limiting usually only lasts a
couple of minutes but generates enough exceptions to cause a p1 but with
no potential action for the responder.

Therefore we downgrade the warning for this case to a warning and assume
traffic will level back out such that the problem resolves itself.

Note, we will still get exceptions if we go over our daily limit, rather
than our per minute sending limit, which does require immediate action
by someone responding.

If we were to continually go over our per second sending rate for a long
continous period of time, then there is a chance we may not be aware but
given the risk of this happening is low I think it's an acceptable risk
for the moment.
This commit is contained in:
David McDonald
2020-08-13 17:18:19 +01:00
parent ff0e655838
commit 36614e5492
4 changed files with 102 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ from unittest.mock import Mock, ANY
from notifications_utils.recipients import InvalidEmailError
from app import aws_ses_client
from app.clients.email.aws_ses import get_aws_responses, AwsSesClientException
from app.clients.email.aws_ses import get_aws_responses, AwsSesClientException, AwsSesClientThrottlingSendRateException
def test_should_return_correct_details_for_delivery():
@@ -116,6 +116,48 @@ def test_send_email_raises_bad_email_as_InvalidEmailError(mocker):
assert 'definitely@invalid_email.com' in str(excinfo.value)
def test_send_email_raises_send_rate_throttling_as_AwsSesClientThrottlingSendRateException(mocker):
boto_mock = mocker.patch.object(aws_ses_client, '_client', create=True)
mocker.patch.object(aws_ses_client, 'statsd_client', create=True)
error_response = {
'Error': {
'Code': 'Throttling',
'Message': 'Maximum sending rate exceeded.',
'Type': 'Sender'
}
}
boto_mock.send_email.side_effect = botocore.exceptions.ClientError(error_response, 'opname')
with pytest.raises(AwsSesClientThrottlingSendRateException):
aws_ses_client.send_email(
source=Mock(),
to_addresses='foo@bar.com',
subject=Mock(),
body=Mock()
)
def test_send_email_does_not_raise_AwsSesClientThrottlingSendRateException_if_non_send_rate_throttling(mocker):
boto_mock = mocker.patch.object(aws_ses_client, '_client', create=True)
mocker.patch.object(aws_ses_client, 'statsd_client', create=True)
error_response = {
'Error': {
'Code': 'Throttling',
'Message': 'Daily message quota exceeded',
'Type': 'Sender'
}
}
boto_mock.send_email.side_effect = botocore.exceptions.ClientError(error_response, 'opname')
with pytest.raises(AwsSesClientException):
aws_ses_client.send_email(
source=Mock(),
to_addresses='foo@bar.com',
subject=Mock(),
body=Mock()
)
def test_send_email_raises_other_errs_as_AwsSesClientException(mocker):
boto_mock = mocker.patch.object(aws_ses_client, '_client', create=True)
mocker.patch.object(aws_ses_client, 'statsd_client', create=True)