diff options
author | Matthew Hodgson <matthew@matrix.org> | 2018-07-18 09:52:28 +0100 |
---|---|---|
committer | Matthew Hodgson <matthew@matrix.org> | 2018-07-18 09:52:28 +0100 |
commit | c82785f5cb7ff277e0b66847add79f0b36584e4c (patch) | |
tree | babb7ef62a0392a296006f89df1a576d774228d0 | |
parent | WIP of tracking per-room and per-user stats (diff) | |
download | synapse-c82785f5cb7ff277e0b66847add79f0b36584e4c.tar.xz |
flake8
-rw-r--r-- | synapse/config/stats.py | 13 | ||||
-rw-r--r-- | synapse/handlers/stats.py | 41 | ||||
-rw-r--r-- | synapse/storage/events.py | 3 | ||||
-rw-r--r-- | synapse/storage/state_deltas.py | 9 | ||||
-rw-r--r-- | synapse/storage/stats.py | 14 | ||||
-rw-r--r-- | synapse/storage/user_directory.py | 2 |
6 files changed, 35 insertions, 47 deletions
diff --git a/synapse/config/stats.py b/synapse/config/stats.py index d0f4578a05..d03df66209 100644 --- a/synapse/config/stats.py +++ b/synapse/config/stats.py @@ -15,6 +15,8 @@ from ._base import Config +import sys + class StatsConfig(Config): """Stats Configuration @@ -24,16 +26,21 @@ class StatsConfig(Config): def read_config(self, config): self.stats_enable = False self.stats_bucket_size = 86400 + self.stats_retention = sys.maxint stats_config = config.get("stats", None) - if stats: + if stats_config: self.stats_enable = stats_config.get("enable", self.stats_enable) - self.stats_bucket_size = stats_config.get("enable", self.stats_bucket_size) + self.stats_bucket_size = stats_config.get( + "bucket_size", self.stats_bucket_size + ) + self.stats_retention = stats_config.get("retention", self.stats_retention) def default_config(self, config_dir_path, server_name, **kwargs): return """ # Stats configuration # # stats: - # enable: true + # enable: false # bucket_size: 86400 # 1 day + # retention: 31536000 # 1 year """ diff --git a/synapse/handlers/stats.py b/synapse/handlers/stats.py index 9d4e1b6f6e..baeb6311b9 100644 --- a/synapse/handlers/stats.py +++ b/synapse/handlers/stats.py @@ -15,12 +15,9 @@ import logging -from six import iteritems - from twisted.internet import defer -from synapse.api.constants import EventTypes, JoinRules, Membership -from synapse.storage.roommember import ProfileInfo +from synapse.api.constants import EventTypes, Membership from synapse.types import get_localpart_from_id from synapse.util.metrics import Measure @@ -124,6 +121,7 @@ class StatsHandler(object): logger.info("Processed all rooms.") + num_processed_users = 0 user_ids = yield self.store.get_all_local_users() logger.info("Doing initial update user_stats. %d users", len(user_ids)) for user_id in user_ids: @@ -169,19 +167,19 @@ class StatsHandler(object): room_id, { "join_rules": join_rules.content.get("join_rule") - if join_rules else None, + if join_rules else None, "history_visibility": history_visibility.content.get("history_visibility") - if history_visibility else None, + if history_visibility else None, "encryption": encryption.content.get("algorithm") - if encryption else None, + if encryption else None, "name": name.content.get("name") - if name else None, + if name else None, "topic": name.content.get("topic") - if canonical_alias else None, + if topic else None, "avatar": name.content.get("url") - if avatar else None, + if avatar else None, "canonical_alias": name.content.get("alias") - if canonical_alias else None, + if canonical_alias else None, } ) @@ -191,11 +189,19 @@ class StatsHandler(object): now = int(now / (self.stats_bucket_size * 1000)) * self.stats_bucket_size * 1000 current_state_events = len(current_state_ids) - joined_members = yield self.store.get_user_count_in_room(room_id, Membership.JOIN) - invited_members = yield self.store.get_user_count_in_room(room_id, Membership.INVITE) - left_members = yield self.store.get_user_count_in_room(room_id, Membership.LEAVE) - banned_members = yield self.store.get_user_count_in_room(room_id, Membership.BAN) - state_events = yield self.store.get_state_event_counts(room_id) + joined_members = yield self.store.get_user_count_in_room( + room_id, Membership.JOIN + ) + invited_members = yield self.store.get_user_count_in_room( + room_id, Membership.INVITE + ) + left_members = yield self.store.get_user_count_in_room( + room_id, Membership.LEAVE + ) + banned_members = yield self.store.get_user_count_in_room( + room_id, Membership.BAN + ) + state_events = yield self.store.get_state_event_counts(room_id) (local_events, remote_events) = yield self.store.get_event_counts( room_id, self.server_name ) @@ -231,8 +237,6 @@ class StatsHandler(object): logger.debug("Handling: %r %r, %s", typ, state_key, event_id) - - @defer.inlineCallbacks def _handle_local_user(self, user_id): """Adds a new local roomless user into the user_directory_search table. @@ -246,4 +250,3 @@ class StatsHandler(object): row = yield self.store.get_user_in_directory(user_id) if not row: yield self.store.add_profiles_to_user_dir(None, {user_id: profile}) - diff --git a/synapse/storage/events.py b/synapse/storage/events.py index 42f3fad613..2ca02cab0e 100644 --- a/synapse/storage/events.py +++ b/synapse/storage/events.py @@ -1817,7 +1817,7 @@ class EventsStore(EventsWorkerStore): " FROM state_events" " WHERE room_id=?" ) - txn.execute(sql, (local_server, room_id,)) + txn.execute(sql, (room_id,)) row = txn.fetchone() return row[0] if row else 0 @@ -1844,7 +1844,6 @@ class EventsStore(EventsWorkerStore): return self.runInteraction("get_event_counts", f) - def purge_history( self, room_id, token, delete_local_events, ): diff --git a/synapse/storage/state_deltas.py b/synapse/storage/state_deltas.py index b733e68c45..b13fcc0eb4 100644 --- a/synapse/storage/state_deltas.py +++ b/synapse/storage/state_deltas.py @@ -14,17 +14,9 @@ # limitations under the License. import logging -import re - -from six import iteritems from twisted.internet import defer -from synapse.api.constants import EventTypes, JoinRules -from synapse.storage.engines import PostgresEngine, Sqlite3Engine -from synapse.types import get_domain_from_id, get_localpart_from_id -from synapse.util.caches.descriptors import cached, cachedInlineCallbacks - from ._base import SQLBaseStore logger = logging.getLogger(__name__) @@ -104,4 +96,3 @@ class StateDeltasStore(SQLBaseStore): retcol="COALESCE(MAX(stream_id), -1)", desc="get_max_stream_id_in_current_state_deltas", ) - diff --git a/synapse/storage/stats.py b/synapse/storage/stats.py index 8b40312eb1..12e75b6753 100644 --- a/synapse/storage/stats.py +++ b/synapse/storage/stats.py @@ -14,18 +14,8 @@ # limitations under the License. import logging -import re -from six import iteritems - -from twisted.internet import defer - -from synapse.api.constants import EventTypes, JoinRules -from synapse.storage.engines import PostgresEngine, Sqlite3Engine -from synapse.types import get_domain_from_id, get_localpart_from_id -from synapse.util.caches.descriptors import cached, cachedInlineCallbacks - -from ._base import SQLBaseStore +from .StateDeltasStore import StateDeltasStore logger = logging.getLogger(__name__) @@ -47,5 +37,3 @@ class StatsStore(StateDeltasStore): updatevalues={"stream_id": stream_id}, desc="update_stats_stream_pos", ) - - def update_room_state(self, ) \ No newline at end of file diff --git a/synapse/storage/user_directory.py b/synapse/storage/user_directory.py index b3b821fc0f..6b3ed10cca 100644 --- a/synapse/storage/user_directory.py +++ b/synapse/storage/user_directory.py @@ -25,7 +25,7 @@ from synapse.storage.engines import PostgresEngine, Sqlite3Engine from synapse.types import get_domain_from_id, get_localpart_from_id from synapse.util.caches.descriptors import cached, cachedInlineCallbacks -from ._base import SQLBaseStore +from .StateDeltasStore import StateDeltasStore logger = logging.getLogger(__name__) |