Commit Graph

5814 Commits

Author SHA1 Message Date
Leo Hemsted
bf62d3ad5f infer template/service from job for notification/ft_noti_status in db.py 2018-12-12 12:59:55 +00:00
Rebecca Law
4ddd38b440 Merge pull request #2257 from alphagov/add-index-to-notifications
New index for  notifications
2018-12-12 12:34:21 +00:00
Rebecca Law
4bb68c3e52 Merge pull request #2249 from alphagov/improve-performance-of-platform-admin-page
Improve performance of platform stats page
2018-12-12 12:20:13 +00:00
Rebecca Law
21a67556b8 Add an index on notifications for (service_id, created_at) to improve the performance of the notification queries.
We've already performed this update on production since you need to create the index concurrently, which is not allowed from the alembic script. For that reason we are checking if the index exists.
2018-12-12 12:14:49 +00:00
Pea (Malgorzata Tyczynska)
8b4655d8af Merge pull request #2255 from alphagov/switch_on_slow_goes_live
Switch providers on slow delivery goes live
2018-12-12 11:35:18 +00:00
Rebecca Law
852f1cbfe4 Merge pull request #2254 from alphagov/improve-performance-of-get-notifications-for-service
Remove the join to TemplateHistory.
2018-12-12 09:48:55 +00:00
Pea Tyczynska
af185adf4c Log the ratio of slow notifications 2018-12-11 15:28:38 +00:00
Pea Tyczynska
abe01c0bc0 Revert "Switch providers on slow delivery only produces logs"
This reverts commit 6938600ab8.
2018-12-11 15:14:08 +00:00
Rebecca Law
dfc12cc354 Remove the join to TemplateHistory.
We are adding an index to Notifications to optimize the get_notifications_for_service. We need to build the index concurrently which can not be run inside a transaction block so the index will need to be run on the db directly.

CREATE INDEX CONCURRENTLY ix_notifications_service_created_at ON notifications (service_id, created_at);
DROP INDEX CONCURRENTLY ix_notifications_service_created_at
2018-12-11 14:57:10 +00:00
Pea (Malgorzata Tyczynska)
d7fcd564e0 Merge pull request #2250 from alphagov/switch_providers_update
Update switch providers on slow delivery method and query
2018-12-11 10:27:29 +00:00
Pea Tyczynska
5ed7564066 Remove unused config variables
We don't use FUNCTIONAL_TEST_PROVIDER_SERVICE_ID or
UNCTIONAL_TEST_PROVIDER_SMS_TEMPLATE_ID anymore so we can safely
delete them from config and tests.
2018-12-10 17:25:53 +00:00
Rebecca Law
5b90fd6fb0 Removed unused method 2018-12-10 16:27:59 +00:00
Leo Hemsted
2d9609b1be Merge pull request #2253 from alphagov/folder-warning-msgs
template folder error messages
2018-12-10 15:51:44 +00:00
Leo Hemsted
474acc5bba new chillmaid approved error messages
these get shown on the front-end so make sure their content is good
2018-12-10 12:59:16 +00:00
Pea (Malgorzata Tyczynska)
ad3b0cabf7 Merge pull request #2251 from alphagov/update_serialize_for_csv
Add sender email and change date formatting on Notification's serialize_for_csv
2018-12-10 10:44:28 +00:00
Pea Tyczynska
9a76d6706e Update tests to match the new csv data 2018-12-07 11:24:15 +00:00
Pea Tyczynska
9ab6542678 Change created_at format for Notification serialize_for_csv
Change date formatting on serialize_for_csv so it is more
machine-readable while still remaining human-readable
2018-12-07 11:23:35 +00:00
Pea Tyczynska
a265871a42 Serialize Notification now also returns sender email address
sent_by_email_address field was added because sometimes two
people at one institution have the same name and then email
address, which is unique, is more useful.
2018-12-07 11:21:45 +00:00
Alexey Bezhan
4850d708fd Merge pull request #2248 from alphagov/disable-expensive-sqlalchemy-options
Disable unused SQLAlchemy configuration flags
2018-12-05 16:05:17 +00:00
Pea Tyczynska
6938600ab8 Switch providers on slow delivery only produces logs 2018-12-05 15:56:16 +00:00
Pea Tyczynska
418060fbdb Update switch provider on slow delivery task to change max once evey 10 minutes 2018-12-05 15:56:16 +00:00
Pea Tyczynska
39ca5b9525 New query for finding if provider is slow
The delivery for provider is slow if more than threshold (currently
we pass in threshold 10%) either took x (for now 4) minutes to deliver,
or are still sending after that time. We look at all notifications
for current provider which are delivered or sending, and are not under
test key, for the last 10 minutes.

We are using created_at to establish if notifications are from last
10 minutes because we have an index on it, so the query is faster.

Also write tests for new is_delivery_slow_for_provider query
2018-12-05 15:51:40 +00:00
Katie Smith
7e2353f497 Merge pull request #2247 from alphagov/add-endpoint-to-update-notification-status
Add endpoint to cancel letters
2018-12-05 15:19:04 +00:00
Rebecca Law
76ea46bc70 Added test for platform stats using query rather than mock. 2018-12-04 13:55:56 +00:00
Alexey Bezhan
1d4e4eae94 Disable unused SQLAlchemy configuration flags
We don't seem to use recorded queries or modification tracking anywhere
in the app, and both features potentially increase memory usage.

