Commit Graph

100 Commits

Author SHA1 Message Date
Imdad Ahad
c811f1b6c6 Init the perf platform client, add logs and refactor payload methods 2017-01-30 18:24:06 +00:00
Imdad Ahad
ed52f41039 Add, init and config performance platform client to prepare/upload daily notification stats 2017-01-27 12:21:08 +00:00
bandesz
fd66fbd719 Run API on Paas 2017-01-13 10:24:13 +00:00
Martyn Inglis
7260561ad5 Makes the app use the redis and statsd clients from utils 2016-12-01 17:20:05 +00:00
Martyn Inglis
7fe56cf992 Add request ID logging to the API.
- adds a request ID if needed to use in all log events
- respects request-ids passed in from calling clients
2016-11-30 17:05:39 +00:00
minglis
40cf6c049f Merge pull request #746 from alphagov/record-user-agent
Statsd counter for user agents.
2016-11-30 12:51:30 +00:00
Martyn Inglis
e698d124ba Statsd counter for user agents.
We want to log the usage of the various API clients we have so that we understand when they can be cycled.

To this end we are going to count usage in statsd.

All notify clients have a suer agent, of the format: NOTIFY-API-{LANGUAGE}-CLIENT/version.number

For example, NOTIFY-API-PYTHON-CLIENT/3.0.0

We convert that into a statsd/graphite friendly string of the format: notify-api-python-client.3-0-0

So we can subdivide on client and client version on our dashboards.

Present but unknown User agents are records as "non-notify-user-agent"

Missing are presented as "unknown"
2016-11-25 13:27:36 +00:00
Rebecca Law
669126d41b Merge pull request #744 from alphagov/add-default-exception-handler
Add application level error handler.
2016-11-25 09:34:23 +00:00
Rebecca Law
52c8596c92 Add application level error handler.
This should catch any unexcpeted exceptions.
2016-11-24 17:09:56 +00:00
Martyn Inglis
2a2ef34339 Merge branch 'master' into caching-with-redis
Conflicts:
	app/__init__.py
2016-11-23 09:12:11 +00:00
Paul Craig
c1fa5e156a Append "Z" to DATETIME_FORMAT
We're formally using the ISO 8601 UTC datetime format, and so the
correct way to output the data is by appending the timezone.
("Z" in the case of UTC*).

Unfortunately, Python's `datetime` formatting will just ignore the
timezone part of the string on output, which means we just have to
append the string "Z" to the end of all datetime strings we output.

Should be fine, as we will only ever output UTC timestamps anyway.

* https://en.wikipedia.org/wiki/ISO_8601#UTC
2016-11-21 15:59:10 +00:00
Paul Craig
9758b96a2b Create 'v2' get notification route
The new 'v2' API wants to return less data than the previous one,
which was sending back tons of fields the clients never used.

This new route returns only useful information, with the JSON
response dict being built up in the model's `.serialize()` method.

