def __init__(self, container, address, timeout=REQUEST_TIMEOUT, namespace='', error_map=None): super(Proxy, self).__init__() self._container = container self._address = address self._method_cache = {} self._timeout = timeout self._namespace = namespace or address self._error_map = error_map or {} self.timeout_counts = metrics.Counter('timeout', {'address': address}) self.exception_counts = metrics.TaggedCounter('exceptions', {'address': address})
def on_start(self): super(Proxy, self).on_start() self.timeout_counts = self.metrics.add(metrics.Counter('rpc.timeout_count', {'address': self._address})) self.exception_counts = self.metrics.add(metrics.TaggedCounter('rpc.exception_count', {'address': self._address}))
def test_get(self): counter = metrics.Counter('requests') self.assertEqual(list(counter), [('requests', 0, {})])
def test_increment_by_many(self): counter = metrics.Counter('requests') counter += 66 self.assertEqual(list(counter), [('requests', 66, {})])
def test_increment_by_one(self): counter = metrics.Counter('requests') counter += 1 self.assertEqual(list(counter), [('requests', 1, {})])
def test_repr(self): counter = metrics.Counter('requests') self.assertEqual(str(counter), repr(counter)) self.assertEqual(repr(counter), "Counter(name='requests', tags={})")