Commit Graph

8995 Commits

Author SHA1 Message Date
Rebecca Law
cd78361be1 Merge pull request #3477 from alphagov/volume-stat-report
Report for total notifications sent per day for each channel.
2022-03-09 13:42:00 +00:00
Rebecca Law
29ebf0eb9a Move the casting the column as an int to the the endpoint, we need to
convert the Decimal data type to datatype json can work with.
2022-03-09 12:29:58 +00:00
Ben Thorner
3fab7a0ca9 Fix letter functional tests to work in Docker
Currently "test_send_letter_notification_via_api" fails at the final
stage in create-fake-letter-response-file [^1]:

        requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=6011): Max retries exceeded with url: /notifications/letter/dvla (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xffff95ffc460>: Failed to establish a new connection: [Errno 111] Connection refused'))

This only applies when running in Docker so the default should still
be "localhost" for the Flask app itself.

[^1]: 5093064533/app/celery/research_mode_tasks.py (L57)
2022-03-09 11:07:50 +00:00
David McDonald
5093064533 Merge pull request #3481 from alphagov/service-callback-timeout
Reduce timeout for service callback attempt to 5 seconds
2022-03-08 14:11:33 +00:00
Ben Thorner
8a8db654c9 Merge pull request #3480 from alphagov/benthorner-patch-1
Fix incorrect code block formatting in README
2022-03-08 14:09:07 +00:00
David McDonald
0d952b4d8c Reduce timeout for service callback attempt to 5 seconds
It is currently 60 seconds but we have had two incidents in the
past week where there is a connection error talking to a service
and the request takes up to 60 seconds before failing. When this
happens, if there are a few of these callbacks then all of them
will completely hog the service callback worker and build up a big
queue of all the other service callbacks.

5 seconds has been chosen as that is still a pretty decent length
time for a simple web request that should just be giving them a
little bit of information for them to store. 5 seconds should be a
sufficient enough reduction that we dramatically reduce this problem
for the moment.

Open to this number
being changed in the future based on how we see it perform.
2022-03-08 13:05:32 +00:00
Ben Thorner
ae41075151 Fix incorrect code block formatting in README 2022-03-08 12:42:14 +00:00
Leo Hemsted
00259893f1 automatically retry letters stuck in pending-virus-scan
Since sept 2019 we've had to log on to production around once every
twenty days to restart the virus scan task for a letter. Most of the
time this is just a case of making sure the file is in the scan bucket,
and then triggering the task. If the file isn't in the scan bucket we'd
need to do some more manual investigation to find out exactly where the
file got stuck, but I can only remember times when it's been in the scan
bucket.

So if the file is in the scan bucket, we can just check that with code
and kick the task off automatically.
2022-03-07 18:31:46 +00:00
Chris Hill-Scott
eb383004fb Merge pull request #3478 from alphagov/custom-base-url-register-email
Allow admin app to specify domain for registration email
2022-03-07 15:17:38 +00:00
Chris Hill-Scott
c2b6a9df80 Allow admin app to specify domain for registration email
This follows the pattern for invite emails where the admin app tells the
API which domain to use when generating the link.

This will starting working once the admin change is merged:
- [ ] TBC

It won’t break anything if it’s merged before the admin change.
2022-03-07 15:03:46 +00:00
Rebecca Law
466b7fa341 Report for total notifications sent per day for each channel.
Daily volumes report: total volumes across the platform aggregated by whole business day (bst_date)
Volumes by service report: total volumes per service aggregated by the date range given.

NB: start and end dates are inclusive
2022-03-07 10:44:49 +00:00
Katie Smith
520d621893 Merge pull request #3476 from alphagov/upgrade-some-dependencies
Upgrade some dependencies
2022-03-03 15:06:27 +00:00
Katie Smith
faec6083fa Update notifications-python-client from 6.0.2 to 6.3.0 2022-03-03 14:17:32 +00:00
Katie Smith
7943010bfb Update lxml from 4.7.1 to 4.8.0 2022-03-03 14:15:16 +00:00
Katie Smith
3a57597266 Update psycopg2-binary from 2.8.6 to 2.9.3 2022-03-03 14:07:11 +00:00
Katie Smith
9e324da311 Update iso8601 from 0.1.14 to 1.0.2
The major version bump is because support for Python 3.6 has been
dropped.
2022-03-03 13:47:47 +00:00
Katie Smith
f74d878a07 Update flask-migrate from 2.7.0 to 3.1.0 2022-03-03 13:47:33 +00:00
Katie Smith
c1a3b4bc24 Update celery from 5.2.0 to 5.2.3
This fixes a security warning.
2022-03-03 13:42:10 +00:00
Katie Smith
a8ed76d4a7 Bump all test dependencies which require no code changes 2022-03-02 17:18:32 +00:00
Katie Smith
514bd48614 Update flake8-bugbear from 20.11.1 to 22.1.11
And ignore a warning, since I did not think that in this case "Using
.strip() with multi-character strings is misleading the reader".
2022-03-02 16:51:09 +00:00
Katie Smith
807db037eb Update flake8 from 3.8.4 to 4.0.1
And adds `noqa` to some non-errors which are being flagged.
2022-03-02 15:52:18 +00:00
Leo Hemsted
e497cbbec6 Merge pull request #3474 from alphagov/fix-returned-letters
split returned letters tasks into a max count of returned letters
2022-03-02 11:49:12 +00:00
Leo Hemsted
b1636b7a1a split returned letters tasks into a max count of returned letters
if we have too many returned letters, we'll exceed SQS's max task size
of 256kb. Cap it to 5000 - this is probably a bit conservative but
follows the initial values we used when implementing this for the
collate-letters-task[^1]. Also follow the pattern of compressing the
sqs payload just to reduce it a little more.

[^1]: https://github.com/alphagov/notifications-api/pull/1536
2022-03-02 10:51:08 +00:00
Katie Smith
ead909d2ce Merge pull request #3472 from alphagov/inbound-no-command
Stop blank strings being inserted as inbound numbers
2022-03-02 08:30:41 +00:00
Ben Thorner
d61133c508 Merge pull request #3468 from alphagov/bump-sms-alert-threshold
Tweak SMS alert to make it worth the effort
2022-03-01 16:10:33 +00:00
Katie Smith
67d1b3719e Stop blank strings being inserted as inbound numbers
We had an inbound number in the database with a value of ''. This
could happen if there are blank lines in the inbound numbers file
we use for the `insert-inbound-numbers` command. To avoid this
happening again, the command now calls `.strip()` on each line of the
file and only inserts a row if the result is truthy (i.e. not '').
2022-03-01 15:31:54 +00:00
Rebecca Law
7a6f53e027 Merge pull request #3473 from alphagov/update-letter-rates
Add new letter rates for March 1, 2022.
2022-03-01 14:49:15 +00:00
Rebecca Law
00ec3ae8f6 Add new letter rates for March 1, 2022.
- second class postage will go up by 2 pence, plus VAT
- international postage will go up by 7 pence, plus VAT
- first class postage will go down by 6 pence, plus VAT
2022-03-01 14:35:39 +00:00
Leo Hemsted
dc8d077e73 Merge pull request #3466 from alphagov/gunicorn-pin
Bump gunicorn
2022-03-01 10:40:39 +00:00
Katie Smith
5ef9198869 Merge pull request #3469 from alphagov/free-allowance-0
Allow SMS fragment limit to be 0
2022-02-28 14:10:44 +00:00
Katie Smith
b56906bc43 Merge pull request #3471 from alphagov/de-flakify-test
Fix test which was flakey due to order of items returned from db
2022-02-28 14:10:27 +00:00
Katie Smith
bff4e3a709 Fix test which was flakey due to order of items returned from db
The test was querying `FactNotificationStatus` and ordering the results
by bst_date and notification_type then checking the rows. However, the
bst_date and notification_type for each row is the same, so this test
could fail based on the order that the results came back in. By ordering
on the notification_status instead, we can be sure of the order of the
results.
2022-02-28 13:03:55 +00:00
Katie Smith
c9dafa0372 Remove unused test code
Notifications don't have a `scheduled_for` attribute, and the test
function deleted isn't used anywhere.
2022-02-28 12:45:25 +00:00
Katie Smith
d572c7228d Allow the free SMS fragment limit to be 0
This updates the schema so that the free allowance has a minimum value
of 0 instead of 1.
2022-02-28 12:45:25 +00:00
Katie Smith
cac6775829 Merge pull request #3470 from alphagov/letters-still-sending-time
Make letters still sending check later
2022-02-28 12:08:50 +00:00
Katie Smith
d53ef27b7f Make letters still sending check later
This changes the scheduled task to raise an alert if letters are still
sending from 1530 to 1700. DVLA have reported that our "monitoring is
executing just before we actually mark them as ‘despatched’ and send
you the feedback files." and asked us to make the check a little later.

We don't actually contact DVLA until the morning after the alert anyway,
so this won't affect the process of getting in touch with them.

This change will require Cronitor to be updated for the new time.
2022-02-28 11:50:55 +00:00
Ben Thorner
a789f80dc2 Merge pull request #3467 from alphagov/optimise-docker-dev
Iterate local development with Docker
2022-02-28 11:44:30 +00:00
Ben Thorner
bd690ab718 Be more helpful for how to install / start Redis
In response to [1].

[1]: https://github.com/alphagov/notifications-api/pull/3467#discussion_r815797015
2022-02-28 11:27:34 +00:00
Ben Thorner
038d47e702 Minor tweaks in response to PR comments 2022-02-25 17:51:53 +00:00
Ben Thorner
d406829b6c Tweak SMS alert to make it worth the effort
Currently we alert if a service wastes £16 of SMS. It may cost us
around that amount just to deal with the alert, especially if the
service refuses to clean up their data.

This bumps the threshold to something more alarming, which should
make it more reasonable to suspend the service if we can show that
they've already wasted public money. £160 seems like a reasonable
compromise between have wasted vs could waste.

Note: we previously compromised on 1000 [1] down from 63K [2]. I
think we can afford to go a little bit higher.

[1]: https://github.com/alphagov/notifications-api/pull/3234
[2]: https://github.com/alphagov/notifications-api/pull/3221
2022-02-25 10:37:56 +00:00
Ben Thorner
c9a9640a4b Iterate local development with Docker
This makes a few changes to:

- Make local development consistent with our other apps. It's now
faster to start Celery locally since we don't try to build the
image each time - this is usually quick, but unnecessary.

- Add support for connecting to a local Redis instance. Note that
the previous suggestion of "REDIS = True" was incorrect as this
would be turned into the literal string "True".

I've also co-located and extended the recipes in the Makefile to
make them a bit more visible.
2022-02-24 17:15:41 +00:00
Leo Hemsted
d34c58925e bump cffi
v1.15 adds arm64 support for macbooks with an m1 chip
2022-02-23 16:43:21 +00:00
Leo Hemsted
ba2479b6e4 pin gunicorn to git commit; bump eventlet
gunicorn doesn't pin eventlet, but functionally, gunicorn==20.1.0
depends on eventlet<=0.30.2 due to a change in eventlet. Gunicorn have
fixed this compat issue, however, haven't released it. By pinning to a
git commit, we're able to bump eventlet up to 0.33, thus solving a
security advisory. (Note that the security advisory didn't actually
impact us as it only affects websockets, however, it was noisy and
distracting).

Note - pip may have cached the old version of gunicorn. You may need to
run `pip install -r requirements.txt --no-cache-dir` to get the updated
version of gunicorn locally.
2022-02-23 16:43:21 +00:00
Chris Hill-Scott
114128f123 Merge pull request #3463 from alphagov/clear-redis-on-cancelling-broadcast
Clear cache when cancelling broadcast via the API
2022-02-23 16:04:19 +00:00
Chris Hill-Scott
9c2f0ce9db Clear cache when cancelling broadcast via the API
Before we implemented ‘cancel’ any updates to a broadcast went through
the admin app. This meant the admin app could deal with clearing the
cache any time a broadcast was updated by a user performing an action.

Now that a broadcast can be updated without the admin app being involved
we have another place we need to clear the cache from.

If we don’t do this then the broadcast can look like it’s still going
even though it’s successfully been cancelled.
2022-02-22 16:26:05 +00:00
Chris Hill-Scott
4b4122a773 Merge pull request #3461 from alphagov/be-more-robust-around-references-to-cancel
Be more robust in handling ambiguous references to cancel an alert
2022-02-21 10:39:48 +00:00
Katie Smith
a165f62b60 Merge pull request #3462 from alphagov/nhs-brand-migration
Migration to make NHS email branding ID consistent across environments
2022-02-18 13:47:24 +00:00
Katie Smith
008cea6222 Migration to make NHS email branding ID consistent
With the changes we will be making to email branding in admin it's
useful to know the ID of the NHS email brand. This makes it easier to
show a preview of the branding.

This means that the ID will need to be consistent across environments,
so this changes the details of the NHS brand in the dev, preview and
staging environments to match the production data.

The migration
- Removes NHS branding from existing services
- Removes NHS branding from any orgs which had it as their default
- Deletes the NHS branding row if it exists
- Inserts a new NHS branding row with details which match those in
  production

This does have the effect of removing NHS branding from people's local
and preview services and orgs  (NHS branding doesn't exist on staging),
but this does not affect real teams. The NHS logo with a filename of
'1ac6f483-3105-4c9e-9017-dd7fb2752c44-nhs-blue_x2.png' exists in the
logo S3 bucket for all environments.
2022-02-18 12:00:01 +00:00
Chris Hill-Scott
cc207ac11f Raise error if multiple broadcasts found for reference
Because the `<reference>` field of a `cancel` message can contain an
arbitrary number of items it’s possible for it to reference more than
one current alert.

In this case it is ambiguous which alert should be cancelled, so we
should raise a custom error.

This will help people know that they have to manually go into Notify and
figure out which alert(s) to cancel there.
2022-02-17 15:23:13 +00:00
Chris Hill-Scott
f691bc2a92 Only lookup broadcasts which can be cancelled
It is possible that, among the references Environment Agency give us for
which broadcast to cancel, there could be references for older, already
expired broadcasts.

This would be the case if someone cancelled a broadcast in Notify, then
issued and try to re-cancel another broadcast to the same area. The
Flood Warning Service has no way of knowing that the first broadcast has
been cancelled in Notify already, so it would add the reference to the
list of things to be cancelled.

We can avoid this from happening by filtering-out already-cancelled and
expired broadcasts before looking up which one should be cancelled.
2022-02-17 15:23:13 +00:00