mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 20:03:53 +01:00
Merge pull request #5476 from matrix-org/erikj/histogram_extremities
Add metrics for length of new extremities persisted.
This commit is contained in:
commit
7456698241
3 changed files with 37 additions and 1 deletions
1
changelog.d/5476.misc
Normal file
1
changelog.d/5476.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Add new metrics for number of forward extremities being persisted and number of state groups involved in resolution.
|
|
@ -21,6 +21,7 @@ from six import iteritems, itervalues
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
from frozendict import frozendict
|
from frozendict import frozendict
|
||||||
|
from prometheus_client import Histogram
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
|
@ -37,6 +38,14 @@ from synapse.util.metrics import Measure
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# Metrics for number of state groups involved in a resolution.
|
||||||
|
state_groups_histogram = Histogram(
|
||||||
|
"synapse_state_number_state_groups_in_resolution",
|
||||||
|
"Number of state groups used when performing a state resolution",
|
||||||
|
buckets=(1, 2, 3, 5, 7, 10, 15, 20, 50, 100, 200, 500, "+Inf"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
KeyStateTuple = namedtuple("KeyStateTuple", ("context", "type", "state_key"))
|
KeyStateTuple = namedtuple("KeyStateTuple", ("context", "type", "state_key"))
|
||||||
|
|
||||||
|
|
||||||
|
@ -476,6 +485,8 @@ class StateResolutionHandler(object):
|
||||||
"Resolving state for %s with %d groups", room_id, len(state_groups_ids)
|
"Resolving state for %s with %d groups", room_id, len(state_groups_ids)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
state_groups_histogram.observe(len(state_groups_ids))
|
||||||
|
|
||||||
# start by assuming we won't have any conflicted state, and build up the new
|
# start by assuming we won't have any conflicted state, and build up the new
|
||||||
# state map by iterating through the state groups. If we discover a conflict,
|
# state map by iterating through the state groups. If we discover a conflict,
|
||||||
# we give up and instead use `resolve_events_with_store`.
|
# we give up and instead use `resolve_events_with_store`.
|
||||||
|
|
|
@ -24,7 +24,7 @@ from six import iteritems, text_type
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
from canonicaljson import json
|
from canonicaljson import json
|
||||||
from prometheus_client import Counter
|
from prometheus_client import Counter, Histogram
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
|
@ -74,6 +74,21 @@ state_delta_reuse_delta_counter = Counter(
|
||||||
"synapse_storage_events_state_delta_reuse_delta", ""
|
"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",
|
||||||
|
"Number of forward extremities for each new event",
|
||||||
|
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",
|
||||||
|
"Number of unchanged forward extremities for each new event",
|
||||||
|
buckets=(0, 1, 2, 3, 5, 7, 10, 15, 20, 50, 100, 200, 500, "+Inf"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def encode_json(json_object):
|
def encode_json(json_object):
|
||||||
"""
|
"""
|
||||||
|
@ -541,6 +556,8 @@ class EventsStore(
|
||||||
and not event.internal_metadata.is_soft_failed()
|
and not event.internal_metadata.is_soft_failed()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
latest_event_ids = set(latest_event_ids)
|
||||||
|
|
||||||
# start with the existing forward extremities
|
# start with the existing forward extremities
|
||||||
result = set(latest_event_ids)
|
result = set(latest_event_ids)
|
||||||
|
|
||||||
|
@ -564,6 +581,13 @@ class EventsStore(
|
||||||
)
|
)
|
||||||
result.difference_update(existing_prevs)
|
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 = latest_event_ids & result
|
||||||
|
stale_forward_extremities_counter.observe(len(stale))
|
||||||
|
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
Loading…
Reference in a new issue