Commit Graph

7099 Commits

Author SHA1 Message Date
David McDonald
e07dea27e1 Merge pull request #2791 from alphagov/link-to-runbook
Link to runbook
2020-04-02 10:28:49 +01:00
David McDonald
98d8388805 Add runbook link to ticket 2020-04-02 09:42:46 +01:00
David McDonald
b28fffc330 Refactor raise_alert_if_letter_notifications_still_sending
Move finding of letter logic into a separate method so it can be unit
tested rather than having to test it by checking the contents of a
zendesk ticket api call.

This will enable us to change the zendesk api ticket call message
without needing to edit lots of tests.
2020-04-02 09:36:56 +01:00
Pea M. Tyczynska
bf7a662b26 Merge pull request #2790 from alphagov/increase-startup-timeout
Increase startup timeout to 15 minutes
2020-04-01 15:27:17 +01:00
Pea Tyczynska
8a1a59a920 Increase startup timeout to 15 minutes - as it takes longer with 35 minimum instances 2020-04-01 15:11:06 +01:00
Pea M. Tyczynska
642eff9563 Merge pull request #2786 from alphagov/add-freezetime
Add missing freezetime to a test
2020-04-01 12:02:35 +01:00
Pea Tyczynska
f8286fdd21 Add missing freezetime to a test 2020-04-01 11:53:13 +01:00
Pea M. Tyczynska
cff7f7b72d Merge pull request #2751 from alphagov/validate-and-format-postcode-api-flow
Validate and format postcode for the API letter sending flow.
2020-04-01 11:09:25 +01:00
Rebecca Law
ac8fc49539 Merge pull request #2770 from alphagov/increase-qry-limit
Increase default query limit to 50,000 from 10,000
2020-03-31 17:15:12 +01:00
Rebecca Law
a7a158fe69 Merge pull request #2784 from alphagov/add-team-key-to-query
Add team key to query
2020-03-31 17:13:42 +01:00
Rebecca Law
ee45a2096c Merge pull request #2785 from alphagov/index-optimisation-1
Optimise indexes
2020-03-31 16:00:03 +01:00
Katie Smith
113ab4805f Merge pull request #2775 from alphagov/task-retries
Add retries to process_sanitised_letter task
2020-03-31 15:39:31 +01:00
Katie Smith
6d7bf5eef8 Merge pull request #2783 from alphagov/bump-utils
Bump utils to 36.9.3 to bring in new version of Bleach
2020-03-31 15:39:14 +01:00
Rebecca Law
5f8ea5d1f5 Remove duplicates 2020-03-31 15:17:27 +01:00
Pea M. Tyczynska
401c8e41d6 Merge pull request #2779 from alphagov/change-error-code
Change error code for duplicate reply-to address to 409 meaning conflict
2020-03-31 14:48:56 +01:00
Rebecca Law
7489cda6f0 Optimise indexes
Dropping unnecessary indexes on Notification and Notication_History
Create new composite indexes that should give queries better performance
Drop and create new indexes.

We are not running this migration on production because we want to run each one at a time.
Run this on staging then start run some load tests
2020-03-31 14:12:55 +01:00
David McDonald
2a528f03b8 Merge pull request #2781 from alphagov/fix-slow-org-user-query
fix the sql
2020-03-31 09:32:10 +01:00
Rebecca Law
1444150d48 Add team key to the notifications to delete/insert into notifications/notification_history 2020-03-31 09:23:41 +01:00
Katie Smith
7218e5887e Bump utils to 36.9.3 to bring in new version of Bleach 2020-03-31 09:13:24 +01:00
Leo Hemsted
8faeefc6cb Merge pull request #2780 from alphagov/fix-purge-task
fix purge functional test data task
2020-03-30 18:02:53 +01:00
Leo Hemsted
53b80b931f fix the sql
"if you want something done right, then do it yourself"

The ORM was building a weird and inefficient query to get all the users
for a given organisation_id:

old query:

```sql
SELECT users.*
FROM users
WHERE (
    EXISTS (
        SELECT 1
        FROM user_to_organisation, organisation
        WHERE users.id = user_to_organisation.user_id AND
        organisation.id = user_to_organisation.organisation_id AND
        organisation.id = '63b9557c-22ea-42ac-bcba-edaa50e3ae51'
    )
) AND
users.state = 'active'
ORDER BY users.created_at
```

Note the cross join on users_to_org and org, there are a lot of users in
organisations on preview, as one is added every functional test run.
Even though they're all filtered out and the query returns the correct
data, it still does the nested loop under the hood.

new query:

```sql
SELECT users.*
FROM users
JOIN user_to_organisation AS user_to_organisation_1 ON users.id = user_to_organisation_1.user_id
JOIN organisation ON organisation.id = user_to_organisation_1.organisation_id
WHERE organisation.id = '63b9557c-22ea-42ac-bcba-edaa50e3ae51' AND users.state = 'active' ORDER BY users.created_at;
```

Much more straightforward.
2020-03-30 17:47:15 +01:00
Leo Hemsted
885f3122bd fix purge functional test data task
* it doesn't delete service email reply to or letter contacts, or
  contact lists. I don't think the contact lists will ever be an issue
  but it doesn't hurt to add it to the list of things to remove.
* it doesn't remove users from organisations before deleting the users

there may be more tables that link to Service that should be deleted,
but for now just add these ones that I could spot.
2020-03-30 17:45:29 +01:00
Katie Smith
8b8e736e49 Add retries to process_sanitised_letter task
This task didn't have retries before, based on the assumption that if
the task failed it was likely to be due to a Boto error, so retrying
would not help because a file was probably not in the expected bucket.
During an incident with the database, we had some letters that were
stuck in the `pending-virus-check` state because this task failed.

