From 7e47987af21b26fdb8d85a624f7422b119ac4a4e Mon Sep 17 00:00:00 2001 From: Sorunome Date: Tue, 10 Sep 2019 18:54:48 +0200 Subject: [PATCH 1/4] add report_stats_endpoint config option --- docs/sample_config.yaml | 2 ++ synapse/app/homeserver.py | 13 +++++++++---- synapse/config/metrics.py | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index 9b1ae58a27fb..911b734a2d64 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -978,6 +978,8 @@ metrics_flags: # Whether or not to report anonymized homeserver usage statistics. # report_stats: true|false +# The endpoint where to report the anonymized homeserver usage statistics to. Defaults to matrix.org +# report_stats_endpoint: "https://matrix.org/report-usage-stats/push" ## API Configuration ## diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 04f1ed14f3c9..42daa003b459 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -561,11 +561,16 @@ def phone_stats_home(): stats["database_engine"] = hs.get_datastore().database_engine_name stats["database_server_version"] = hs.get_datastore().get_server_version() - logger.info("Reporting stats to matrix.org: %s" % (stats,)) + logger.info("Reporting stats: %s" % (stats,)) try: - yield hs.get_simple_http_client().put_json( - "https://matrix.org/report-usage-stats/push", stats - ) + if hs.config.report_stats_endpoint: + yield hs.get_simple_http_client().put_json( + hs.config.report_stats_endpoint, stats + ) + else: + yield hs.get_simple_http_client().put_json( + "https://matrix.org/report-usage-stats/push", stats + ) except Exception as e: logger.warn("Error reporting stats: %s", e) diff --git a/synapse/config/metrics.py b/synapse/config/metrics.py index 653b990e67d8..3703ed62e4f3 100644 --- a/synapse/config/metrics.py +++ b/synapse/config/metrics.py @@ -39,6 +39,7 @@ class MetricsConfig(Config): def read_config(self, config, **kwargs): self.enable_metrics = config.get("enable_metrics", False) self.report_stats = config.get("report_stats", None) + self.report_stats_endpoint = config.get("report_stats_endpoint", None) self.metrics_port = config.get("metrics_port") self.metrics_bind_host = config.get("metrics_bind_host", "127.0.0.1") From 52ca0aef34edc71ef41fcad56763a8831018e448 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Tue, 10 Sep 2019 19:03:56 +0200 Subject: [PATCH 2/4] add changelog entry --- changelog.d/6012.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6012.feature diff --git a/changelog.d/6012.feature b/changelog.d/6012.feature new file mode 100644 index 000000000000..fff5810d8485 --- /dev/null +++ b/changelog.d/6012.feature @@ -0,0 +1 @@ +Add report_stats_endpoint option to configure where stats are reported to, if enabled From 8e0d2f2c9d7638bb36cc8fc13593587eded0ba66 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Wed, 11 Sep 2019 14:21:48 +0200 Subject: [PATCH 3/4] improve things --- changelog.d/6012.feature | 2 +- docs/sample_config.yaml | 4 ++-- synapse/app/homeserver.py | 13 ++++--------- synapse/config/metrics.py | 6 +++++- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/changelog.d/6012.feature b/changelog.d/6012.feature index fff5810d8485..3248bd9ff970 100644 --- a/changelog.d/6012.feature +++ b/changelog.d/6012.feature @@ -1 +1 @@ -Add report_stats_endpoint option to configure where stats are reported to, if enabled +Add report_stats_endpoint option to configure where stats are reported to, if enabled. Contributed by @Sorunome diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index 911b734a2d64..eb950570c47e 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -978,8 +978,8 @@ metrics_flags: # Whether or not to report anonymized homeserver usage statistics. # report_stats: true|false -# The endpoint where to report the anonymized homeserver usage statistics to. Defaults to matrix.org -# report_stats_endpoint: "https://matrix.org/report-usage-stats/push" +# The endpoint to report the anonymized homeserver usage statistics to. +#report_stats_endpoint: https://matrix.org/report-usage-stats/push ## API Configuration ## diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 42daa003b459..a9eb04f537f4 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -561,16 +561,11 @@ def phone_stats_home(): stats["database_engine"] = hs.get_datastore().database_engine_name stats["database_server_version"] = hs.get_datastore().get_server_version() - logger.info("Reporting stats: %s" % (stats,)) + logger.info("Reporting stats to %s: %s" % (hs.config.report_stats_endpoint, stats)) try: - if hs.config.report_stats_endpoint: - yield hs.get_simple_http_client().put_json( - hs.config.report_stats_endpoint, stats - ) - else: - yield hs.get_simple_http_client().put_json( - "https://matrix.org/report-usage-stats/push", stats - ) + yield hs.get_simple_http_client().put_json( + hs.config.report_stats_endpoint, stats + ) except Exception as e: logger.warn("Error reporting stats: %s", e) diff --git a/synapse/config/metrics.py b/synapse/config/metrics.py index 3703ed62e4f3..e75904e5eacc 100644 --- a/synapse/config/metrics.py +++ b/synapse/config/metrics.py @@ -39,7 +39,7 @@ class MetricsConfig(Config): def read_config(self, config, **kwargs): self.enable_metrics = config.get("enable_metrics", False) self.report_stats = config.get("report_stats", None) - self.report_stats_endpoint = config.get("report_stats_endpoint", None) + self.report_stats_endpoint = config.get("report_stats_endpoint", "https://matrix.org/report-usage-stats/push") self.metrics_port = config.get("metrics_port") self.metrics_bind_host = config.get("metrics_bind_host", "127.0.0.1") @@ -98,4 +98,8 @@ def generate_config_section(self, report_stats=None, **kwargs): else: res += "report_stats: %s\n" % ("true" if report_stats else "false") + res += """\ + # The endpoint to report the anonymized homeserver usage statistics to. + #report_stats_endpoint: https://example.com/report-usage-stats/push + """ return res From c1f2fe7f8d36e505f511dfe32a03a94922e3f8f9 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Wed, 11 Sep 2019 15:57:22 +0200 Subject: [PATCH 4/4] Hopefully fix formatting properly --- changelog.d/6012.feature | 2 +- docs/sample_config.yaml | 5 ++++- synapse/app/homeserver.py | 4 +++- synapse/config/metrics.py | 8 ++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/changelog.d/6012.feature b/changelog.d/6012.feature index 3248bd9ff970..25425510c6db 100644 --- a/changelog.d/6012.feature +++ b/changelog.d/6012.feature @@ -1 +1 @@ -Add report_stats_endpoint option to configure where stats are reported to, if enabled. Contributed by @Sorunome +Add report_stats_endpoint option to configure where stats are reported to, if enabled. Contributed by @Sorunome. diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index eb950570c47e..bee854d807f4 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -979,7 +979,10 @@ metrics_flags: # report_stats: true|false # The endpoint to report the anonymized homeserver usage statistics to. -#report_stats_endpoint: https://matrix.org/report-usage-stats/push +# Defaults to https://matrix.org/report-usage-stats/push +# +#report_stats_endpoint: https://example.com/report-usage-stats/push + ## API Configuration ## diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index a9eb04f537f4..774326dff9ec 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -561,7 +561,9 @@ def phone_stats_home(): stats["database_engine"] = hs.get_datastore().database_engine_name stats["database_server_version"] = hs.get_datastore().get_server_version() - logger.info("Reporting stats to %s: %s" % (hs.config.report_stats_endpoint, stats)) + logger.info( + "Reporting stats to %s: %s" % (hs.config.report_stats_endpoint, stats) + ) try: yield hs.get_simple_http_client().put_json( hs.config.report_stats_endpoint, stats diff --git a/synapse/config/metrics.py b/synapse/config/metrics.py index e75904e5eacc..d9dfda0bbaf7 100644 --- a/synapse/config/metrics.py +++ b/synapse/config/metrics.py @@ -39,7 +39,9 @@ class MetricsConfig(Config): def read_config(self, config, **kwargs): self.enable_metrics = config.get("enable_metrics", False) self.report_stats = config.get("report_stats", None) - self.report_stats_endpoint = config.get("report_stats_endpoint", "https://matrix.org/report-usage-stats/push") + self.report_stats_endpoint = config.get( + "report_stats_endpoint", "https://matrix.org/report-usage-stats/push" + ) self.metrics_port = config.get("metrics_port") self.metrics_bind_host = config.get("metrics_bind_host", "127.0.0.1") @@ -98,8 +100,10 @@ def generate_config_section(self, report_stats=None, **kwargs): else: res += "report_stats: %s\n" % ("true" if report_stats else "false") - res += """\ + res += """ # The endpoint to report the anonymized homeserver usage statistics to. + # Defaults to https://matrix.org/report-usage-stats/push + # #report_stats_endpoint: https://example.com/report-usage-stats/push """ return res