summary refs log tree commit diff
path: root/synapse/federation/federation_client.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-03-10 15:29:22 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-03-12 16:24:51 +0000
commit2e4f0b2bd736fd70040d936145948b65b4e00b12 (patch)
treef9a631dc9895be2c04ee74cf9d63b5b0c2ce9d47 /synapse/federation/federation_client.py
parentAdd an .inc_by() method to CounterMetric; implement DistributionMetric a neat... (diff)
downloadsynapse-2e4f0b2bd736fd70040d936145948b65b4e00b12.tar.xz
Replace the @metrics.counted annotations in federation with specifically-written counters and distributions
Diffstat (limited to 'synapse/federation/federation_client.py')
-rw-r--r--synapse/federation/federation_client.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/synapse/federation/federation_client.py b/synapse/federation/federation_client.py
index ef177b79cc..6811a0e3d1 100644
--- a/synapse/federation/federation_client.py
+++ b/synapse/federation/federation_client.py
@@ -36,7 +36,15 @@ import random
 
 logger = logging.getLogger(__name__)
 
-metrics = synapse.metrics.get_metrics_for(__name__)
+
+# synapse.federation.federation_client is a silly name
+metrics = synapse.metrics.get_metrics_for("synapse.federation.client")
+
+sent_pdus_destination_dist = metrics.register_distribution("sent_pdu_destinations")
+
+sent_edus_counter = metrics.register_counter("sent_edus")
+
+sent_queries_counter = metrics.register_counter("sent_queries", labels=["type"])
 
 
 class FederationClient(FederationBase):
@@ -53,7 +61,6 @@ class FederationClient(FederationBase):
         self._get_pdu_cache.start()
 
     @log_function
-    @metrics.counted
     def send_pdu(self, pdu, destinations):
         """Informs the replication layer about a new PDU generated within the
         home server that should be transmitted to others.
@@ -70,6 +77,8 @@ class FederationClient(FederationBase):
         order = self._order
         self._order += 1
 
+        sent_pdus_destination_dist.inc_by(len(destinations))
+
         logger.debug("[%s] transaction_layer.enqueue_pdu... ", pdu.event_id)
 
         # TODO, add errback, etc.
@@ -81,7 +90,6 @@ class FederationClient(FederationBase):
         )
 
     @log_function
-    @metrics.counted
     def send_edu(self, destination, edu_type, content):
         edu = Edu(
             origin=self.server_name,
@@ -90,18 +98,18 @@ class FederationClient(FederationBase):
             content=content,
         )
 
+        sent_edus_counter.inc()
+
         # TODO, add errback, etc.
         self._transaction_queue.enqueue_edu(edu)
         return defer.succeed(None)
 
     @log_function
-    @metrics.counted
     def send_failure(self, failure, destination):
         self._transaction_queue.enqueue_failure(failure, destination)
         return defer.succeed(None)
 
     @log_function
-    @metrics.counted
     def make_query(self, destination, query_type, args,
                    retry_on_dns_fail=True):
         """Sends a federation Query to a remote homeserver of the given type
@@ -118,6 +126,8 @@ class FederationClient(FederationBase):
             a Deferred which will eventually yield a JSON object from the
             response
         """
+        sent_queries_counter.inc(query_type)
+
         return self.transport_layer.make_query(
             destination, query_type, args, retry_on_dns_fail=retry_on_dns_fail
         )
@@ -163,7 +173,6 @@ class FederationClient(FederationBase):
 
     @defer.inlineCallbacks
     @log_function
-    @metrics.counted
     def get_pdu(self, destinations, event_id, outlier=False):
         """Requests the PDU with given origin and ID from the remote home
         servers.
@@ -253,7 +262,6 @@ class FederationClient(FederationBase):
 
     @defer.inlineCallbacks
     @log_function
-    @metrics.counted
     def get_state_for_room(self, destination, room_id, event_id):
         """Requests all of the `current` state PDUs for a given room from
         a remote home server.
@@ -294,7 +302,6 @@ class FederationClient(FederationBase):
 
     @defer.inlineCallbacks
     @log_function
-    @metrics.counted
     def get_event_auth(self, destination, room_id, event_id):
         res = yield self.transport_layer.get_event_auth(
             destination, room_id, event_id,
@@ -314,7 +321,6 @@ class FederationClient(FederationBase):
         defer.returnValue(signed_auth)
 
     @defer.inlineCallbacks
-    @metrics.counted
     def make_join(self, destinations, room_id, user_id):
         for destination in destinations:
             try:
@@ -341,7 +347,6 @@ class FederationClient(FederationBase):
         raise RuntimeError("Failed to send to any server.")
 
     @defer.inlineCallbacks
-    @metrics.counted
     def send_join(self, destinations, pdu):
         for destination in destinations:
             try:
@@ -391,7 +396,6 @@ class FederationClient(FederationBase):
         raise RuntimeError("Failed to send to any server.")
 
     @defer.inlineCallbacks
-    @metrics.counted
     def send_invite(self, destination, room_id, event_id, pdu):
         time_now = self._clock.time_msec()
         code, content = yield self.transport_layer.send_invite(
@@ -415,7 +419,6 @@ class FederationClient(FederationBase):
         defer.returnValue(pdu)
 
     @defer.inlineCallbacks
-    @metrics.counted
     def query_auth(self, destination, room_id, event_id, local_auth):
         """
         Params: