From ffbdb9f2beb34ee0ca6bd1dbde23fb384bddab1b Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 7 May 2025 17:27:47 -0500 Subject: [PATCH 1/5] Move specific Synapse config out of `RootConfig` --- synapse/config/_base.py | 29 ----------------------------- synapse/config/metrics.py | 27 ++++++++++++++++++++++++++- synapse/config/server.py | 12 +++++++++++- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index 132ba26af90..f746c8c5a10 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -101,28 +101,6 @@ def format_config_error(e: ConfigError) -> Iterator[str]: parent_e = parent_e.__cause__ -# We split these messages out to allow packages to override with package -# specific instructions. -MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS = """\ -Please opt in or out of reporting homeserver usage statistics, by setting -the `report_stats` key in your config file to either True or False. -""" - -MISSING_REPORT_STATS_SPIEL = """\ -We would really appreciate it if you could help our project out by reporting -homeserver usage statistics from your homeserver. Your homeserver's server name, -along with very basic aggregate data (e.g. number of users) will be reported. But -it helps us to track the growth of the Matrix community, and helps us to make Matrix -a success, as well as to convince other networks that they should peer with us. - -Thank you. -""" - -MISSING_SERVER_NAME = """\ -Missing mandatory `server_name` config option. -""" - - CONFIG_FILE_HEADER = """\ # Configuration file for Synapse. # @@ -929,13 +907,6 @@ def read_config_files(config_files: Iterable[str]) -> Dict[str, Any]: specified_config.update(yaml_config) - if "server_name" not in specified_config: - raise ConfigError(MISSING_SERVER_NAME) - - if "report_stats" not in specified_config: - raise ConfigError( - MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS + "\n" + MISSING_REPORT_STATS_SPIEL - ) return specified_config diff --git a/synapse/config/metrics.py b/synapse/config/metrics.py index 8a4ded62efd..fba2ce8ad29 100644 --- a/synapse/config/metrics.py +++ b/synapse/config/metrics.py @@ -29,6 +29,21 @@ from ._base import Config, ConfigError +MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS = """\ +Please opt in or out of reporting homeserver usage statistics, by setting +the `report_stats` key in your config file to either True or False. +""" + +MISSING_REPORT_STATS_SPIEL = """\ +We would really appreciate it if you could help our project out by reporting +homeserver usage statistics from your homeserver. Your homeserver's server name, +along with very basic aggregate data (e.g. number of users) will be reported. But +it helps us to track the growth of the Matrix community, and helps us to make Matrix +a success, as well as to convince other networks that they should peer with us. + +Thank you. +""" + @attr.s class MetricsFlags: @@ -50,7 +65,17 @@ class MetricsConfig(Config): def read_config(self, config: JsonDict, **kwargs: Any) -> None: self.enable_metrics = config.get("enable_metrics", False) - self.report_stats = config.get("report_stats", None) + report_stats = config.get("report_stats", None) + + if report_stats is None: + raise ConfigError( + MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS + + "\n" + + MISSING_REPORT_STATS_SPIEL, + ("report_stats",), + ) + + self.report_stats = report_stats self.report_stats_endpoint = config.get( "report_stats_endpoint", "https://matrix.org/report-usage-stats/push" ) diff --git a/synapse/config/server.py b/synapse/config/server.py index 6b299836176..9b2deb48cca 100644 --- a/synapse/config/server.py +++ b/synapse/config/server.py @@ -49,6 +49,11 @@ Please see https://element-hq.github.io/synapse/latest/upgrade.html#direct-tcp-replication-is-no-longer-supported-migrate-to-redis """ + +MISSING_SERVER_NAME = """\ +Missing mandatory `server_name` config option. +""" + # by default, we attempt to listen on both '::' *and* '0.0.0.0' because some OSes # (Windows, macOS, other BSD/Linux where net.ipv6.bindv6only is set) will only listen # on IPv6 when '::' is set. @@ -295,9 +300,14 @@ class ServerConfig(Config): section = "server" def read_config(self, config: JsonDict, **kwargs: Any) -> None: - self.server_name = config["server_name"] self.server_context = config.get("server_context", None) + server_name = config.get("server_name") + if server_name is None: + raise ConfigError(MISSING_SERVER_NAME, ("server_name",)) + + self.server_name = server_name + try: parse_and_validate_server_name(self.server_name) except ValueError as e: From 83458c2b339b170ab8fda584442a2afef19222b5 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 7 May 2025 17:33:19 -0500 Subject: [PATCH 2/5] Add changelog --- changelog.d/18410.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/18410.misc diff --git a/changelog.d/18410.misc b/changelog.d/18410.misc new file mode 100644 index 00000000000..c1c2b000636 --- /dev/null +++ b/changelog.d/18410.misc @@ -0,0 +1 @@ +Move specific Synapse config out of `RootConfig`. From b86a878db2284a8ee67363530f0666f268eec741 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 14 May 2025 15:39:22 -0500 Subject: [PATCH 3/5] Fix lints --- synapse/config/_base.py | 10 ++++++++++ synapse/config/metrics.py | 12 +----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index 25458d3230d..71400d4729d 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -54,6 +54,16 @@ logger = logging.getLogger(__name__) +MISSING_REPORT_STATS_SPIEL = """\ +We would really appreciate it if you could help our project out by reporting +homeserver usage statistics from your homeserver. Your homeserver's server name, +along with very basic aggregate data (e.g. number of users) will be reported. But +it helps us to track the growth of the Matrix community, and helps us to make Matrix +a success, as well as to convince other networks that they should peer with us. + +Thank you. +""" + class ConfigError(Exception): """Represents a problem parsing the configuration diff --git a/synapse/config/metrics.py b/synapse/config/metrics.py index fba2ce8ad29..96465620e5f 100644 --- a/synapse/config/metrics.py +++ b/synapse/config/metrics.py @@ -27,23 +27,13 @@ from synapse.types import JsonDict from synapse.util.check_dependencies import check_requirements -from ._base import Config, ConfigError +from ._base import MISSING_REPORT_STATS_SPIEL, Config, ConfigError MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS = """\ Please opt in or out of reporting homeserver usage statistics, by setting the `report_stats` key in your config file to either True or False. """ -MISSING_REPORT_STATS_SPIEL = """\ -We would really appreciate it if you could help our project out by reporting -homeserver usage statistics from your homeserver. Your homeserver's server name, -along with very basic aggregate data (e.g. number of users) will be reported. But -it helps us to track the growth of the Matrix community, and helps us to make Matrix -a success, as well as to convince other networks that they should peer with us. - -Thank you. -""" - @attr.s class MetricsFlags: From f871dcb1162162b2cdd91635bf6e437b45cbc2e8 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 14 May 2025 15:40:29 -0500 Subject: [PATCH 4/5] Move back to original position --- synapse/config/_base.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index 71400d4729d..0d22ba441b0 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -54,16 +54,6 @@ logger = logging.getLogger(__name__) -MISSING_REPORT_STATS_SPIEL = """\ -We would really appreciate it if you could help our project out by reporting -homeserver usage statistics from your homeserver. Your homeserver's server name, -along with very basic aggregate data (e.g. number of users) will be reported. But -it helps us to track the growth of the Matrix community, and helps us to make Matrix -a success, as well as to convince other networks that they should peer with us. - -Thank you. -""" - class ConfigError(Exception): """Represents a problem parsing the configuration @@ -111,6 +101,16 @@ def format_config_error(e: ConfigError) -> Iterator[str]: parent_e = parent_e.__cause__ +MISSING_REPORT_STATS_SPIEL = """\ +We would really appreciate it if you could help our project out by reporting +homeserver usage statistics from your homeserver. Your homeserver's server name, +along with very basic aggregate data (e.g. number of users) will be reported. But +it helps us to track the growth of the Matrix community, and helps us to make Matrix +a success, as well as to convince other networks that they should peer with us. + +Thank you. +""" + CONFIG_FILE_HEADER = """\ # Configuration file for Synapse. # From cbd49b072af5a2ac51f2cd98ab26103c9401943e Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 14 May 2025 16:27:32 -0500 Subject: [PATCH 5/5] More specific changelog --- changelog.d/18410.misc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/18410.misc b/changelog.d/18410.misc index c1c2b000636..31aca65f3b1 100644 --- a/changelog.d/18410.misc +++ b/changelog.d/18410.misc @@ -1 +1 @@ -Move specific Synapse config out of `RootConfig`. +Move Synapse specific config out of `RootConfig` for the load/read config flow (not config generation).