Commit Graph

5586 Commits

Author SHA1 Message Date
Rebecca Law
a0c6f6a22e Merge pull request #1828 from alphagov/refactor-post-letters
refactor post letters
2018-04-09 16:13:54 +01:00
Leo Hemsted
46021f4604 Merge pull request #1826 from alphagov/pyup-update-pytest-mock-1.7.1-to-1.8.0
Update pytest-mock to 1.8.0
2018-04-09 15:17:23 +01:00
Leo Hemsted
aa7a33c859 Merge pull request #1815 from alphagov/pyup-update-sqlalchemy-1.2.5-to-1.2.6
Update sqlalchemy to 1.2.6
2018-04-09 15:17:14 +01:00
Leo Hemsted
41e3a150d8 Merge pull request #1824 from alphagov/redis-populate-command-fix
make sure redis command filters dates properly
2018-04-09 15:17:07 +01:00
Rebecca Law
b73bf4220f Refactor process_letter_notification to make the code easier to read.
- Separated the logic of precompiled and template letters.
- Remove the check for research mode, research mode is not relevant to api calls. The test key is used for testing.
Refactor upload_pdf_letter to accept a precompile boolean to save a query to template.
2018-04-09 13:56:44 +01:00
Leo Hemsted
ac0b2d79a2 sys.exit rather than throwing an assertion error
Assertions should only be used in tests - they can be disabled at
runtime by setting the python flag -O (though I don't believe we use
that flag under normal circumstances).

also clean up test asserts - mock_redis is the redis object, so its
`called` property will always be false, because we never say
`redis_store()`. Rather, we should use the `mock_calls` property to
see all calls to all of its children
2018-04-09 11:45:43 +01:00
pyup-bot
a6b3c3e018 Update pytest-mock from 1.7.1 to 1.8.0 2018-04-07 05:13:11 +01:00
Rebecca Law
e7bd6380ab Merge pull request #1825 from alphagov/revert-1820-ken-fix-precompiled-research-mode
Revert "Fix research mode preview of precompiled letters"
2018-04-06 16:14:46 +01:00
Rebecca Law
3c92f00fdb Revert "Fix research mode preview of precompiled letters" 2018-04-06 16:10:06 +01:00
Rebecca Law
002b96b4f8 Merge pull request #1820 from alphagov/ken-fix-precompiled-research-mode
Fix research mode preview of precompiled letters
2018-04-06 15:22:09 +01:00
Rebecca Law
39e4f63b8c Use the positive condition when checking the environment 2018-04-06 12:01:16 +01:00
Chris Waszczuk
15d92e235f Merge pull request #1822 from alphagov/added-new-paginated-inbound-endpoint
Added new paginated inbound endpoint
2018-04-06 11:11:48 +01:00
Leo Hemsted
ba612b0f5b make sure redis command filters dates properly
also write the tests that i should have written a while ago for this
2018-04-05 15:11:29 +01:00
chrisw
0f2ddd8cfa added new paginated inbound endpoint 2018-04-04 17:10:41 +01:00
Leo Hemsted
730eff7e97 Merge pull request #1818 from alphagov/redis-templates
add new redis template usage per day key
2018-04-04 16:25:39 +01:00
Rebecca Law
5b92b0e4ee Merge pull request #1821 from alphagov/fix-delete-notification-time
Fix BST date bug
2018-04-04 14:17:29 +01:00
Rebecca Law
dc325a3ab4 Merge pull request #1819 from alphagov/reduce-exception-when-id-not-found
Fix error message for invalid UUID
2018-04-04 13:07:42 +01:00
Rebecca Law
e47b9364d9 Now that we are in British Summer Time the delete notification scheduled tasks were running at 23:40, but the code expects that the task runs the following day.
Which resulted in the notifications being around for 8 days.
This PR fixes that.
2018-04-04 12:20:36 +01:00
Athanasios Voutsadakis
5068d4cf38 Merge branch 'master' into add-http-healthchecks 2018-04-04 10:22:56 +01:00
Ken Tsang
8b35c1c007 Fix research mode preview of precompiled letters 2018-04-03 22:52:45 +01:00
Rebecca Law
ecc4cde4de Update the get_notification_by_id to return a sensible message if the id is not a valid UUID.
Previously "Result not found" would be returned when the id is not a valid uuid, which does not make sense.
Now the message says "notification_id is not a valid UUID", this should be a clearer message for the client service.
2018-04-03 16:37:41 +01:00
Sakis
dce24147a6 Merge pull request #1814 from alphagov/bump-db-connections
Increase pool size to 15 permanent connections
2018-04-03 16:17:21 +01:00
Leo Hemsted
6e554188bd add command to backfill template usage
The command takes a service id and a day, grabs the historical data for
that day (potentially out of notification_history), and pops it in
redis (for eight days, same as if it were written to manually).

