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

Commit 6e834e9

Browse files
authored
Fix and refactor room and user stats (#5971)
Previously the stats were not being correctly populated.
1 parent ea128a3 commit 6e834e9

File tree

11 files changed

+1642
-641
lines changed

11 files changed

+1642
-641
lines changed

changelog.d/5971.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix room and user stats tracking.

docs/room_and_user_statistics.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Room and User Statistics
2+
========================
3+
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.
7+
8+
9+
# Synapse Developer Documentation
10+
11+
## High-Level Concepts
12+
13+
### Definitions
14+
15+
* **subject**: Something we are tracking stats about – currently a room or user.
16+
* **current row**: An entry for a subject in the appropriate current statistics
17+
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.
20+
21+
### Overview
22+
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.

synapse/config/stats.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,16 @@ class StatsConfig(Config):
2727

2828
def read_config(self, config, **kwargs):
2929
self.stats_enabled = True
30-
self.stats_bucket_size = 86400
30+
self.stats_bucket_size = 86400 * 1000
3131
self.stats_retention = sys.maxsize
3232
stats_config = config.get("stats", None)
3333
if stats_config:
3434
self.stats_enabled = stats_config.get("enabled", self.stats_enabled)
35-
self.stats_bucket_size = (
36-
self.parse_duration(stats_config.get("bucket_size", "1d")) / 1000
35+
self.stats_bucket_size = self.parse_duration(
36+
stats_config.get("bucket_size", "1d")
3737
)
38-
self.stats_retention = (
39-
self.parse_duration(
40-
stats_config.get("retention", "%ds" % (sys.maxsize,))
41-
)
42-
/ 1000
38+
self.stats_retention = self.parse_duration(
39+
stats_config.get("retention", "%ds" % (sys.maxsize,))
4340
)
4441

4542
def generate_config_section(self, config_dir_path, server_name, **kwargs):

0 commit comments

Comments
 (0)