Note that writing the test for this was a bit painful because of
having to treat loads of keys differently. Hopefully we think this
is a good way to write this test, because if we don't, we should
start thinking of a better way to check the values are what we
expect.
2016-11-21 15:41:49 +00:00
Martyn Inglis
6c27f8023e Added tests for setting and fetching from redis respecting the enabled flag. 2016-11-10 13:22:38 +00:00
Martyn Inglis
aabda3f83e Refactored the initialisation of the redis client to follow the model used in the StatsdClient.
Basically wrapped the client so we can enable/disable, exception handle and so on.
2016-11-10 11:50:49 +00:00
Martyn Inglis
eb94fe6c0a Adding Flask-Redis to the project.
[https://pypi.python.org/pypi/Flask-Redis/0.1.0](https://pypi.python.org/pypi/Flask-Redis/0.1.0)

Initial addition as we think about redis as cache.
2016-11-10 11:27:57 +00:00
Martyn Inglis
aea2356ae1 Initial SPIKE into redis for cache 2016-11-07 11:55:59 +00:00
Rebecca Law
c2eecdae36 - Add validation methods for post notification.
- Use these validation methods in post_sms_notification and the version 1 of post_notification.
- Create a v2 error handlers.
- InvalidRequest has a to_dict method for private and v1 error responses and a to_dict_v2 method to create the v2 of the error responses.
- Each validation method has extensive unit tests, so the unit test for the endpoint do not need to check every error case, but check that the error handle formats the message correctly.
- The format of the error messages is still a work on progress.
- This version of the api could be deployed without causing a problem to the application.
- The new endpoing is still a work in progress and is not being used yet.
2016-10-27 11:46:37 +01:00
Martyn Inglis
37a2dc7925 Implemented the REST endpoint to communicate with the new send-to-provider code
- this allows us to send a notification to a provider by means of an API call
- This is in addition to the celery code.
- idea is that we can use this method to help speed up throughput by generating API traffic by node/lambda etc to supplement the celery code in times of high load.
2016-09-22 14:01:25 +01:00
Martyn Inglis
c1b00a5f0c Simplified the config. Aim is to get the actual secrets in credstash to be env specific, and not the random collection of things we have at the moment.
Secret definition also includes env specific things such as URLs / Queue prefixes / URLs for providers and so on.
2016-09-07 09:35:31 +01:00
Leo Hemsted
2053ebd933 rename service to service_blueprint
it was causing a bug where a local variable service was not being
instantiated and we were trying to operate on the blueprint instead

it's being used in so few places it makes sense to rename it
2016-08-24 15:00:51 +01:00
Leo Hemsted
f065b08db2 remove unused dao functions 2016-08-11 16:13:53 +01:00
Leo Hemsted
fff81b4910 remove unused notification-statistics endpoints 2016-08-11 11:55:28 +01:00
Leo Hemsted
e631333a34 add GET /organisation and GET /organisation/id endpoints 2016-08-09 15:59:22 +01:00
Martyn Inglis
0fa614d812 Removed unused import 2016-08-08 11:09:07 +01:00
Martyn Inglis
f223446f73 Refactor statsd logging
Removed all existing statsd logging and replaced with:

- statsd decorator. Infers the stat name from the decorated function call. Delegates statsd call to statsd client. Calls incr and timing for each decorated method. This is applied to all tasks and all dao methods that touch the notifications/notification_history tables

- statsd client changed to prefix all stats with "notification.api."

- Relies on https://github.com/alphagov/notifications-utils/pull/61 for request logging. Once integrated we pass the statsd client to the logger, allowing us to statsd all API calls. This passes in the start time and the method to be called (NOT the url) onto the global flask object. We then construct statsd counters and timers in the following way

	notifications.api.POST.notifications.send_notification.200

This should allow us to aggregate to the level of

	- API or ADMIN
	- POST or GET etc
	- modules
	- methods
	- status codes

Finally we count the callbacks received from 3rd parties to mapped status.
2016-08-05 10:44:43 +01:00
Martyn Inglis
dbe34f46e6 Reordered imports 2016-07-29 10:15:34 +01:00
Martyn Inglis
9ec52eac02 New config style 2016-07-29 10:15:34 +01:00
Rebecca Law
f52755742c Split send_email task into one task to create the notification and one to send it to the provider.
Is there is an exception the task will go to the retry queue.
2016-07-01 14:14:28 +01:00
Leo Hemsted
11093530f9 Merge pull request #485 from alphagov/api_user-cleanup
Api user cleanup
2016-07-01 10:58:18 +01:00
Leo Hemsted
18b30de452 fix calling init_app twice
this was causing flask decorators like auth check to be mounted twice
2016-06-30 10:44:21 +01:00
Chris Hill-Scott
7c3d25a87a Publish a Swagger specification
Adds a new endpoint (`/spec`) which returns a the specification of the
API in Swagger-formatted JSON.

This means we will have something to point frontends at, so we can
evaluate which ones we like.

Right now it’s all hand-defined. If we were consistent about our use of
Marshmallow we could generated the spec from the Marshmallow schemas.
2016-06-29 12:07:32 +01:00
Rebecca Law
f8262b13c1 Refactor permissions dao - removed custom query filter
Removed permissions rest - not being used.
2016-06-15 16:32:52 +01:00
Leo Hemsted
0a8cb679d7 make mmg and firetext client params consistent 2016-06-01 15:58:48 +01:00
Martyn Inglis
3f7559b286 Added statsd integration into the API
- new client for statsd, follows conventions used elsewhere for configuration
- client wraps underlying library so we can use a config property to send/not send statsd

Added statsd metrics for:
- count of API successful calls SMS/Email
- count of successful task execution for SMS/Email
- count of errors from Client libraries
- timing of API calls to third party clients
- timing of how long messages live on the SQS queue
2016-05-13 17:15:39 +01:00
Martyn Inglis
19d65772c7 Log start of request so requests can be timed 2016-05-12 13:56:27 +01:00
Martyn Inglis
06bfe81329 Load testing client added 2016-05-12 10:46:35 +01:00
Martyn Inglis
9e71759e57 Added get provider by id 2016-05-10 15:18:41 +01:00
Martyn Inglis
571686b638 Ensure that the primary provider is used in all tasks 2016-05-10 09:04:22 +01:00
Martyn Inglis
4f38039e09 Set up clients wrapper to hold all the clients
- tests FAIL if there is a provider in the DB and not in the CODE
- tests PASS is there a provider in the CODE and not in the DB
2016-05-06 09:47:06 +01:00
Martyn Inglis
57e05feafb Updated the Provider stats and rates DAO objects to query based on the identifier in the ProviderDetails object.
- updated all tests
- changed teardown to leave provider details rows on end of individual tests
2016-05-06 09:09:47 +01:00
Adam Shimali
b51ee0b4d0 Add delivery status endpoint 2016-04-29 13:00:21 +01:00
Adam Shimali
dacbbfbf2f Endpoint for recording events in api.
An event has an id, a type and a blob of json attached.
2016-04-27 10:36:59 +01:00
Nicholas Staples
1b76646170 Working placeholders in subject with upgraded notifications-utils.
Fix test.
2016-04-13 15:53:27 +01:00
Rebecca Law
e8d5a9292a Merge branch 'master' into integrate_MMG
Conflicts:
	app/notifications/rest.py
2016-04-06 14:58:13 +01:00
Rebecca Law
4806123d5c Add process_mmg_responses
Refactor process_firetext_responses
Removed the abstract ClientResponses for firetext and mmg. There is a map for each response to handle the status codes sent by each client.
Since MMG has about 20 different status code, none of which seem to be a pending state (unlike firetext that has 3 status one for pending - network delay).
For MMG status codes, look for 00 as successful, everything else is assumed to be a failure.
2016-04-06 14:31:33 +01:00
Adam Shimali
0d06be05e1 [WIP] Added dao method and rest endpoint for getting template
statistics by service.

Some cosmetic changes to imports.

Added fix for job rest not correctly returning errors.
2016-04-04 14:38:54 +01:00
Rebecca Law
69697388d7 Initial set up for mmg client integration 2016-04-01 16:42:31 +01:00
Rebecca Law
8df4919029 The admin app now sends the email from when creating a service and when updating the service name.
This PR removes the need for the email_safe function. The api does not create the email_from field for the service.
Tests were updated to reflect this change.
2016-03-31 17:46:18 +01:00
Martyn Inglis
9a7788a6f5 Allowing overrides on a per environment basis 2016-03-17 11:47:44 +00:00
Martyn Inglis
6ceddf0ebf pep8 fixed 2016-03-16 14:08:25 +00:00