This removes deprecated SQLALCHEMY_COMMIT_ON_TEARDOWN options. It's
been removed from the docs and the default matches the value we set
anyway.
2018-12-04 12:04:18 +00:00
Rebecca Law
20fbb96bc2 Added key_type to resultset 2018-12-04 12:02:43 +00:00
Katie Smith
90d9135fcf Return cancelled letters for dashboard
Added cancelled letters to the number of failed letters in the statistics
that get used for the dashboard. At some point, we want to stop
including cancelled letters in the stats, but for now this keeps things
consistent with our current letter failure state, permanent-failure.
2018-12-03 17:51:09 +00:00
Katie Smith
1d67b55b16 Add endpoint for cancelling letters 2018-12-03 17:51:08 +00:00
Rebecca Law
c766febe94 Update /platform-stats to return the data from ft_notification_status, that way the request should not time out for a long date range.
Next steps is to update the query for platform admin stats for all services.
2018-12-03 15:46:44 +00:00
Katie Smith
365c462e93 Update get_notification_by_id to take an optional service_id
It can be useful to get a notification by id while checking that the
notification belongs to a given service. This changes the
get_notification_by_id DAO function to optionally also filter by
service_id so that we can check this.
2018-12-03 12:05:23 +00:00
Katie Smith
902e1b403a Update update_notification_status_by_id DAO function
Replaced `.with_for_lockmode()`, which is now deprecated, with
`.with_for_update() - https://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.with_lockmode

The function should update any statuses that are not 'final', so added
`pending-virus-check` to the list of statuses that the function can
update.
2018-12-03 12:05:23 +00:00
Chris Hill-Scott
7ec3dbd667 Merge pull request #2244 from alphagov/add-reference-to-one-off-letters
Add reference to one off letters
2018-12-03 11:41:49 +00:00
Chris Hill-Scott
3cfeadcae8 Refactor if statement to be positive 2018-12-03 11:34:14 +00:00
Chris Hill-Scott
f5ea77ffa0 Add reference to one off letters
Letters should always have a reference, because that’s what DVLA use to
tell us when they’ve sent a letter.

If a letter has a reference of `None` then DVLA say they’ve sent a
letter with a reference of `'None'`. This means we can never reconcile
the letter, which means it stays in `created`, which means it never
gets billed.

We don’t think this has affected any real letters yet, just ones that
we’ve sent as tests.
2018-12-03 11:34:14 +00:00
Alexey Bezhan
0ac0cd7bde Merge pull request #2243 from alphagov/disable-sa-preping
Revert "Enable pessimistic DB connection disconnect handling"
2018-11-30 16:42:42 +00:00
Alexey Bezhan
b17fd21bb8 Revert "Enable pessimistic DB connection disconnect handling"
Once the DB upgrade is complete we no longer want the added
overhead of "pre-ping" connection check.
2018-11-30 16:20:08 +00:00
Alexey Bezhan
32f0236ff2 Merge pull request #2242 from alphagov/enable-sa-preping
Enable pessimistic DB connection disconnect handling
2018-11-30 16:18:31 +00:00
Alexey Bezhan
614a2dae2c Enable pessimistic DB connection disconnect handling
By default, SQLAlchemy will start a transaction with an
existing connection without checking that the connection
is still valid.

Enabling "pre-ping" makes the ORM send a `SELECT 1` when
acquiring a connection, which should help avoid some errors
caused by connections breaking during a DB failover.

The added statement has a constant overhead for all transactions,
so we should only keep it enabled when we're planning to switch
or upgrade the database server.

https://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-pessimistic
2018-11-30 15:41:58 +00:00
Alexey Bezhan
15849b421b Merge pull request #2233 from alphagov/flexible_retention_jobs_deletion
Delete jobs in accordance with flexible retention policies
2018-11-28 14:47:23 +00:00
Alexey Bezhan
452924faaf Update jobs archived flag before setting the default value
Running an update before setting the column default value reduces
the time the table is locked (since most rows don't have a NULL
value anymore), but the migration takes slightly longer to run
overall.
2018-11-28 14:38:59 +00:00
Pea Tyczynska
f941b8b146 Use archived flag to see if job needs deleting from s3 bucket 2018-11-28 14:38:59 +00:00
Pea Tyczynska
fd06924f3a Build a command to archive old jobs 2018-11-28 14:38:59 +00:00
Pea Tyczynska
50811c3b8e Archive job after corresponding file deleted from s3 2018-11-28 14:38:59 +00:00
Pea Tyczynska
641cb6ec36 Add archived column to jobs table with default value of false 2018-11-28 14:38:59 +00:00
Pea Tyczynska
e5fd027192 Move nightly tasks before introduction of archived flag on jobs 2018-11-28 14:38:59 +00:00
Pea Tyczynska
be6f37069b Change job selection dao to take flexible retention into account
Also test deleting jobs with flexible data retention

Also update tests for default data retention following logic
change: dao_get_jobs_older_than_data_retention now counts
today at the start of the day, not at a time when function runs
and updated tests reflect that
2018-11-28 14:37:43 +00:00
Rebecca Law
744389f557 Merge pull request #2239 from alphagov/remove-unused-task
Remove unused task
2018-11-28 13:45:28 +00:00
Alexey Bezhan
e6c581b5b7 Merge pull request #2240 from alphagov/service-rate-limit-info-not-error
Lower service rate limit log level to INFO
2018-11-28 10:50:41 +00:00
Alexey Bezhan
462c8db4c3 Lower service rate limit log level to INFO
Services reaching rate limits are triggering our alerts and make it
hard to find actual exceptions in the logs.

As far as the API is concerned this is not an exceptional state,
so we shouldn't log it as such.
2018-11-27 15:50:51 +00:00
Alexey Bezhan
e7a2f4c151 Update utils to 30.7.1 to silence 'Header missing' warnings
Brings in changes from https://github.com/alphagov/notifications-utils/pull/553
2018-11-27 15:50:33 +00:00