summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-06-17 16:20:20 +0100
committerErik Johnston <erik@matrix.org>2019-06-17 17:02:48 +0100
commit499d4a32cda7bc26d82140d84a7279372c519538 (patch)
tree63aa1841d5bb67a58615a4f7defdef33c3936cda /synapse
parentMerge pull request #5385 from matrix-org/erikj/reduce_http_exceptions (diff)
downloadsynapse-499d4a32cda7bc26d82140d84a7279372c519538.tar.xz
Add metrics for len of new extremities persisted.
Of new events being persisted add metrics for total size of forward
extremities and number of unchanged, "stale" extremities.
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/events.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index f631fb1733..f2374bc3f4 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -24,7 +24,7 @@ from six import iteritems, text_type
 from six.moves import range
 
 from canonicaljson import json
-from prometheus_client import Counter
+from prometheus_client import Counter, Histogram
 
 from twisted.internet import defer
 
@@ -74,6 +74,19 @@ state_delta_reuse_delta_counter = Counter(
     "synapse_storage_events_state_delta_reuse_delta", ""
 )
 
+# The number of forward extremities for each new event.
+forward_extremities_counter = Histogram(
+    "synapse_storage_events_forward_extremities_persisted", "",
+    buckets=(1, 2, 3, 5, 7, 10, 15, 20, 50, 100, 200, 500, "+Inf")
+)
+
+# The number of stale forward extremities for each new event. Stale extremities
+# are those that were in the previous set of extremities as well as the new.
+stale_forward_extremities_counter = Histogram(
+    "synapse_storage_events_stale_forward_extremities_persisted", "",
+    buckets=(0, 1, 2, 3, 5, 7, 10, 15, 20, 50, 100, 200, 500, "+Inf")
+)
+
 
 def encode_json(json_object):
     """
@@ -541,6 +554,8 @@ class EventsStore(
             and not event.internal_metadata.is_soft_failed()
         ]
 
+        latest_event_ids = set(latest_event_ids)
+
         # start with the existing forward extremities
         result = set(latest_event_ids)
 
@@ -564,6 +579,13 @@ class EventsStore(
         )
         result.difference_update(existing_prevs)
 
+        # We only update metrics for events that change forward extremities
+        # (e.g. we ignore backfill/outliers/etc)
+        if result != latest_event_ids:
+            forward_extremities_counter.observe(len(result))
+            stale = set(latest_event_ids) & result
+            stale_forward_extremities_counter.observe(len(stale))
+
         defer.returnValue(result)
 
     @defer.inlineCallbacks