also, prefix template usage key with "service" to make clear that it's
a service id, and not an individual template id.
2018-04-03 16:14:47 +01:00
Leo Hemsted
8e73961f65 add new redis template usage per day key
We've run into issues with redis expiring keys while we try and write
to them - short lived redis TTLs aren't really sustainable for keys
where we mutate the state. Template usage is a hash contained in redis
where we increment a count keyed by template_id each time a message is
sent for that template. But if the key expires, hincrby (redis command
for incrementing a value in a hash) will re-create an empty hash.

This is no good, as we need the hash to be populated with the last
seven days worth of data, which we then increment further. We can't
tell whether the hincrby created the key, so a different approach
entirely was needed:

* New redis key: <service_id>-template-usage-<YYYY-MM-DD>. Note: This
  YYYY-MM-DD is BTC time so it lines up nicely with ft_billing table
* Incremented to from process_notification - if it doesn't exist yet,
  it'll be created then.
* Expiry set to 8 days every time it's incremented to.

Then, at read time, we'll just read the last eight days of keys from
Redis, and sum them up. This works because we're only ever incrementing
from that one place - never setting wholesale, never recreating the
data from scratch. So we know that if the data is in redis, then it is
good and accurate data.

One thing we *don't* know and *cannot* reason about is what no key in
redis means. It could be either of:

* This is the first message that the service has sent today.
* The key was deleted from redis for some reason.

Since we set the TTL to so long, we'll never be writing to a key that
previously expired. But if there is a redis (or operator) error and the
key is deleted, then we'll have bad data - after any data loss we'll
have to rebuild the data.
2018-04-03 16:12:54 +01:00
Leo Hemsted
e692e06b7f add new template stat read pseudocode
we can't use this new code until the new redis keys have been popualted
for the last seven days
2018-04-03 16:12:25 +01:00
kentsanggds
a0f74b35e1 Merge pull request #1813 from alphagov/ken-hide-notify-tag-on-first-page
Hide notify tag on first page
2018-04-03 15:40:54 +01:00
Richard Chapman
82274123f4 Merge pull request #1817 from alphagov/rc_add_virus_scan_error_task
Logging refactor to make debugging Antivirus scans easier
2018-04-03 14:17:15 +01:00
Chris Hill-Scott
c392053847 Merge pull request #1816 from alphagov/bump-utils-asterisks
Bump utils to 25.2.3
2018-04-03 13:07:51 +01:00
Richard Chapman
f1abce22ae Logging refactor to make debugging easier. Before the filename needed to
be known. Added the notification id to the logging message so that
the notification can be traced through the logging system by knowing
the notification id, making it easier to debug. Also changed to raise an
exception so that alerts are generated. This way we should get an email
to say that there has been an error.
2018-04-03 12:31:52 +01:00
Chris Hill-Scott
c9b297a3d4 Bump utils to 25.2.3
To bring in:
- [x] https://github.com/alphagov/notifications-utils/pull/436

