Remove everything for the performance platform

We no longer will send them any stats so therefore don't need the code
- the code to work out the nightly stats
- the performance platform client
- any configuration for the client
- any nightly tasks that kick off the sending off the stats

We will require a change in cronitor as we no longer will have this task
run meaning we need to delete the cronitor check.
This commit is contained in:
David McDonald
2021-03-11 18:53:43 +00:00
parent 8325431462
commit 41d95378ea
16 changed files with 9 additions and 570 deletions

View File

@@ -1,5 +1,5 @@
from datetime import date, datetime, timedelta
from unittest.mock import PropertyMock, call, patch
from unittest.mock import call
import pytest
import pytz
@@ -20,21 +20,15 @@ from app.celery.nightly_tasks import (
remove_sms_email_csv_files,
s3,
save_daily_notification_processing_time,
send_daily_performance_platform_stats,
send_total_sent_notifications_to_performance_platform,
timeout_notifications,
)
from app.celery.service_callback_tasks import (
create_delivery_status_callback_data,
)
from app.clients.performance_platform.performance_platform_client import (
PerformancePlatformClient,
)
from app.config import QueueNames
from app.exceptions import NotificationTechnicalFailureException
from app.models import EMAIL_TYPE, LETTER_TYPE, SMS_TYPE, FactProcessingTime
from tests.app.db import (
create_ft_notification_status,
create_job,
create_notification,
create_service,
@@ -232,55 +226,6 @@ def test_timeout_notifications_sends_status_update_to_service(client, sample_tem
mocked.assert_called_once_with([str(notification.id), encrypted_data], queue=QueueNames.CALLBACKS)
def test_send_daily_performance_stats_calls_does_not_send_if_inactive(client, mocker):
send_mock = mocker.patch(
'app.celery.nightly_tasks.total_sent_notifications.send_total_notifications_sent_for_day_stats') # noqa
with patch.object(
PerformancePlatformClient,
'active',
new_callable=PropertyMock
) as mock_active:
mock_active.return_value = False
send_daily_performance_platform_stats()
assert send_mock.call_count == 0
@freeze_time("2016-06-11 02:00:00")
def test_send_total_sent_notifications_to_performance_platform_calls_with_correct_totals(
notify_db_session,
sample_template,
sample_email_template,
mocker
):
perf_mock = mocker.patch(
'app.celery.nightly_tasks.total_sent_notifications.send_total_notifications_sent_for_day_stats') # noqa
today = date(2016, 6, 11)
create_ft_notification_status(bst_date=today, template=sample_template)
create_ft_notification_status(bst_date=today, template=sample_email_template)
# Create some notifications for the day before
yesterday = date(2016, 6, 10)
create_ft_notification_status(bst_date=yesterday, template=sample_template, count=2)
create_ft_notification_status(bst_date=yesterday, template=sample_email_template, count=3)
with patch.object(
PerformancePlatformClient,
'active',
new_callable=PropertyMock
) as mock_active:
mock_active.return_value = True
send_total_sent_notifications_to_performance_platform(yesterday)
perf_mock.assert_has_calls([
call(datetime(2016, 6, 9, 23, 0), 'sms', 2),
call(datetime(2016, 6, 9, 23, 0), 'email', 3),
call(datetime(2016, 6, 9, 23, 0), 'letter', 0)
])
def test_should_call_delete_inbound_sms(notify_api, mocker):
mocker.patch('app.celery.nightly_tasks.delete_inbound_sms_older_than_retention')
delete_inbound_sms()

View File

@@ -1,32 +0,0 @@
from datetime import datetime
from app.commands import (
backfill_performance_platform_totals,
backfill_processing_time,
)
def test_backfill_processing_time_works_for_correct_dates(mocker, notify_api):
send_mock = mocker.patch('app.commands.send_processing_time_for_start_and_end')
# backfill_processing_time is a click.Command object - if you try invoking the callback on its own, it
# throws a `RuntimeError: There is no active click context.` - so get at the original function using __wrapped__
backfill_processing_time.callback.__wrapped__(datetime(2017, 8, 1), datetime(2017, 8, 3))
assert send_mock.call_count == 3
send_mock.assert_any_call(datetime(2017, 7, 31, 23, 0), datetime(2017, 8, 1, 23, 0), datetime(2017, 8, 2, 0, 0))
send_mock.assert_any_call(datetime(2017, 8, 1, 23, 0), datetime(2017, 8, 2, 23, 0), datetime(2017, 8, 3, 0, 0))
send_mock.assert_any_call(datetime(2017, 8, 2, 23, 0), datetime(2017, 8, 3, 23, 0), datetime(2017, 8, 4, 0, 0))
def test_backfill_totals_works_for_correct_dates(mocker, notify_api):
send_mock = mocker.patch('app.commands.send_total_sent_notifications_to_performance_platform')
# backfill_processing_time is a click.Command object - if you try invoking the callback on its own, it
# throws a `RuntimeError: There is no active click context.` - so get at the original function using __wrapped__
backfill_performance_platform_totals.callback.__wrapped__(datetime(2017, 8, 1), datetime(2017, 8, 3))
assert send_mock.call_count == 3
send_mock.assert_any_call(datetime(2017, 8, 1))
send_mock.assert_any_call(datetime(2017, 8, 2))
send_mock.assert_any_call(datetime(2017, 8, 3))

View File

@@ -1,102 +0,0 @@
from datetime import date, datetime, timedelta
from freezegun import freeze_time
from app.dao.notifications_dao import (
dao_get_total_notifications_sent_per_day_for_performance_platform,
)
from app.models import KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST
from tests.app.db import create_notification
BEGINNING_OF_DAY = date(2016, 10, 18)
END_OF_DAY = date(2016, 10, 19)
def test_get_total_notifications_filters_on_date_within_date_range(sample_template):
create_notification(sample_template, created_at=datetime(2016, 10, 17, 23, 59, 59))
create_notification(sample_template, created_at=BEGINNING_OF_DAY)
create_notification(sample_template, created_at=datetime(2016, 10, 18, 23, 59, 59))
create_notification(sample_template, created_at=END_OF_DAY)
result = dao_get_total_notifications_sent_per_day_for_performance_platform(BEGINNING_OF_DAY, END_OF_DAY)
assert result.messages_total == 2
@freeze_time('2016-10-18T10:00')
def test_get_total_notifications_only_counts_api_notifications(sample_template, sample_job, sample_api_key):
create_notification(sample_template, one_off=True)
create_notification(sample_template, one_off=True)
create_notification(sample_template, job=sample_job)
create_notification(sample_template, job=sample_job)
create_notification(sample_template, api_key=sample_api_key)
result = dao_get_total_notifications_sent_per_day_for_performance_platform(BEGINNING_OF_DAY, END_OF_DAY)
assert result.messages_total == 1
@freeze_time('2016-10-18T10:00')
def test_get_total_notifications_ignores_test_keys(sample_template):
# Creating multiple templates with normal and team keys but only 1 template
# with a test key to test that the count ignores letters
create_notification(sample_template, key_type=KEY_TYPE_NORMAL)
create_notification(sample_template, key_type=KEY_TYPE_NORMAL)
create_notification(sample_template, key_type=KEY_TYPE_TEAM)
create_notification(sample_template, key_type=KEY_TYPE_TEAM)
create_notification(sample_template, key_type=KEY_TYPE_TEST)
result = dao_get_total_notifications_sent_per_day_for_performance_platform(BEGINNING_OF_DAY, END_OF_DAY)
assert result.messages_total == 4
@freeze_time('2016-10-18T10:00')
def test_get_total_notifications_ignores_letters(
sample_template,
sample_email_template,
sample_letter_template
):
# Creating multiple sms and email templates but only 1 letter template to
# test that the count ignores letters
create_notification(sample_template)
create_notification(sample_template)
create_notification(sample_email_template)
create_notification(sample_email_template)
create_notification(sample_letter_template)
result = dao_get_total_notifications_sent_per_day_for_performance_platform(BEGINNING_OF_DAY, END_OF_DAY)
assert result.messages_total == 4
@freeze_time('2016-10-18T10:00')
def test_get_total_notifications_counts_messages_within_10_seconds(sample_template):
created_at = datetime.utcnow()
create_notification(sample_template, sent_at=created_at + timedelta(seconds=5))
create_notification(sample_template, sent_at=created_at + timedelta(seconds=10))
create_notification(sample_template, sent_at=created_at + timedelta(seconds=15))
result = dao_get_total_notifications_sent_per_day_for_performance_platform(BEGINNING_OF_DAY, END_OF_DAY)
assert result.messages_total == 3
assert result.messages_within_10_secs == 2
@freeze_time('2016-10-18T10:00')
def test_get_total_notifications_counts_messages_that_have_not_sent(sample_template):
create_notification(sample_template, status='created', sent_at=None)
result = dao_get_total_notifications_sent_per_day_for_performance_platform(BEGINNING_OF_DAY, END_OF_DAY)
assert result.messages_total == 1
assert result.messages_within_10_secs == 0
@freeze_time('2016-10-18T10:00')
def test_get_total_notifications_returns_zero_if_no_data(notify_db_session):
result = dao_get_total_notifications_sent_per_day_for_performance_platform(BEGINNING_OF_DAY, END_OF_DAY)
assert result.messages_total == 0
assert result.messages_within_10_secs == 0

View File

@@ -16,7 +16,6 @@ from app.dao.fact_notification_status_dao import (
fetch_notification_statuses_for_job,
fetch_stats_for_all_services_by_date_range,
get_total_notifications_for_date_range,
get_total_sent_notifications_for_day_and_type,
update_fact_notification_status,
)
from app.models import (
@@ -601,51 +600,6 @@ def test_fetch_monthly_template_usage_for_service_does_not_include_test_notifica
assert len(results) == 0
@pytest.mark.parametrize("notification_type, count",
[("sms", 3),
("email", 5),
("letter", 7)])
def test_get_total_sent_notifications_for_day_and_type_returns_right_notification_type(
notification_type, count, sample_template, sample_email_template, sample_letter_template
):
create_ft_notification_status(bst_date="2019-03-27", service=sample_template.service, template=sample_template,
count=3)
create_ft_notification_status(bst_date="2019-03-27", service=sample_email_template.service,
template=sample_email_template, count=5)
create_ft_notification_status(bst_date="2019-03-27", service=sample_letter_template.service,
template=sample_letter_template, count=7)
result = get_total_sent_notifications_for_day_and_type(day='2019-03-27', notification_type=notification_type)
assert result == count
@pytest.mark.parametrize("day",
["2019-01-27", "2019-04-02"])
def test_get_total_sent_notifications_for_day_and_type_returns_total_for_right_day(
day, sample_template
):
date = datetime.strptime(day, "%Y-%m-%d")
create_ft_notification_status(bst_date=date - timedelta(days=1), notification_type=sample_template.template_type,
service=sample_template.service, template=sample_template, count=1)
create_ft_notification_status(bst_date=date, notification_type=sample_template.template_type,
service=sample_template.service, template=sample_template, count=2)
create_ft_notification_status(bst_date=date + timedelta(days=1), notification_type=sample_template.template_type,
service=sample_template.service, template=sample_template, count=3)
total = get_total_sent_notifications_for_day_and_type(day, sample_template.template_type)
assert total == 2
def test_get_total_sent_notifications_for_day_and_type_returns_zero_when_no_counts(
notify_db_session
):
total = get_total_sent_notifications_for_day_and_type("2019-03-27", "sms")
assert total == 0
@freeze_time('2019-05-10 14:00')
def test_fetch_monthly_notification_statuses_per_service(notify_db_session):
service_one = create_service(service_name='service one', service_id=UUID('e4e34c4e-73c1-4802-811c-3dd273f21da4'))

View File

@@ -1,47 +0,0 @@
from datetime import date, datetime, timedelta
from freezegun import freeze_time
from app.performance_platform.processing_time import (
send_processing_time_data,
send_processing_time_to_performance_platform,
)
from tests.app.db import create_notification
@freeze_time('2016-10-18T02:00')
def test_send_processing_time_to_performance_platform_generates_correct_calls(mocker, sample_template):
send_mock = mocker.patch('app.performance_platform.processing_time.send_processing_time_data')
created_at = datetime.utcnow() - timedelta(days=1)
create_notification(sample_template, created_at=created_at, sent_at=created_at + timedelta(seconds=5))
create_notification(sample_template, created_at=created_at, sent_at=created_at + timedelta(seconds=15))
create_notification(sample_template, created_at=datetime.utcnow() - timedelta(days=2))
send_processing_time_to_performance_platform(date(2016, 10, 17))
send_mock.assert_any_call(datetime(2016, 10, 16, 23, 0), 'messages-total', 2)
send_mock.assert_any_call(datetime(2016, 10, 16, 23, 0), 'messages-within-10-secs', 1)
def test_send_processing_time_to_performance_platform_creates_correct_call_to_perf_platform(mocker):
send_stats = mocker.patch('app.performance_platform.total_sent_notifications.performance_platform_client.send_stats_to_performance_platform') # noqa
send_processing_time_data(
start_time=datetime(2016, 10, 15, 23, 0, 0),
status='foo',
count=142
)
assert send_stats.call_count == 1
request_args = send_stats.call_args[0][0]
assert request_args['dataType'] == 'processing-time'
assert request_args['service'] == 'govuk-notify'
assert request_args['period'] == 'day'
assert request_args['status'] == 'foo'
assert request_args['_timestamp'] == '2016-10-16T00:00:00'
assert request_args['count'] == 142
expected_base64_id = 'MjAxNi0xMC0xNlQwMDowMDowMGdvdnVrLW5vdGlmeWZvb3Byb2Nlc3NpbmctdGltZWRheQ=='
assert request_args['_id'] == expected_base64_id

View File

@@ -1,59 +0,0 @@
from datetime import date, datetime
from freezegun import freeze_time
from app.performance_platform.total_sent_notifications import (
get_total_sent_notifications_for_day,
send_total_notifications_sent_for_day_stats,
)
from tests.app.db import create_ft_notification_status, create_template
def test_send_total_notifications_sent_for_day_stats_stats_creates_correct_call(mocker, client):
send_stats = mocker.patch('app.performance_platform.total_sent_notifications.performance_platform_client.send_stats_to_performance_platform') # noqa
send_total_notifications_sent_for_day_stats(
start_time=datetime(2016, 10, 15, 23, 0, 0),
notification_type='sms',
count=142
)
assert send_stats.call_count == 1
request_args = send_stats.call_args[0][0]
assert request_args['dataType'] == 'notifications'
assert request_args['service'] == 'govuk-notify'
assert request_args['period'] == 'day'
assert request_args['channel'] == 'sms'
assert request_args['_timestamp'] == '2016-10-16T00:00:00'
assert request_args['count'] == 142
expected_base64_id = 'MjAxNi0xMC0xNlQwMDowMDowMGdvdnVrLW5vdGlmeXNtc25vdGlmaWNhdGlvbnNkYXk='
assert request_args['_id'] == expected_base64_id
@freeze_time('2018-06-10 01:00')
def test_get_total_sent_notifications_yesterday_returns_expected_totals_dict(sample_service):
sms = create_template(sample_service, template_type='sms')
email = create_template(sample_service, template_type='email')
letter = create_template(sample_service, template_type='letter')
today = date(2018, 6, 10)
yesterday = date(2018, 6, 9)
# todays is excluded
create_ft_notification_status(bst_date=today, template=sms)
create_ft_notification_status(bst_date=today, template=email)
create_ft_notification_status(bst_date=today, template=letter)
# yesterdays is included
create_ft_notification_status(bst_date=yesterday, template=sms, count=2)
create_ft_notification_status(bst_date=yesterday, template=email, count=3)
create_ft_notification_status(bst_date=yesterday, template=letter, count=1)
total_count_dict = get_total_sent_notifications_for_day(yesterday)
assert total_count_dict == {
"email": 3,
"sms": 2,
"letter": 1
}