Rename Metrics' "keys" to "labels"

pull/108/head
Paul "LeoNerd" Evans 2015-03-06 15:28:06 +00:00
parent 399689dcc7
commit f9478e475b
7 changed files with 26 additions and 26 deletions

View File

@ -71,11 +71,11 @@ class TransactionQueue(object):
metrics.register_callback("pending_pdus", metrics.register_callback("pending_pdus",
lambda: {(dest,): len(pdus[dest]) for dest in pdus.keys()}, lambda: {(dest,): len(pdus[dest]) for dest in pdus.keys()},
keys=["dest"], labels=["dest"],
) )
metrics.register_callback("pending_edus", metrics.register_callback("pending_edus",
lambda: {(dest,): len(edus[dest]) for dest in edus.keys()}, lambda: {(dest,): len(edus[dest]) for dest in edus.keys()},
keys=["dest"], labels=["dest"],
) )
def can_send_to(self, destination): def can_send_to(self, destination):

View File

@ -35,10 +35,10 @@ logger = logging.getLogger(__name__)
metrics = synapse.metrics.get_metrics_for(__name__) metrics = synapse.metrics.get_metrics_for(__name__)
outgoing_requests_counter = metrics.register_counter("outgoing_requests", outgoing_requests_counter = metrics.register_counter("outgoing_requests",
keys=["method"], labels=["method"],
) )
incoming_responses_counter = metrics.register_counter("incoming_responses", incoming_responses_counter = metrics.register_counter("incoming_responses",
keys=["method","code"], labels=["method","code"],
) )

View File

@ -44,10 +44,10 @@ logger = logging.getLogger(__name__)
metrics = synapse.metrics.get_metrics_for(__name__) metrics = synapse.metrics.get_metrics_for(__name__)
outgoing_requests_counter = metrics.register_counter("outgoing_requests", outgoing_requests_counter = metrics.register_counter("outgoing_requests",
keys=["method"], labels=["method"],
) )
incoming_responses_counter = metrics.register_counter("incoming_responses", incoming_responses_counter = metrics.register_counter("incoming_responses",
keys=["method","code"], labels=["method","code"],
) )

View File

@ -38,10 +38,10 @@ logger = logging.getLogger(__name__)
metrics = synapse.metrics.get_metrics_for(__name__) metrics = synapse.metrics.get_metrics_for(__name__)
incoming_requests_counter = metrics.register_counter("incoming_requests", incoming_requests_counter = metrics.register_counter("incoming_requests",
keys=["method"], labels=["method"],
) )
outgoing_responses_counter = metrics.register_counter("outgoing_responses", outgoing_responses_counter = metrics.register_counter("outgoing_responses",
keys=["method","code"], labels=["method","code"],
) )

View File

@ -25,22 +25,22 @@ def map_concat(func, items):
class BaseMetric(object): class BaseMetric(object):
def __init__(self, name, keys=[]): def __init__(self, name, labels=[]):
self.name = name self.name = name
self.keys = keys # OK not to clone as we never write it self.labels = labels # OK not to clone as we never write it
def dimension(self): def dimension(self):
return len(self.keys) return len(self.labels)
def is_scalar(self): def is_scalar(self):
return not len(self.keys) return not len(self.labels)
def _render_key(self, values): def _render_key(self, values):
if self.is_scalar(): if self.is_scalar():
return "" return ""
# TODO: some kind of value escape # TODO: some kind of value escape
return "{%s}" % ( return "{%s}" % (
",".join(["%s=%s" % kv for kv in zip(self.keys, values)]) ",".join(["%s=%s" % kv for kv in zip(self.labels, values)])
) )
def render(self): def render(self):
@ -62,7 +62,7 @@ class CounterMetric(BaseMetric):
def inc(self, *values): def inc(self, *values):
if len(values) != self.dimension(): if len(values) != self.dimension():
raise ValueError("Expected as many values to inc() as keys (%d)" % raise ValueError("Expected as many values to inc() as labels (%d)" %
(self.dimension()) (self.dimension())
) )
@ -85,8 +85,8 @@ class CallbackMetric(BaseMetric):
it is rendered. Typically this is used to implement gauges that yield the it is rendered. Typically this is used to implement gauges that yield the
size or other state of some in-memory object by actively querying it.""" size or other state of some in-memory object by actively querying it."""
def __init__(self, name, callback, keys=[]): def __init__(self, name, callback, labels=[]):
super(CallbackMetric, self).__init__(name, keys=keys) super(CallbackMetric, self).__init__(name, labels=labels)
self.callback = callback self.callback = callback
@ -139,15 +139,15 @@ class CacheMetric(object):
This metric generates standard metric name pairs, so that monitoring rules This metric generates standard metric name pairs, so that monitoring rules
can easily be applied to measure hit ratio.""" can easily be applied to measure hit ratio."""
def __init__(self, name, size_callback, keys=[]): def __init__(self, name, size_callback, labels=[]):
self.name = name self.name = name
self.hits = CounterMetric(name + ":hits", keys=keys) self.hits = CounterMetric(name + ":hits", labels=labels)
self.misses = CounterMetric(name + ":misses", keys=keys) self.misses = CounterMetric(name + ":misses", labels=labels)
self.size = CallbackMetric(name + ":size", self.size = CallbackMetric(name + ":size",
callback=size_callback, callback=size_callback,
keys=keys, labels=labels,
) )
def inc_hits(self, *values): def inc_hits(self, *values):

View File

@ -38,9 +38,9 @@ transaction_logger = logging.getLogger("synapse.storage.txn")
metrics = synapse.metrics.get_metrics_for("synapse.storage") metrics = synapse.metrics.get_metrics_for("synapse.storage")
sql_query_timer = metrics.register_timer("queries", keys=["verb"]) sql_query_timer = metrics.register_timer("queries", labels=["verb"])
sql_txn_timer = metrics.register_timer("transactions", keys=["desc"]) sql_txn_timer = metrics.register_timer("transactions", labels=["desc"])
sql_getevents_timer = metrics.register_timer("get_events", keys=["desc"]) sql_getevents_timer = metrics.register_timer("get_events", labels=["desc"])
# TODO(paul): # TODO(paul):

View File

@ -43,7 +43,7 @@ class CounterMetricTestCase(unittest.TestCase):
]) ])
def test_vector(self): def test_vector(self):
counter = CounterMetric("vector", keys=["method"]) counter = CounterMetric("vector", labels=["method"])
# Empty counter doesn't yet know what values it has # Empty counter doesn't yet know what values it has
self.assertEquals(counter.render(), []) self.assertEquals(counter.render(), [])
@ -83,7 +83,7 @@ class CallbackMetricTestCase(unittest.TestCase):
def test_vector(self): def test_vector(self):
vals = dict() vals = dict()
metric = CallbackMetric("values", lambda: vals, keys=["type"]) metric = CallbackMetric("values", lambda: vals, labels=["type"])
self.assertEquals(metric.render(), []) self.assertEquals(metric.render(), [])
@ -115,7 +115,7 @@ class TimerMetricTestCase(unittest.TestCase):
]) ])
def test_vector(self): def test_vector(self):
metric = TimerMetric("queries", keys=["verb"]) metric = TimerMetric("queries", labels=["verb"])
self.assertEquals(metric.render(), []) self.assertEquals(metric.render(), [])