Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #70 from mozilla-services/greeshma-patch
Browse files Browse the repository at this point in the history
Add the statsd_count helper.
  • Loading branch information
Natim committed Nov 16, 2015
2 parents 7b916e8 + 41b9f38 commit 0251f2c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
5 changes: 2 additions & 3 deletions syncto/views/collection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pyramid.security import NO_PERMISSION_REQUIRED

from cliquet import Service
from cliquet.statsd import statsd_count
from cliquet.errors import raise_invalid

from syncto.authentication import build_sync_client
Expand Down Expand Up @@ -64,9 +65,7 @@ def collection_get(request):
records = sync_client.get_records(collection_name, full=True,
headers=headers, **params)

statsd = request.registry.statsd
if statsd:
statsd.count("syncclient.status_code.200")
statsd_count(request, "syncclient.status_code.200")

for r in records:
r['last_modified'] = int(r.pop('modified') * 1000)
Expand Down
9 changes: 4 additions & 5 deletions syncto/views/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cliquet import logger
from cliquet.errors import http_error, ERRORS
from cliquet.statsd import statsd_count
from cliquet.utils import reapply_cors
from cliquet.views.errors import service_unavailable

Expand All @@ -18,11 +19,9 @@ def response_error(context, request):
context.response.reason,
context.response.text)

statsd = request.registry.statsd

if statsd:
statsd.count("syncclient.status_code.%s" %
context.response.status_code)
# XXX: Make sure these HTTPError exception are coming from SyncClient.
statsd_count(request, "syncclient.status_code.%s" %
context.response.status_code)

if context.response.status_code in (400, 401, 403, 404):
# For this code we also want to log the info about the error.
Expand Down
16 changes: 6 additions & 10 deletions syncto/views/record.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import re

import colander
from cliquet import Service, schema, errors
from pyramid import httpexceptions
from pyramid.security import NO_PERMISSION_REQUIRED

from cliquet import Service, schema, errors
from cliquet.statsd import statsd_count

from syncto.authentication import build_sync_client
from syncto.headers import import_headers, export_headers

Expand Down Expand Up @@ -61,9 +63,7 @@ def record_get(request):
# Configure headers
export_headers(sync_client.raw_resp, request)

statsd = request.registry.statsd
if statsd:
statsd.count("syncclient.status_code.200")
statsd_count(request, "syncclient.status_code.200")

return {'data': record}

Expand Down Expand Up @@ -93,9 +93,7 @@ def record_put(request):
# Configure headers
export_headers(sync_client.raw_resp, request)

statsd = request.registry.statsd
if statsd:
statsd.count("syncclient.status_code.200")
statsd_count(request, "syncclient.status_code.200")

return {'data': record}

Expand All @@ -113,9 +111,7 @@ def record_delete(request):
sync_client = build_sync_client(request)
sync_client.delete_record(collection_name, sync_id, headers=headers)

statsd = request.registry.statsd
if statsd:
statsd.count("syncclient.status_code.204")
statsd_count(request, "syncclient.status_code.204")

request.response.status_code = 204
del request.response.headers['Content-Type']
Expand Down

0 comments on commit 0251f2c

Please sign in to comment.