Commit Graph

5905 Commits

Author SHA1 Message Date
Rebecca Law
a4d89359c5 Adding a filter to exclude test keys for the template monthly usage query.
Added a test.
2019-01-15 16:13:38 +00:00
Rebecca Law
3fdf0c7822 Merge pull request #2302 from alphagov/clean-up-template-stats-table
Clean up template stats task and queries
2019-01-15 11:03:58 +00:00
Rebecca Law
efad58edd8 There is no need to have a separate table to store template monthly statistics. It's easy enough to aggregate the stats from ft_notification_status.
This removes the nightly task, and all the dao methods.
The next PR will remove the table.
2019-01-14 16:30:36 +00:00
Rebecca Law
79f49ebdc2 Merge pull request #2298 from alphagov/use-ft-notification-statu-for-monthly-template-usage
Use ft_notification_status for monthly template usage
2019-01-14 15:43:41 +00:00
Rebecca Law
b5a3ef9576 Added order by.
Added more unit tests.
Remove comments.
2019-01-14 15:28:26 +00:00
Katie Smith
4f917067a5 Merge pull request #2295 from alphagov/move-unopenable-precompiled-letters
Move letters which can't be opened to invalid PDF bucket
2019-01-14 12:56:45 +00:00
Alexey Bezhan
5336a72d0f Merge pull request #2291 from alphagov/set-db-statement-timeout
Set statement timeout on all DB connections
2019-01-14 10:24:07 +00:00
Rebecca Law
92460fbd38 Merge branch 'master' into use-ft-notification-statu-for-monthly-template-usage 2019-01-11 17:11:23 +00:00
Rebecca Law
c3c9d1eac9 Add unit tests.
Fix data types in result set.
2019-01-11 17:09:42 +00:00
Katie Smith
a9b755b08c Move letters which can't be opened to invalid PDF bucket
If a precompiled letter can't be opened (e.g. because it isn't a valid
PDF) we were setting its billable units to 0, but not moving it to the
invalid PDF bucket. If a precompiled letter failed sanitisation, we were
moving it to the invalid PDF bucket but not setting its billable units
to 0.

This commit makes sure that we always set the billable units to 0
and move the PDF to the right bucket if it fails sanitisation or can't be
opened.
2019-01-11 16:59:07 +00:00
Chris Hill-Scott
04610716f3 Merge pull request #2296 from alphagov/north-somerset-letter-logo
Add letter logo for North Somerset council
2019-01-11 16:09:53 +00:00
Pea (Malgorzata Tyczynska)
cfb55daa12 Merge pull request #2292 from alphagov/exclude_cancelled_from_requested
Remove cancelled from requested statuses in service statistics
2019-01-11 15:01:20 +00:00
Chris Hill-Scott
3559063b91 Add letter logo for North Somerset council 2019-01-11 14:44:23 +00:00
Pea Tyczynska
bd5126481c Remove cancelled from requested statuses in service statistics 2019-01-11 14:27:54 +00:00
Leo Hemsted
5e7bff08aa Merge pull request #2287 from alphagov/redis-bump
bump utils (inc redis bump)
2019-01-11 10:59:46 +00:00
Leo Hemsted
a970318586 Merge pull request #2294 from alphagov/remove-unused-functions
remove unused usage functions
2019-01-11 10:59:17 +00:00
Rebecca Law
507138cc94 Create a new query for template monthly stats. 2019-01-10 16:24:51 +00:00
Leo Hemsted
20fe055ac9 remove unused usage functions 2019-01-10 16:08:15 +00:00
Pea (Malgorzata Tyczynska)
c5e5c86982 Merge pull request #2290 from alphagov/its_not_a_failure_to_cancel
Cancelled notifications don't show as failures in statistics
2019-01-10 15:09:30 +00:00
Alexey Bezhan
4a26ee1813 Set statement timeout on all DB connections
A recent issue with a long-running query (#2288) highlighted the
fact that even though the original HTTP connection might be closed
(for example after gorouter timeout of 15 minutes, which returns a
504 response to the client), the request worker will not be stopped.

This means that the worker is spending time and potentially DB
resources generating a response that will never be delivered.

Gunicorn's timeout setting only applies to sync workers and there
doesn't seem to be an option to interrupt individual requests in
gevent/eventlet deployments.

Since the most likely (and potentially most dangerous) scenario for
this is a long-running DB query, we can set a statement timeout on
our DB connections. This will raise a sqlalchemy.exc.OperationalError
(wrapping psycopg2.extensions.QueryCanceledError), interrupting the
request after the given timeout has been reached.

This is a Postgres client setting, so the database itself will abort
the transaction when it reaches the set timeout.

Since this will also apply to our celery tasks (including potentially
long-running nightly tasks) we set a timeout of 20 minutes to begin
with.

This can potentially be split in the future to set a different value
for each app, so that we could limit API requests even more.
2019-01-09 14:36:50 +00:00
Alexey Bezhan
1719f31909 Merge pull request #2284 from alphagov/add-count-pages-flag-to-service-notifications
Don't return pagination links for API Message log requests
2019-01-09 14:36:36 +00:00
Leo Hemsted
d4570281fa Merge pull request #2288 from alphagov/plat-adm-fix
Platform admin fix
2019-01-09 14:04:30 +00:00
Pea Tyczynska
e179e1e4a4 Update test 2019-01-09 13:30:28 +00:00
Leo Hemsted
3e21f57481 fix platform admin stats row-order bug
now that we're reading from two tables (ft_notification_status and
notifications) for stats, we'll get a couple of rows for each
notification type. If a service doesn't have any rows in one of those
tables, the query will return a row with nulls for the notification
types and counts. Some services will have history but no stats from
today, others will have data from today but no history.