Changes:
- https://github.com/alphagov/notifications-utils/compare/25.2.2...25.2.3
2018-04-03 12:10:45 +01:00
Sakis
f06bd20900 Merge pull request #1809 from alphagov/revisit-proxy-header-check
Revisit proxy header check
2018-04-03 10:55:41 +01:00
pyup-bot
691a44f1cf Update sqlalchemy from 1.2.5 to 1.2.6 2018-03-30 21:49:12 +01:00
Athanasios Voutsadakis
8f1f546f69 Increase pool size to 15 permanent connections
At the same time, decrease the number of workers from 5 to 4.

Effect on max db connections will be the same - although with a higher
"resting" number of connections.

Before:
12 (instances) * 5 (workers) * 20 (10 permanent + 10 overflow) = 1200

After:
12 (instances) * 4 (workers) * 25 (15 permanent + 10 overflow) = 1200
2018-03-29 14:57:19 +01:00
Ken Tsang
7524402b56 Only hide the notify tag on precompiled on first page 2018-03-29 14:38:38 +01:00
Ken Tsang
0e6907aba7 Refactor letter utils tests
- tests were failing as creating duplicate buckets
2018-03-29 14:28:06 +01:00
Chris Hill-Scott
54fe9ba275 Merge pull request #1794 from alphagov/pyup-update-pytest-3.4.2-to-3.5.0
Update pytest to 3.5.0
2018-03-29 13:46:28 +01:00
Venus Bailey
2dc663018e Merge pull request #1812 from alphagov/vb-report-tasks
Bug fix: use date only when comparing unique records rather than date…
2018-03-29 11:47:49 +01:00
venusbb
52aeec2247 bug fix: use date only when comparing unique records rather than datetime 2018-03-29 11:42:31 +01:00
Athanasios Voutsadakis
9888ba3d4e Add http health-check for the api app
Also rename the 'elb' argument to 'simple' to be more descriptive.

The healthcheck is going to issue requests to `/_status?simple=true`
just to check that gunicorn is up and running - we don't need to go all
the way to the database, as this would have adverse impact when api is
under load.
2018-03-28 17:19:02 +01:00
Venus Bailey
998863514e Merge pull request #1810 from alphagov/vb-report-tasks
Alter primary key for ft_billing table to include international
2018-03-28 16:17:14 +01:00
venusbb
71bf1fb774 Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-report-tasks 2018-03-28 16:11:00 +01:00
venusbb
3ec68435ff add international as a composite primary key for billing 2018-03-28 16:09:06 +01:00
Athanasios Voutsadakis
331500ce94 Merge branch 'master' into revisit-proxy-header-check 2018-03-28 15:38:56 +01:00
Venus Bailey
a883fc54d8 Merge pull request #1807 from alphagov/vb-report-tasks
Billing database tweak and BST bug fix
2018-03-28 11:01:18 +01:00
venusbb
cf766313e6 Merge branch 'master' of https://github.com/alphagov/notifications-api into vb-report-tasks 2018-03-28 10:53:45 +01:00
venusbb
83aa1b9fa3 use datetime.combine rather than parser.parse 2018-03-28 10:52:37 +01:00
Athanasios Voutsadakis
6f1e4c76d5 Make test context managers more reliable
Sometimes, when a test using one of the set_config[_values] context managers
failed or raised an exception it would cause the context to not be able
to revert its config changes, resulting in a 'spooky action at a
distance' where random tests would start to fail for non-obvious reasons.
2018-03-27 17:41:05 +01:00
Athanasios Voutsadakis
463f1eefaf Move proxy header check to auth-requiring endpoints
The main drive behind this is to allow us to enable http healthchecks on
the `/_status` endpoint. The healthcheck requests are happening directly
on the instances without going to the proxy to get the header properly
set.

In any case, endpoints like `/_status` should be generally accessible by
anything without requiring any form of authorization.
2018-03-27 17:37:09 +01:00
Chris Hill-Scott
45aca51d4d Merge pull request #1808 from alphagov/no-entities-plain-text
Don’t show HTML entities in plain text emails
2018-03-27 15:31:47 +01:00
Chris Hill-Scott
eebd754a58 Don’t show HTML entities in plain text emails
Brings in:
- [ ] https://github.com/alphagov/notifications-utils/pull/427
2018-03-27 14:44:41 +01:00