Commit Graph

8709 Commits

Author SHA1 Message Date
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
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
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
Ben Thorner
8fac5c72db Merge pull request #3454 from alphagov/upsert-status-180693991
Rewrite status aggregation to be a bulk upsert
2022-02-17 13:21:50 +00:00
Chris Hill-Scott
8ca0b88177 Merge pull request #3458 from alphagov/more-cap-acceptance
More tweaks of broadcast message validation
2022-02-16 15:58:18 +00:00
Chris Hill-Scott
d73131bbec Allow cancel of alert via API with no description
The XML for an alerts requires a `<description>` field. The XML for
a `<cancel>` may have a `<description>` field populated (although we
ignore the contents) but it may also be empty.

This commit updates the schema to leave the all the validation to the
view layer, which can decide when or when not to validate the content of
the `<description>` field.
2022-02-16 15:31:50 +00:00
Chris Hill-Scott
288f5d11cd Test that alert with no references is OK
References are optional, and we fixed errors when they are not provided
in bbc444699a

This commit amends the tests so that they cover the `Alert` message type
as well as the `Cancel` (which is already covered).
2022-02-16 15:31:47 +00:00
Ben Thorner
574b1d3c63 Fix not deleting dead rows in status table
To address: https://github.com/alphagov/notifications-api/pull/3454#pullrequestreview-880302729

Since we now delete all rows before inserting fresh ones, we no
longer need to worry about conflicts. I've also extended the old
test to check all three kinds of overwrite: new, changed, gone.
2022-02-16 13:40:08 +00:00
Ben Thorner
a69d1635a1 Update FactStatus table in bulk for each service
Previously we were looping over data from the Notifications/History
table and then shovelling it into the status table, one row at a time
- plus an extra delete to clean up any existing data.

This replaces that with a batch insertion, similar to how we archive
notifications [1], but using a simple subquery (via "from_select" [2])
instead of a temporary table.

To make the select compatible with the insert, I've used "literal"
to inject the constant pieces of data, so each row has everything it
needs to go into the status table.

[1]: 9ce6d2fe92/app/dao/notifications_dao.py (L295)
[2]: https://docs.sqlalchemy.org/en/14/core/dml.html#sqlalchemy.sql.expression.Insert.from_select
2022-02-16 13:40:05 +00:00
Ben Thorner
efde271c5a Rewrite FactStatus updates to be an upsert
This is consistent with the way we do billing updates [1] and is a
bit less clunky. Functionally it should be the same - note that the
tests already cover the "overwriting" behaviour if a row exists.

[1]: 9ce6d2fe92/app/dao/fact_billing_dao.py (L522)
2022-02-16 13:39:08 +00:00
Ben Thorner
7bc037f1ce Merge pull request #3459 from alphagov/fix-status-task-logs-180693991
Fix task name and action in status task logs
2022-02-16 13:38:38 +00:00
Ben Thorner
5206844a95 Merge pull request #3438 from alphagov/lower-query-timeout-180693991
Revert increased timeout for reporting worker
2022-02-16 13:38:29 +00:00
Ben Thorner
ef231d5de7 Fix task name and action in status task logs 2022-02-16 11:45:45 +00:00
Ben Thorner
8aeee7ce40 Merge pull request #3457 from alphagov/bump-beat-memory
Bump memory for Celery Beat to 512M
2022-02-14 14:22:47 +00:00
Ben Thorner
2d6ee2eb72 Bump memory for Celery Beat to 512M
This fixes the app crashing - apparently due to a lack of free
memory. Looking over the last month, we can see it's been hovering
at ~90% utilisation. 512M seems like a good compromise to avoid
this happening again vs paying for what we use.

The limit was last changed 5 years ago:

https://github.com/alphagov/notifications-api/pull/882
2022-02-14 14:13:21 +00:00
Chris Hill-Scott
d21c09f0fa Merge pull request #3456 from alphagov/error-if-cap-missing-references
Return 400 if references missing from cancel broadcast
2022-02-14 13:15:46 +00:00
Chris Hill-Scott
bbc444699a Return 400 if references missing from cancel broadcast
If someone tries to cancel a broadcast but the references don’t match
and existing broadcast we correctly return a 404.

If they don’t provide any references then we get an exception. This
commit catches the missing references and returns a 400. I think this
is more appropriate because it’s malformed request, rather than a
well-formed request that doesn’t match our data. It also lets us write a
more specific and helpful error message.
2022-02-14 12:34:09 +00:00
Ben Thorner
5a87d8c7d7 Merge pull request #3437 from alphagov/retry-parallel-status-180693991
Attempt 2 of parallelising status aggregation more
2022-02-14 10:50:26 +00:00
Pea Tyczynska
e5b1a65f1e Merge pull request #3448 from alphagov/drop_api_key_id_column_from_broadcast_message_table
Drop api_key_id column from broadcast_message table
2022-02-11 14:01:25 +00:00
Pea Tyczynska
66dba8a7c6 Merge pull request #3452 from alphagov/revert-3449-revert-3440-audit-api-key-id-when-cancelling-broadcast-via-api
Audit api key id when cancelling broadcast via api - second try
2022-02-11 12:13:33 +00:00
Pea Tyczynska
c55d917b28 Drop api_key_id column from broadcast_message table
This column has been superseded by a new column named
created_by_api_key_id.

Also create constraint checking that we know who created broadcast

Also move data so that constraint is met before instatiating it.
2022-02-11 12:12:00 +00:00
Pea Tyczynska
3dc1907321 Audit api key id when cancelling broadcast via api 2022-02-11 12:01:56 +00:00
Pea Tyczynska
87ab81912c Merge pull request #3453 from alphagov/audit-cancel-alert-via-api-just-first-migration
Migration adding cancelled_by_api_key_id to broadcast_message
2022-02-11 10:34:12 +00:00
Ben Thorner
966c4db8c6 Fix getting service IDs for status aggregation
Addresses [1].

