Commit Graph

5586 Commits

Author SHA1 Message Date
Katie Smith
82f07de200 Merge pull request #2116 from alphagov/update-first-class-rates-dates
Update first class letter rate start dates
2018-09-28 13:45:45 +01:00
Leo Hemsted
6aa4bfa426 Merge pull request #2118 from alphagov/fix-awscli
fix awscli botocore dependency
2018-09-28 11:37:29 +01:00
Leo Hemsted
78b4231915 fix awscli botocore dependency
awscli has a requirement of a new version of botocore

moto has a requirement of an old version of boto3, which requires an
old version of botocore

We had to pin boto to an older version, because of the moto issues.
this commit pins awscli to the version currently deployed on prod, so
that it plays nice with that older version of boto/botocore
2018-09-28 11:25:55 +01:00
Rebecca Law
eeb705b68b Merge pull request #2114 from alphagov/dont-update-page-count
Do not update billable_units if page count does not match postal provider
2018-09-28 10:59:07 +01:00
Katie Smith
45e714e694 Update first class letter rate start dates
We want to bring the start dates for first class letter rates forward by
a month so that we don't see billing errors when sending first class letters now.
(The feature will still go live at the planned time - this is to let us test things
beforehand.)
2018-09-28 10:25:44 +01:00
Tom Byers
b0549f9623 Merge pull request #2110 from alphagov/bump-utils
Bump utils to 30.4.0
2018-09-28 10:22:12 +01:00
Tom Byers
78cc503a91 Bump utils to 30.4.0
Brings in changes to allow letter timings to
include 1st class letters.

https://github.com/alphagov/notifications-utils/pull/533
2018-09-28 10:02:16 +01:00
Rebecca Law
a4f357499d Sometimes the page counts from DVLA do not match our page counts. Our counts have always been right. This PR does not update notification with the DVLA page count but does still let us know the difference happened. 2018-09-27 16:13:15 +01:00
Leo Hemsted
f0f54c0dff Merge pull request #2113 from alphagov/fix-noti-migration
separate notification postage constraint into three separate commits
2018-09-27 15:48:44 +01:00
Leo Hemsted
2b354eb5df separate notification postage constraint into three separate commits
we had an issue where the notification postage constraint command ran
into a deadlock, after trying to acquire two exclusive access locks on
large frequently modified/read tables.

To avoid this happening, we've had to split the upgrade script into
three - one script to apply the not-valid constraint to notifications
table, one for notification_history, and a third to validate the two
constraints.

Note: The first two scripts acquire exclusive access locks, but the
third only needs a row by row lock.

since this involves changing the exsiting alembic upgrades, if you've
upgraded your db you'll need to run the following three commands to
revert your database to a previous good state.

```
alter table notifications drop constraint chk_notifications_postage_null;
alter table notification_history drop constraint chk_notification_history_postage_null;
update alembic_version set version_num = '0229_new_letter_rates';
```
2018-09-27 15:20:28 +01:00
Tom Byers
c126859efc Lock botocore library to <1.11.0
Using version 1.11.0 or above causes an error with
the moto library where it makes real HTTP requests
instead of mocking them:

https://github.com/spulec/moto/issues/1793

Until this is resolved, botocore needs to be
locked. This copies the approach the Digital
Marketplace team took to the same problem:

https://github.com/alphagov/digitalmarketplace-utils/pull/452
2018-09-27 14:38:29 +01:00
Leo Hemsted
f73d9ef852 Merge pull request #2108 from alphagov/postage-constraint
Postage constraint
2018-09-27 13:45:49 +01:00
Tom Byers
8b86257a8b Bump utils to 30.3.1
Brings in stripping of the line separator
character from emails.

https://github.com/alphagov/notifications-utils/pull/531
2018-09-26 10:23:14 +01:00
Leo Hemsted
69e08fa23b fix tests to create notifications properly
migrated away from calling fixtures as functions
2018-09-25 16:10:26 +01:00
Leo Hemsted
3739c573ea fix null check in constraint
There are two fun quirks of postgres/sql that we need to work around:
* any `x = y` where x or y is NULL returns NULL, rather than false.
* check constraints accept NULL or true values as good.

