Skip to content

Commit

Permalink
Merge pull request #1514 from GabiThume/bug916905
Browse files Browse the repository at this point in the history
Fixes Bug 916905 - removing unique uuids and dates
  • Loading branch information
lonnen committed Sep 17, 2013
2 parents 9e8d664 + 7ab6b5c commit 3537765
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
14 changes: 13 additions & 1 deletion webapp-django/crashstats/crashstats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import stat
import time
import urllib
import re

from django.conf import settings
from django.core.cache import cache
Expand Down Expand Up @@ -176,12 +177,23 @@ def _process_response(self, method, url, status_code):
path = urlparse.urlparse(url).path
path_info = urllib.quote(path.encode('utf-8'))

# Removes uuids from path_info
if "uuid/" in url:
uuid = path_info.rsplit("/uuid/")
if len(uuid) == 2:
path_info = uuid[0] + '/uuid' + uuid[1][uuid[1].find('/'):]

# Replaces dates for XXXX-XX-XX
replaces = re.findall(r'(\d{4}-\d{2}-\d{2})', path_info)
for date in replaces:
date = path_info[path_info.find(date):].rsplit("/")[0]
path_info = path_info.replace(date, "XXXX-XX-XX")

metric = u"middleware.{0}.{1}.{2}".format(
method.upper(),
path_info.lstrip('/').replace('.', '-'),
status_code
)

metric = metric.encode('utf-8')
statsd.incr(metric)

Expand Down
64 changes: 63 additions & 1 deletion webapp-django/crashstats/crashstats/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,69 @@ def mocked_get(url, **options):
rget.side_effect = mocked_get
api.get(crash_id='crash-id')
assert incr.called
metric = 'middleware.GET.crash_data/uuid/crash-id/datatype/meta/.200'
metric = 'middleware.GET.crash_data/uuid/datatype/meta/.200'
incr.assert_called_with(metric)

# Test if replaces dates for XXXX-XX-XX
model = models.TCBS
api = model()

def mocked_get(**options):
assert 'crashes/signatures' in options['url']
return Response("""
{
"start_date": "2012-05-10",
"end_date": "2012-05-24"
}
""")

rget.side_effect = mocked_get
today = datetime.datetime.utcnow()
api.get(
product='Thunderbird',
version='12.0',
end_date=today,
)
assert incr.called
metric = "middleware.GET.crashes/signatures/product/Thunderbird/" \
"version/12-0/end_date/XXXX-XX-XX/limit/300/.200"
incr.assert_called_with(metric)

# Test if removes unique uuids
model = models.ProcessedCrash
api = model()

def mocked_get(url, **options):
assert '/crash_data/' in url
ok_('/datatype/processed/' in url)
return Response("""
{
"product": "WaterWolf",
"uuid": "7c44ade2-fdeb-4d6c-830a-07d302120525",
"version": "13.0",
"build": "20120501201020",
"ReleaseChannel": "beta",
"os_name": "Windows NT",
"date_processed": "2012-05-25 11:35:57",
"success": true,
"signature": "CLocalEndpointEnumerator::OnMediaNotific",
"addons": [
[
"testpilot@labs.mozilla.com",
"1.2.1"
],
[
"{972ce4c6-7e08-4474-a285-3208198ce6fd}",
"13.0"
]
]
}
""")

rget.side_effect = mocked_get
api.get(crash_id='7c44ade2-fdeb-4d6c-830a-07d302120525')
assert incr.called
metric = "middleware.GET.crash_data/datatype/processed/uuid/.200"
incr.assert_called_with(metric)


Expand Down

0 comments on commit 3537765

Please sign in to comment.