This commit acknowledges that any row might have nulls, not just the
first row.
2019-01-09 11:43:40 +00:00
Leo Hemsted
5d838415d3 fix filter to look at right table
a query for notifications was filtering on FtNotificationStatus - we
aren't joining to that table in the query, so sqlalchemy added a cross
join between ft_notification_status (3.7k rows) and Notifications (3.9m
rows), resulting in a 1.3 trillion row materialised table. This query
took 17 hours and pending.

Also, remove orders from querys other than the outer one, since we're
grouping anyway.
2019-01-09 11:26:08 +00:00
Pea Tyczynska
e3a79e80c9 Cancelled notifications don't show as failures in statistics 2019-01-08 17:50:34 +00:00
Rebecca Law
9c75e08e2c Merge pull request #2282 from alphagov/optimise-platform-admin-live-services
Optimise platform admin live services
2019-01-08 15:27:46 +00:00
Leo Hemsted
7f9b64d3df bump utils (inc redis bump) 2019-01-08 15:02:09 +00:00
Alexey Bezhan
47c403f6ab Don't return pagination links for API Message log requests
Flask-SQLAlchemy paginate function issues a separate query to get
the total count of rows for a given filter. This query (with
filters used by the API integration Message log page) is slow for
services with large number of notifications.

Since Message log page doesn't actually allow users to paginate
through the response (it only shows the last 50 messages) we can
use limit instead of paginate, which requires passing in another
flag from admin to the dao method.

`count` flag has been added to `paginate` in March 2018, however
there was no release of flask-sqlalchemy since then, so we need
to pull the dev version of the package from Github.
2019-01-08 13:22:27 +00:00
Rebecca Law
8fbe60bb90 Remove unused query 2019-01-07 15:37:26 +00:00
Rebecca Law
4522547753 Merge branch 'master' into optimise-platform-admin-live-services 2019-01-07 15:25:50 +00:00
Leo Hemsted
fe498f9a79 Merge pull request #2280 from alphagov/redis-pin
pin redis to 2.x
2019-01-07 11:30:34 +00:00
Leo Hemsted
40a17a0e93 pin redis to 2.x
while we sort out v3 compatibility
2019-01-07 11:14:25 +00:00
Rebecca Law
bd9a6352fd Optimise the query for getting the platform statistics for all services. The page should render for all time after this change.
This is one step closer to eliminating the need to read from NotificationHistory.
2019-01-04 16:45:39 +00:00
Leo Hemsted
63e16ea0ba Merge pull request #2276 from alphagov/utils-bump
bump utils
2019-01-04 16:37:09 +00:00
Leo Hemsted
2e53ba1e3e bump utils
brings in https://github.com/alphagov/notifications-utils/pull/563
2019-01-04 16:17:52 +00:00
Chris Hill-Scott
90a6ec5a15 Merge pull request #2275 from alphagov/trailing-new-line-before-markdown
Bump utils to 30.7.2
2019-01-04 11:28:17 +00:00
Leo Hemsted
ea3070d645 Merge pull request #2272 from alphagov/delivery-receipt-logging
log more info when we receive multiple delivery callbacks
2019-01-04 09:52:54 +00:00
Leo Hemsted
021625abb3 make sure log line works if notification still in created 2019-01-03 17:08:17 +00:00
Leo Hemsted
2355ee011f log more info when we receive multiple delivery callbacks for one notification
Previously, we logged a warning containing the notification reference
and new status. However it wasn't a great message - this new one
includes the notification id, the old status, the time difference and
more.

This separates out logs for callbacks for notifications we don't know
(error level) and duplicates (info level).
2019-01-03 17:08:16 +00:00
Pea (Malgorzata Tyczynska)
d5130d8579 Merge pull request #2273 from alphagov/cautious_prepping_for_pytest4
Preparation for pytest 4 by sorting our use of fixtures in conftest
2019-01-03 11:12:52 +00:00
Pea Tyczynska
eea324a19d Add flag on create_service to decide whether we should also check if service exists 2019-01-03 10:57:29 +00:00
Pea Tyczynska
f79c0b03e7 Sample job uses create_template instead of sample template 2019-01-03 10:52:14 +00:00
Pea Tyczynska
cde30de100 Use create_template instead of sample_template in sample_notification 2019-01-03 10:52:14 +00:00
Pea Tyczynska
154257027f Nothing in conftest uses sample_service now :) 2019-01-03 10:52:14 +00:00
Pea Tyczynska
d367daaf6e Some more conftest fixtures use create_service instead of sample_service 2019-01-03 10:52:14 +00:00
Pea Tyczynska
a3310c2da6 sample_job uses create_service instead of sample_service 2019-01-03 10:52:14 +00:00
Pea Tyczynska
0bcf13d85c sample_api_key uses create_service instead of sample_service 2019-01-03 10:52:14 +00:00
Pea Tyczynska
e8ce669b72 Use create_service instead of sample_service when creating sample_email_template for tests 2019-01-03 10:52:14 +00:00
Pea Tyczynska
95115e7ae6 Use create_service instead of sample_service when creating service permission for tests 2019-01-03 10:52:14 +00:00