Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit f6767ab

Browse files
authored
Remove functionality associated with unused historical stats tables (#9721)
Fixes #9602
1 parent aa78064 commit f6767ab

File tree

10 files changed

+22
-572
lines changed

10 files changed

+22
-572
lines changed

changelog.d/9721.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove functionality associated with the unused `room_stats_historical` and `user_stats_historical` tables. Contributed by @xmunoz.

docs/room_and_user_statistics.md

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Room and User Statistics
22
========================
33

4-
Synapse maintains room and user statistics (as well as a cache of room state),
5-
in various tables. These can be used for administrative purposes but are also
6-
used when generating the public room directory.
4+
Synapse maintains room and user statistics in various tables. These can be used
5+
for administrative purposes but are also used when generating the public room
6+
directory.
77

88

99
# Synapse Developer Documentation
@@ -15,48 +15,8 @@ used when generating the public room directory.
1515
* **subject**: Something we are tracking stats about – currently a room or user.
1616
* **current row**: An entry for a subject in the appropriate current statistics
1717
table. Each subject can have only one.
18-
* **historical row**: An entry for a subject in the appropriate historical
19-
statistics table. Each subject can have any number of these.
2018

2119
### Overview
2220

23-
Stats are maintained as time series. There are two kinds of column:
24-
25-
* absolute columns – where the value is correct for the time given by `end_ts`
26-
in the stats row. (Imagine a line graph for these values)
27-
* They can also be thought of as 'gauges' in Prometheus, if you are familiar.
28-
* per-slice columns – where the value corresponds to how many of the occurrences
29-
occurred within the time slice given by `(end_ts − bucket_size)…end_ts`
30-
or `start_ts…end_ts`. (Imagine a histogram for these values)
31-
32-
Stats are maintained in two tables (for each type): current and historical.
33-
34-
Current stats correspond to the present values. Each subject can only have one
35-
entry.
36-
37-
Historical stats correspond to values in the past. Subjects may have multiple
38-
entries.
39-
40-
## Concepts around the management of stats
41-
42-
### Current rows
43-
44-
Current rows contain the most up-to-date statistics for a room.
45-
They only contain absolute columns
46-
47-
### Historical rows
48-
49-
Historical rows can always be considered to be valid for the time slice and
50-
end time specified.
51-
52-
* historical rows will not exist for every time slice – they will be omitted
53-
if there were no changes. In this case, the following assumptions can be
54-
made to interpolate/recreate missing rows:
55-
- absolute fields have the same values as in the preceding row
56-
- per-slice fields are zero (`0`)
57-
* historical rows will not be retained forever – rows older than a configurable
58-
time will be purged.
59-
60-
#### Purge
61-
62-
The purging of historical rows is not yet implemented.
21+
Stats correspond to the present values. Current rows contain the most up-to-date
22+
statistics for a room. Each subject can only have one entry.

docs/sample_config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,11 +2652,6 @@ stats:
26522652
#
26532653
#enabled: false
26542654

2655-
# The size of each timeslice in the room_stats_historical and
2656-
# user_stats_historical tables, as a time period. Defaults to "1d".
2657-
#
2658-
#bucket_size: 1h
2659-
26602655

26612656
# Server Notices room configuration
26622657
#

synapse/config/stats.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@ class StatsConfig(Config):
3838

3939
def read_config(self, config, **kwargs):
4040
self.stats_enabled = True
41-
self.stats_bucket_size = 86400 * 1000
4241
stats_config = config.get("stats", None)
4342
if stats_config:
4443
self.stats_enabled = stats_config.get("enabled", self.stats_enabled)
45-
self.stats_bucket_size = self.parse_duration(
46-
stats_config.get("bucket_size", "1d")
47-
)
4844
if not self.stats_enabled:
4945
logger.warning(ROOM_STATS_DISABLED_WARN)
5046

@@ -59,9 +55,4 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
5955
# correctly.
6056
#
6157
#enabled: false
62-
63-
# The size of each timeslice in the room_stats_historical and
64-
# user_stats_historical tables, as a time period. Defaults to "1d".
65-
#
66-
#bucket_size: 1h
6758
"""

synapse/handlers/stats.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def __init__(self, hs: "HomeServer"):
4545
self.clock = hs.get_clock()
4646
self.notifier = hs.get_notifier()
4747
self.is_mine_id = hs.is_mine_id
48-
self.stats_bucket_size = hs.config.stats_bucket_size
4948

5049
self.stats_enabled = hs.config.stats_enabled
5150

@@ -106,20 +105,6 @@ async def _unsafe_process(self) -> None:
106105
room_deltas = {}
107106
user_deltas = {}
108107

109-
# Then count deltas for total_events and total_event_bytes.
110-
(
111-
room_count,
112-
user_count,
113-
) = await self.store.get_changes_room_total_events_and_bytes(
114-
self.pos, max_pos
115-
)
116-
117-
for room_id, fields in room_count.items():
118-
room_deltas.setdefault(room_id, Counter()).update(fields)
119-
120-
for user_id, fields in user_count.items():
121-
user_deltas.setdefault(user_id, Counter()).update(fields)
122-
123108
logger.debug("room_deltas: %s", room_deltas)
124109
logger.debug("user_deltas: %s", user_deltas)
125110

@@ -181,12 +166,10 @@ async def _handle_deltas(
181166

182167
event_content = {} # type: JsonDict
183168

184-
sender = None
185169
if event_id is not None:
186170
event = await self.store.get_event(event_id, allow_none=True)
187171
if event:
188172
event_content = event.content or {}
189-
sender = event.sender
190173

191174
# All the values in this dict are deltas (RELATIVE changes)
192175
room_stats_delta = room_to_stats_deltas.setdefault(room_id, Counter())
@@ -244,12 +227,6 @@ async def _handle_deltas(
244227
room_stats_delta["joined_members"] += 1
245228
elif membership == Membership.INVITE:
246229
room_stats_delta["invited_members"] += 1
247-
248-
if sender and self.is_mine_id(sender):
249-
user_to_stats_deltas.setdefault(sender, Counter())[
250-
"invites_sent"
251-
] += 1
252-
253230
elif membership == Membership.LEAVE:
254231
room_stats_delta["left_members"] += 1
255232
elif membership == Membership.BAN:
@@ -279,10 +256,6 @@ async def _handle_deltas(
279256
room_state["is_federatable"] = (
280257
event_content.get("m.federate", True) is True
281258
)
282-
if sender and self.is_mine_id(sender):
283-
user_to_stats_deltas.setdefault(sender, Counter())[
284-
"rooms_created"
285-
] += 1
286259
elif typ == EventTypes.JoinRules:
287260
room_state["join_rules"] = event_content.get("join_rule")
288261
elif typ == EventTypes.RoomHistoryVisibility:

synapse/storage/databases/main/purge_events.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ def _purge_room_txn(self, txn, room_id: str) -> List[int]:
392392
"room_memberships",
393393
"room_stats_state",
394394
"room_stats_current",
395-
"room_stats_historical",
396395
"room_stats_earliest_token",
397396
"rooms",
398397
"stream_ordering_to_exterm",

0 commit comments

Comments
 (0)