so, the check `postage in ('first', 'second')` returns `null` rather
than `false` when postage is null itself. This surprisingly passes the
check constraint. To get around this, we have to add an explicit not
null check as well.
2018-09-25 16:10:26 +01:00
Leo Hemsted
17612e5446 add postage constraint to notification history
A not valid constraint only checks against new rows, not existing rows.
We can call VALIDATE CONSTRAINT against this new constraint to check
the old rows (which we know are good, having run the command from
74961781). Adding a normal constraint acquires an ACCESS EXCLUSIVE
lock, but validate constraint only needs a SHARE UPDATE EXCLUSIVE lock.

see 9d4b8961 and 0a50993f for more information on marking constraints
as not valid.
2018-09-25 16:10:16 +01:00
Pea (Malgorzata Tyczynska)
d2962cdc10 Merge pull request #2096 from alphagov/new_letter_rates_from_10_2018
Introduce new letter rates, valid from 01.10.2018
2018-09-25 15:17:50 +01:00
Pea Tyczynska
ea3144c3fd Add downgrade steps to new rates migration, add end_date to old rates
and refactor migration statements for security good practice
2018-09-25 15:10:16 +01:00
Pea Tyczynska
165b65612e Change how rates are filtered by date to equal or greater 2018-09-25 15:10:16 +01:00
Pea Tyczynska
08fec8f928 Fix tests - update number fo letter rates in test 2018-09-25 15:10:16 +01:00
Pea Tyczynska
eed1d83187 Test that get_rate gets right rate based on post_class and date 2018-09-25 15:10:16 +01:00
Pea Tyczynska
86533c2366 Do not update the rate that doesn't change 2018-09-25 15:10:16 +01:00
Pea Tyczynska
0c0166922c Update migration number and get rid of explicit UTC zoning therein 2018-09-25 15:10:16 +01:00
Pea Tyczynska
85e57025b2 Define MMG inbound credentials for local in Development environment 2018-09-25 15:10:16 +01:00
Pea Tyczynska
39ebfb6826 Test filtering letter_rates by post_class 2018-09-25 15:10:16 +01:00
Pea Tyczynska
b3191dbc2a Filter letter rates by post_class in get_rate
Also adjust existing tests.
2018-09-25 15:10:15 +01:00
Pea Tyczynska
8b410e8876 Add new letter rates from 1st of October 2018 2018-09-25 15:10:15 +01:00
Rebecca Law
cb1a9a59c2 Merge pull request #2107 from alphagov/set-postage-on-file-name
Set postage on PDF filename from notification
2018-09-25 13:31:57 +01:00
Rebecca Law
a54645c5a3 Set the postage in the filename based on the postage set on the notification. 2018-09-25 11:04:58 +01:00
Leo Hemsted
ecbba69f53 Merge pull request #2103 from alphagov/populate-notification-postage
populate historic notification postage data
2018-09-24 11:13:07 +01:00
Sakis
a5ae9a21cd Merge pull request #2097 from alphagov/remove-http-healthcheck
Remove http healthcheck for api instances
2018-09-21 10:47:40 +01:00
Leo Hemsted
7496178156 populate historic notification postage data
sets all letters in notification history (and notifications) to
"second", so that there's no null letters for billing etc. Commits in
ten day chunks (up to ~30k letters)
2018-09-20 17:41:04 +01:00
Rebecca Law
1b7e0a8ec4 Merge pull request #2102 from alphagov/reduce-updates-to-notification
Reduce updates to notification
2018-09-20 16:01:43 +01:00
Rebecca Law
bb97a9038f Merge branch 'master' into reduce-updates-to-notification 2018-09-20 14:48:40 +01:00
Rebecca Law
b00308d122 Removed an update statement to notifications.
It's a small change, but we should remove any db operations that are not necessary.
2018-09-20 14:47:24 +01:00
Leo Hemsted
7c48dd2c4e Merge pull request #2100 from alphagov/notification-postage
Notification postage
2018-09-20 13:25:34 +01:00
Leo Hemsted
8e19a0742f remove default postage from noti history
also add test for notification_history properly setting
2018-09-20 12:26:58 +01:00
Leo Hemsted
4dc3f829e3 give letter notifications the postage from their service 2018-09-19 17:23:17 +01:00
Leo Hemsted
9021b43eb6 use pytest.param to contain marks like xfail or skip 2018-09-19 16:33:00 +01:00
Leo Hemsted
918e4b390f add postage to notification + noti_history
if it's a letter notification, postage must equal "first" or "second",
else it must equal null
2018-09-19 16:32:58 +01:00
Rebecca Law
645da3f33d Merge pull request #2098 from alphagov/postage-constraints
Add constraints to services.postage
2018-09-19 11:08:02 +01:00
Rebecca Law
01ef8dd379 Merge pull request #2099 from alphagov/add-valid-message
Added an info log message when the precompiled pdf is successful.
2018-09-19 11:05:12 +01:00
Rebecca Law
a30ed976f4 Added an info log message when the precompiled pdf is successful. This is because we can't tell when the letters are passing. 2018-09-18 17:46:19 +01:00
Rebecca Law
5f73dfdbe9 Added constraints to services.postage: not nullable and can only containt "first" or "second" 2018-09-18 17:41:25 +01:00
Rebecca Law
29a666302e Merge pull request #2092 from alphagov/letter-class-default-for-services
Add letter_class to Service
2018-09-18 17:03:55 +01:00
Rebecca Law
7200ccb452 Remove print 2018-09-18 16:44:07 +01:00
Rebecca Law
1c0892888f Change the name of letter_class to postage, this will match the domain language used in the documentation.
Updated the tests to answer review comments.
2018-09-18 15:22:08 +01:00
Athanasios Voutsadakis
2e12c68d2e Remove http healthcheck for api instances
This was introduced in #1811 as a way to avoid sending traffic to newly
created apps where gunicorn had not started yet, such as the case during
a scaling event. These days we depend mostly on scheduled scaling and we
rarely need to scale above the scheduled values.

