mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
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.
This commit is contained in:
24
tests/app/test_statsd_decorators.py
Normal file
24
tests/app/test_statsd_decorators.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from mock import ANY
|
||||
|
||||
from app.statsd_decorators import statsd
|
||||
import app
|
||||
|
||||
|
||||
class AnyStringWith(str):
|
||||
def __eq__(self, other):
|
||||
return self in other
|
||||
|
||||
|
||||
def test_should_call_statsd(notify_api, mocker):
|
||||
mocker.patch('app.statsd_client.incr')
|
||||
mocker.patch('app.statsd_client.timing')
|
||||
mock_logger = mocker.patch.object(notify_api.logger, 'info')
|
||||
|
||||
@statsd(namespace="test")
|
||||
def test_function():
|
||||
return True
|
||||
|
||||
assert test_function()
|
||||
app.statsd_client.incr.assert_called_once_with("test.test_function")
|
||||
app.statsd_client.timing.assert_called_once_with("test.test_function", ANY)
|
||||
mock_logger.assert_called_once_with(AnyStringWith("test call test_function took "))
|
||||
Reference in New Issue
Block a user