Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
Merge 6187c00 into 013f8ac
Browse files Browse the repository at this point in the history
  • Loading branch information
pior committed Dec 16, 2014
2 parents 013f8ac + 6187c00 commit f033902
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -9,6 +9,11 @@ TODO
* Introspectables
* Content negociation: we should add content type in cache key.

Development
-----------

* Fix invalid Graphite metric names (replace periods/colon with underscore)

0.2.3
-----

Expand Down
3 changes: 2 additions & 1 deletion pyramid_caching/ext/metrics.py
Expand Up @@ -36,4 +36,5 @@ def cache_miss(event):

def count_view_cache_event(event, access):
metrics = event.request.metrics
metrics.incr(('cache.%s' % access, event.cache_key.root()))
key = event.cache_key.root().replace(':', '_').replace('.', '_')
metrics.incr(('cache.%s' % access, key))
6 changes: 3 additions & 3 deletions pyramid_caching/tests/functional/test_metrics.py
Expand Up @@ -25,7 +25,7 @@ def test_cache_miss(self, m_statsd):
self.app.get('/users/1')
m_incr = m_statsd.return_value.incr
m_incr.assert_called_once_with(
'cache.miss.example.views:get_user:http', count=1)
'cache.miss.example_views_get_user_http', count=1)

@mock.patch('pyramid_metrics.utility.StatsClient')
def test_cache_hit(self, m_statsd):
Expand All @@ -34,8 +34,8 @@ def test_cache_hit(self, m_statsd):

m_incr = m_statsd.return_value.incr
m_incr.assert_has_calls([
mock.call('cache.miss.example.views:get_user:http', count=1),
mock.call('cache.hit.example.views:get_user:http', count=1),
mock.call('cache.miss.example_views_get_user_http', count=1),
mock.call('cache.hit.example_views_get_user_http', count=1),
])


Expand Down
4 changes: 2 additions & 2 deletions pyramid_caching/tests/unittests/test_metrics_extension.py
Expand Up @@ -9,14 +9,14 @@ def test_cache_hit(self):
event = DummyEvent()
cache_hit(event)
self.assertEqual(len(event.request.metrics.keys), 1)
self.assertEqual(event.request.metrics.keys[0], ('cache.hit', 'a:b'))
self.assertEqual(event.request.metrics.keys[0], ('cache.hit', 'a_b'))

def test_cache_miss(self):
from pyramid_caching.ext.metrics import cache_miss
event = DummyEvent()
cache_miss(event)
self.assertEqual(len(event.request.metrics.keys), 1)
self.assertEqual(event.request.metrics.keys[0], ('cache.miss', 'a:b'))
self.assertEqual(event.request.metrics.keys[0], ('cache.miss', 'a_b'))


class DummyEvent:
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Expand Up @@ -5,7 +5,7 @@ nose-parameterized
coverage
mock
webtest
yanc
yanc==0.2.4
Paste
PasteDeploy
coveralls
Expand Down

0 comments on commit f033902

Please sign in to comment.