Previously the query would always use UTC midnight, even after we
had switched to BST (+1h). We store timestamps as naive UTC in our
DB - without a timezone - but we want the query to work in terms
of GMT / BST so we adjust for that - BST midnight is 11PM in UTC.

[1]: https://github.com/alphagov/notifications-api/pull/3437#discussion_r791998690
2022-02-10 10:51:45 +00:00
Ben Thorner
6e8f121548 Standardise how we query midnight-to-midnight
Partially addresses [1] (lots more detail to read in the comment).
I've also added some tests for the status DAO function to confirm
it behaves as expected across timezones.

[1]: https://github.com/alphagov/notifications-api/pull/3437#discussion_r802634913
2022-02-10 10:51:27 +00:00
Ben Thorner
7f4b140f97 Rename function to make it consistent
This is consistent with the new "on_date" function. It was going
off the edge of my screen before in some parts of the code.
2022-02-09 17:39:08 +00:00
Ben Thorner
1213463b8e Only aggregate status when necessary for a service
This takes a similar approach to the nightly deletion task so that
we only create sub-tasks when there are actually notifications to
aggregate for a given type and day [1].

We're making this change to stop the duplication errors we're getting
at the moment and ensure the task can scale to more messages and more
services. There are two parts to this:

- Each subtask should now run within the 5 minute visibility timeout.
However, they may still be duplicated if the parent task overruns [2].

- The parent task creates a mininal number of subtasks, and the query
to determine this is very fast for a normal process day (milliseconds).

Since all tasks will run quickly, there should be no more duplication.

In order to test this more nuanced task, I rewrote the tests:

- One test checks the subtask is called correctly.
- One test checks we create all the right subtasks.

[1]: https://github.com/alphagov/notifications-api/pull/3381
[2]: https://docs.google.com/document/d/1MaP6Nyy3nJKkuh_4lP1wuDm19X8LZITOLRd9n3Ax-xg/edit#heading=h.q3intzwqhfzl
2022-02-09 17:39:07 +00:00
Ben Thorner
c8db58d0e8 Reorder loops for creation status agg sub tasks
This will help tailor the innermost loop on services.
2022-02-09 17:39:06 +00:00
Ben Thorner
d6678b6a70 Remove unnecessary logs from status aggreagtion
These can be inferred elsewhere:

- Task creation is obvious from task execution. If we're concerned
about a specific service, we can check the updated times on the DB
records, since all records are recreated each time this runs.

- Task starting is already logged.

- Task completion is already logged. The number of rows updated can
also be inferred from the DB.

The log I've found useful is the one about fetching the data, and
I've also added another to time how long it takes to insert the data,
as both could be sources of poor performance.

Arguably we should use metrics for this sort of thing, but logs are
easier in practice for the metric systems we have.
2022-02-09 17:39:05 +00:00
Ben Thorner
018a253b6f Revert "Revert running status aggregation in parallel"
This reverts commit 0f6dea0deb.
2022-02-09 17:39:00 +00:00
Pea Tyczynska
00b63ca5c7 Migration adding cancelled_by_api_key_id to broadcast_message
table. Also add created_by_api_key_id column that will supersede
api_key_id_column.

We do migration and code in separate PRs to make it easier to
downgrade if anything goes wrong.
2022-02-09 17:26:37 +00:00
Pea Tyczynska
9ce6d2fe92 Merge pull request #3449 from alphagov/revert-3440-audit-api-key-id-when-cancelling-broadcast-via-api
Revert "Audit api key id when cancelling broadcast via api"
2022-02-09 11:12:28 +00:00
Pea Tyczynska
a780933893 Revert "Audit api key id when cancelling broadcast via api" 2022-02-09 11:01:39 +00:00
Pea Tyczynska
d05bff9efc Merge pull request #3440 from alphagov/audit-api-key-id-when-cancelling-broadcast-via-api
Audit api key id when cancelling broadcast via api
2022-02-09 10:15:03 +00:00
Pea Tyczynska
f2bef7392e api_key_id column will have to be dropped in a separate PR
This is to avoid situation where we deploy migration already
but don't deploy code yet and they are not compatible for a while
which leads to errors.
2022-02-08 15:57:35 +00:00
Chris Hill-Scott
0614a70764 Merge pull request #3445 from alphagov/bump-utils-53.0.0
Bump utils to 53.0.0
2022-02-08 09:56:18 +00:00
Chris Hill-Scott
7f72d3a60f Bump utils to 53.0.0
Changes:

53.0.0
---

* `notifications_utils.columns.Columns` has moved to
  `notifications_utils.insensitive_dict.InsensitiveDict`
* `notifications_utils.columns.Rows` has moved to
  `notifications_utils.recipients.Rows`
* `notifications_utils.columns.Cell` has moved to
  `notifications_utils.recipients.Cell`

52.0.0
---

* Deprecate the following unused `redis_client` functions:
  - `redis_client.increment_hash_value`
  - `redis_client.decrement_hash_value`
  - `redis_client.get_all_from_hash`
  - `redis_client.set_hash_and_expire`
  - `redis_client.expire`

51.3.1
---

* Bump govuk-bank-holidays to cache holidays for next year.
2022-02-08 09:45:10 +00:00
David McDonald
79766aeabd Merge pull request #3447 from alphagov/remove-unused-functions
Remove unused functions
2022-02-07 16:20:43 +00:00
David McDonald
1d8fafcdf4 Remove unused functions
Can't see these being used anywhere so lets get rid of them
2022-02-07 15:58:04 +00:00