Rename Metrics' "keys" to "labels"

This commit is contained in:
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",
lambda: {(dest,): len(pdus[dest]) for dest in pdus.keys()},
keys=["dest"],
labels=["dest"],
)
metrics.register_callback("pending_edus",
lambda: {(dest,): len(edus[dest]) for dest in edus.keys()},
keys=["dest"],
labels=["dest"],
)
def can_send_to(self, destination):

View File

@ -35,10 +35,10 @@ logger = logging.getLogger(__name__)
metrics = synapse.metrics.get_metrics_for(__name__)
outgoing_requests_counter = metrics.register_counter("outgoing_requests",
keys=["method"],
labels=["method"],
)
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__)
outgoing_requests_counter = metrics.register_counter("outgoing_requests",
keys=["method"],
labels=["method"],
)
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__)
incoming_requests_counter = metrics.register_counter("incoming_requests",
keys=["method"],
labels=["method"],
)
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):
def __init__(self, name, keys=[]):
def __init__(self, name, labels=[]):
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):
return len(self.keys)
return len(self.labels)
def is_scalar(self):
return not len(self.keys)
return not len(self.labels)
def _render_key(self, values):
if self.is_scalar():
return ""
# TODO: some kind of value escape
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):
@ -62,7 +62,7 @@ class CounterMetric(BaseMetric):
def inc(self, *values):
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())
)
@ -85,8 +85,8 @@ class CallbackMetric(BaseMetric):
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."""
def __init__(self, name, callback, keys=[]):
super(CallbackMetric, self).__init__(name, keys=keys)
def __init__(self, name, callback, labels=[]):
super(CallbackMetric, self).__init__(name, labels=labels)
self.callback = callback
@ -139,15 +139,15 @@ class CacheMetric(object):
This metric generates standard metric name pairs, so that monitoring rules
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.hits = CounterMetric(name + ":hits", keys=keys)
self.misses = CounterMetric(name + ":misses", keys=keys)
self.hits = CounterMetric(name + ":hits", labels=labels)
self.misses = CounterMetric(name + ":misses", labels=labels)
self.size = CallbackMetric(name + ":size",
callback=size_callback,
keys=keys,
labels=labels,
)
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")
sql_query_timer = metrics.register_timer("queries", keys=["verb"])
sql_txn_timer = metrics.register_timer("transactions", keys=["desc"])
sql_getevents_timer = metrics.register_timer("get_events", keys=["desc"])
sql_query_timer = metrics.register_timer("queries", labels=["verb"])
sql_txn_timer = metrics.register_timer("transactions", labels=["desc"])
sql_getevents_timer = metrics.register_timer("get_events", labels=["desc"])
# TODO(paul):

View File

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