From 89cea9a2e7de9ad252c966f3b999d46396da6ead Mon Sep 17 00:00:00 2001 From: Ben Thorner Date: Mon, 26 Apr 2021 13:51:34 +0100 Subject: [PATCH] Warn about SMS failures when it's cost effective MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously we warned when as little as 100 SMS messages failed, which equates to £1.60 in cost. This increases the absolute threshold so that we avoid taking action when the cost in developer time is greater than the money wasted. If it takes us an hour to solve the ticket, then that equates to roughly £100 in people costs. In future, we should also consider simplifying this check to be about permanent failures in general. --- app/celery/scheduled_tasks.py | 2 +- app/dao/services_dao.py | 4 ++-- tests/app/celery/test_scheduled_tasks.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index f3d5e39bc..8625dbac8 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -274,7 +274,7 @@ def check_for_services_with_high_failure_rates_or_sending_to_tv_numbers(): ) message += "service: {} failure rate: {},\n".format(service_dashboard, service.permanent_failure_rate) elif services_sending_to_tv_numbers: - message += "{} service(s) have sent over 500 sms messages to tv numbers in last 24 hours:\n".format( + message += "{} service(s) have sent high volumes of sms messages to tv numbers in last 24 hours:\n".format( len(services_sending_to_tv_numbers) ) for service in services_sending_to_tv_numbers: diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 3c7d42722..b992ef933 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -542,7 +542,7 @@ def dao_fetch_active_users_for_service(service_id): return query.all() -def dao_find_services_sending_to_tv_numbers(start_date, end_date, threshold=500): +def dao_find_services_sending_to_tv_numbers(start_date, end_date, threshold=62_500): return db.session.query( Notification.service_id.label('service_id'), func.count(Notification.id).label('notification_count') @@ -563,7 +563,7 @@ def dao_find_services_sending_to_tv_numbers(start_date, end_date, threshold=500) ).all() -def dao_find_services_with_high_failure_rates(start_date, end_date, threshold=100): +def dao_find_services_with_high_failure_rates(start_date, end_date, threshold=62_500): subquery = db.session.query( func.count(Notification.id).label('total_count'), Notification.service_id.label('service_id') diff --git a/tests/app/celery/test_scheduled_tasks.py b/tests/app/celery/test_scheduled_tasks.py index 9e67e4920..bf2d09ec9 100644 --- a/tests/app/celery/test_scheduled_tasks.py +++ b/tests/app/celery/test_scheduled_tasks.py @@ -564,9 +564,9 @@ MockServicesWithHighFailureRate = namedtuple( ], [ [], - [MockServicesSendingToTVNumbers("123", 300)], - "1 service(s) have sent over 500 sms messages to tv numbers in last 24 hours:\n" - "service: {}/services/{} count of sms to tv numbers: 300,\n".format( + [MockServicesSendingToTVNumbers("123", 63_000)], + "1 service(s) have sent high volumes of sms messages to tv numbers in last 24 hours:\n" + "service: {}/services/{} count of sms to tv numbers: 63000,\n".format( Config.ADMIN_BASE_URL, "123" ) ]