This change adds retries to the task if there was an Exception that was
not a `BotoClientError`.
2020-03-30 17:28:01 +01:00
Pea Tyczynska
0250bee1a0 Change error code for duplicate reply-to address to 409 meaning conflict 2020-03-30 17:16:55 +01:00
David McDonald
c1ba3fb1be Merge pull request #2777 from alphagov/add-runbook-link
Add runbook link to resolve letters pending virus scan
2020-03-30 13:50:30 +01:00
David McDonald
87cb02fa1d Add runbook link to resolve letters pending virus scan 2020-03-30 12:07:05 +01:00
Rebecca Law
eaf38dd6a7 Merge pull request #2776 from alphagov/save-to-queue-gracefully-abort
if message too big to put on high volume queue then save to queue
2020-03-28 10:06:42 +00:00
Leo Hemsted
0b3d711652 if message too big to put on high volume queue then save to queue
SQS fails if the message body is over 256kb. Normally our messages are
quite small, but if we're using the new save-api-email task with an
email that has a large body, we can get over that limit. If so, handle
the exception and fall back to the existing code path (saving to the
database and sending a deliver-email task, which only has a notification
id.
2020-03-28 09:55:31 +00:00
Rebecca Law
c81388d004 Merge pull request #2774 from alphagov/fix-report-and-delete-tasks
Fix report and delete tasks
2020-03-27 16:30:16 +00:00
Rebecca Law
5d0830d7f7 Rename function for clarity 2020-03-27 15:48:54 +00:00
Chris Hill-Scott
4aed012d92 Merge pull request #2759 from alphagov/delete-contact-list
Add an endpoint to delete a contact list
2020-03-27 14:50:51 +00:00
Rebecca Law
46b72a6bbb Refactor process_ses_receipt
It is possible a service has data rention that is smaller than the time it takes to get a delivery receipt.
This PR refactors process_ses_receipt to update NotificationHistory if the Notifcation has already been purged.
2020-03-27 14:12:39 +00:00
Chris Hill-Scott
14605764bd Add comment explaining test data 2020-03-27 13:41:32 +00:00
Rebecca Law
8da73510c2 Delete all notification_status types.
This will ensure the whole day has been deleted. The stats table could get the wrong updates if there is partial data for a day.
2020-03-27 12:14:30 +00:00
David McDonald
814fb6043c Merge pull request #2773 from alphagov/move-high-volume-key-to-creds
Move high volume config
2020-03-27 11:08:04 +00:00
Rebecca Law
1d7c3466b0 Add cred to manifest 2020-03-27 10:08:30 +00:00
Chris Hill-Scott
5fe0fafadf Archive, don’t delete contact lists
So we keep a record of who first uploaded a list it’s better to archive
a list than completely delete it.

The list in the database doesn’t contain any recipient info so this
isn’t a change to what data we’re retaining.

This means updating the endpoints that get contact lists to exclude ones
that are archived.
2020-03-27 09:51:54 +00:00
Rebecca Law
dc44cb29d1 To make the deployment and testing a little easier move the high volume service ids to the credential repo.
This way we can only add the ids when we are ready and all the infrastrure for the new service has been applied.
2020-03-27 08:02:51 +00:00
Chris Hill-Scott
4a6143aeb1 Remove the list from S3 once we don’t need it
Once a contact list is gone from the database there’s no way to
reference it again. Any jobs have made their own copy.

So we can clean it up, meaning we’re not storing personal data longer
than we need to.
2020-03-26 17:42:38 +00:00
Chris Hill-Scott
b50dbab8fd Add an endpoint to delete a contact list
This was one of things we de-scoped when we first shipped this feature.

In order to safely delete a list, we first need to make sure any jobs
aren’t referencing it.
2020-03-26 17:42:38 +00:00
Rebecca Law
e4df43e412 Merge pull request #2771 from alphagov/take-pressure-off-api-db
Reduce the pressure on the db for API post email requests.
2020-03-26 12:03:30 +00:00
Rebecca Law
a801230fc4 Added test that the notification exists or not 2020-03-26 11:18:59 +00:00
Rebecca Law
d04bb1caca Remove argument from retry 2020-03-26 08:44:28 +00:00
Rebecca Law
d0a2e0f3ce Move high volume service id to config 2020-03-25 15:25:45 +00:00
Rebecca Law
db4b4d929d - If the task runs twice and the notification already exists ignore the primary key constraint.
- Remove prints
- Add some more tests
- Only allow the new method to run for emails
2020-03-25 12:39:15 +00:00
Rebecca Law
e5b6fa2143 Reduce log messages. 2020-03-25 08:08:33 +00:00
Rebecca Law
a13bcc6697 Reduce the pressure on the db for API post email requests.
Instead of saving the email notification to the db add it to a queue to save later.
This is an attempt to alleviate pressure on the db from the api requests.
This initial PR is to trial it see if we see improvement in the api performance an a reduction in queue pool errors. If we are happy with this we could remove the hard coding of the service id.

In a nutshell:
 - If POST /v2/notification/email is from our high volume service (hard coded for now) then create a notification to send to a queue to persist the notification to the db.
 - create a save_api_email task to persist the notification
 - return the notification
 - New worker app to process the save_api_email tasks.
2020-03-25 07:59:05 +00:00
Rebecca Law
31f83bb9c4 Increase default query limit to 50,000 from 10,000 2020-03-24 17:04:38 +00:00
Rebecca Law
544537791d Merge pull request #2768 from alphagov/optimise-delete-notifications-task
Refactor delete_notifications_older_than_retention_by_type
2020-03-24 15:04:48 +00:00
Rebecca Law
69102db4cb Remove the hourly loop and replace it with a while loop, which check if we still have things to delete for the day.
We are already limiting the query by a query limit.
2020-03-24 14:54:06 +00:00