Yesterday we had an event where (during a traffic spike) the healthcheck
failed causing the instance to be killed and sending a 5XX response code
to all the connections that this instance was handling at the time.

However, this instance was not unhealthy and was serving traffic. The
problem stems from a combination of using async workers, having to limit
the number of database connections and a thread holding onto a db
connection for the entire duration of the request.

Specifically, we end up having requests queued up in gunicorn waiting
for other requests to finish and release the db connection. Some pages
such as the dashboard generate queries that can take >5s.

If a healthcheck request is sent during a traffic spike and the instance in
question was "unfortunate" enough to get handled a few of these long
running queries, the healthcheck request will be queued up behind these
slow requests and will fail to receive a response within 1s [docs].

Ideally we should be able to configure the healthcheck timeout to a
value of our choosing, since we can end up in this situation again in
the future.

docs: https://docs.cloudfoundry.org/devguide/deploy-apps/healthchecks.html#types
2018-09-18 10:34:00 +01:00
Rebecca Law
efb618e956 Fix merge conflicts for the db migration file.
Update test_services_dao to stop using fixtures. This is a massive change. The only real change in the file is to check for the letter_class.
2018-09-17 15:45:29 +01:00
Rebecca Law
79815b4f8a In order to support sending letters by first class we need a way to know how the service wants us to send the letter.
To start with this will be an attribute on the service, at the time the notification is created it will look at Service.letter_class to decide what class to use for the letter.

This PR adds Service.letter class as a nullable column.
Updated the create_service and update_service method to default the value to second.

Subsequent PRs will add the check constraint to ensure we only get first or second in the letter_class column and make that column nullable.
This can't be done all at once because it will cause an error if someone inserts or updates a service during the deploy.
2018-09-17 11:27:43 +01:00