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

Commit 4a30e4a

Browse files
authored
Room Statistics (#4338)
1 parent f4c80d7 commit 4a30e4a

File tree

15 files changed

+1306
-13
lines changed

15 files changed

+1306
-13
lines changed

changelog.d/4338.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Synapse now more efficiently collates room statistics.

docs/sample_config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,22 @@ password_config:
11531153
#
11541154

11551155

1156+
1157+
# Local statistics collection. Used in populating the room directory.
1158+
#
1159+
# 'bucket_size' controls how large each statistics timeslice is. It can
1160+
# be defined in a human readable short form -- e.g. "1d", "1y".
1161+
#
1162+
# 'retention' controls how long historical statistics will be kept for.
1163+
# It can be defined in a human readable short form -- e.g. "1d", "1y".
1164+
#
1165+
#
1166+
#stats:
1167+
# enabled: true
1168+
# bucket_size: 1d
1169+
# retention: 1y
1170+
1171+
11561172
# Server Notices room configuration
11571173
#
11581174
# Uncomment this section to enable a room which can be used to send notices

synapse/api/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class EventTypes(object):
7979

8080
RoomHistoryVisibility = "m.room.history_visibility"
8181
CanonicalAlias = "m.room.canonical_alias"
82+
Encryption = "m.room.encryption"
8283
RoomAvatar = "m.room.avatar"
8384
RoomEncryption = "m.room.encryption"
8485
GuestAccess = "m.room.guest_access"

synapse/config/homeserver.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16+
1617
from .api import ApiConfig
1718
from .appservice import AppServiceConfig
1819
from .captcha import CaptchaConfig
@@ -36,20 +37,41 @@
3637
from .server import ServerConfig
3738
from .server_notices_config import ServerNoticesConfig
3839
from .spam_checker import SpamCheckerConfig
40+
from .stats import StatsConfig
3941
from .tls import TlsConfig
4042
from .user_directory import UserDirectoryConfig
4143
from .voip import VoipConfig
4244
from .workers import WorkerConfig
4345

4446

45-
class HomeServerConfig(ServerConfig, TlsConfig, DatabaseConfig, LoggingConfig,
46-
RatelimitConfig, ContentRepositoryConfig, CaptchaConfig,
47-
VoipConfig, RegistrationConfig, MetricsConfig, ApiConfig,
48-
AppServiceConfig, KeyConfig, SAML2Config, CasConfig,
49-
JWTConfig, PasswordConfig, EmailConfig,
50-
WorkerConfig, PasswordAuthProviderConfig, PushConfig,
51-
SpamCheckerConfig, GroupsConfig, UserDirectoryConfig,
52-
ConsentConfig,
53-
ServerNoticesConfig, RoomDirectoryConfig,
54-
):
47+
class HomeServerConfig(
48+
ServerConfig,
49+
TlsConfig,
50+
DatabaseConfig,
51+
LoggingConfig,
52+
RatelimitConfig,
53+
ContentRepositoryConfig,
54+
CaptchaConfig,
55+
VoipConfig,
56+
RegistrationConfig,
57+
MetricsConfig,
58+
ApiConfig,
59+
AppServiceConfig,
60+
KeyConfig,
61+
SAML2Config,
62+
CasConfig,
63+
JWTConfig,
64+
PasswordConfig,
65+
EmailConfig,
66+
WorkerConfig,
67+
PasswordAuthProviderConfig,
68+
PushConfig,
69+
SpamCheckerConfig,
70+
GroupsConfig,
71+
UserDirectoryConfig,
72+
ConsentConfig,
73+
StatsConfig,
74+
ServerNoticesConfig,
75+
RoomDirectoryConfig,
76+
):
5577
pass

synapse/config/stats.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2018 New Vector Ltd
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from __future__ import division
17+
18+
import sys
19+
20+
from ._base import Config
21+
22+
23+
class StatsConfig(Config):
24+
"""Stats Configuration
25+
Configuration for the behaviour of synapse's stats engine
26+
"""
27+
28+
def read_config(self, config):
29+
self.stats_enabled = True
30+
self.stats_bucket_size = 86400
31+
self.stats_retention = sys.maxsize
32+
stats_config = config.get("stats", None)
33+
if stats_config:
34+
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
37+
)
38+
self.stats_retention = (
39+
self.parse_duration(
40+
stats_config.get("retention", "%ds" % (sys.maxsize,))
41+
)
42+
/ 1000
43+
)
44+
45+
def default_config(self, config_dir_path, server_name, **kwargs):
46+
return """
47+
# Local statistics collection. Used in populating the room directory.
48+
#
49+
# 'bucket_size' controls how large each statistics timeslice is. It can
50+
# be defined in a human readable short form -- e.g. "1d", "1y".
51+
#
52+
# 'retention' controls how long historical statistics will be kept for.
53+
# It can be defined in a human readable short form -- e.g. "1d", "1y".
54+
#
55+
#
56+
#stats:
57+
# enabled: true
58+
# bucket_size: 1d
59+
# retention: 1y
60+
"""

0 commit comments

Comments
 (0)