From 21a65416a25b97bac3714478d97f53b5ab27311f Mon Sep 17 00:00:00 2001 From: Remi Rampin Date: Thu, 1 Feb 2024 11:10:03 -0500 Subject: [PATCH 1/2] Add metric for emails sent --- synapse/push/mailer.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/synapse/push/mailer.py b/synapse/push/mailer.py index 60161e86f2c..b4bd88f308d 100644 --- a/synapse/push/mailer.py +++ b/synapse/push/mailer.py @@ -26,6 +26,7 @@ import bleach import jinja2 from markupsafe import Markup +from prometheus_client import Counter from synapse.api.constants import EventTypes, Membership, RoomTypes from synapse.api.errors import StoreError @@ -56,6 +57,12 @@ T = TypeVar("T") +emails_sent_counter = Counter( + "synapse_emails_sent_total", + "Emails sent by type", + ["type"], +) + CONTEXT_BEFORE = 1 CONTEXT_AFTER = 1 @@ -130,6 +137,8 @@ def __init__( logger.info("Created Mailer for app_name %s" % app_name) + emails_sent_counter.labels("password_reset") + async def send_password_reset_mail( self, email_address: str, token: str, client_secret: str, sid: str ) -> None: @@ -153,6 +162,8 @@ async def send_password_reset_mail( template_vars: TemplateVars = {"link": link} + emails_sent_counter.labels("password_reset").inc() + await self.send_email( email_address, self.email_subjects.password_reset @@ -160,6 +171,8 @@ async def send_password_reset_mail( template_vars, ) + emails_sent_counter.labels("registration") + async def send_registration_mail( self, email_address: str, token: str, client_secret: str, sid: str ) -> None: @@ -183,6 +196,8 @@ async def send_registration_mail( template_vars: TemplateVars = {"link": link} + emails_sent_counter.labels("registration").inc() + await self.send_email( email_address, self.email_subjects.email_validation @@ -190,6 +205,8 @@ async def send_registration_mail( template_vars, ) + emails_sent_counter.labels("add_threepid") + async def send_add_threepid_mail( self, email_address: str, token: str, client_secret: str, sid: str ) -> None: @@ -214,6 +231,8 @@ async def send_add_threepid_mail( template_vars: TemplateVars = {"link": link} + emails_sent_counter.labels("add_threepid").inc() + await self.send_email( email_address, self.email_subjects.email_validation @@ -221,6 +240,8 @@ async def send_add_threepid_mail( template_vars, ) + emails_sent_counter.labels("notification") + async def send_notification_mail( self, app_id: str, @@ -315,6 +336,8 @@ async def _fetch_room_state(room_id: str) -> None: "reason": reason, } + emails_sent_counter.labels("notification").inc() + await self.send_email( email_address, summary_text, template_vars, unsubscribe_link ) From b4e2b119731323893934e93194ef99409a5ba7ae Mon Sep 17 00:00:00 2001 From: Remi Rampin Date: Thu, 1 Feb 2024 11:17:24 -0500 Subject: [PATCH 2/2] Add changelog entry --- changelog.d/16881.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/16881.feature diff --git a/changelog.d/16881.feature b/changelog.d/16881.feature new file mode 100644 index 00000000000..d1c8cc304e8 --- /dev/null +++ b/changelog.d/16881.feature @@ -0,0 +1 @@ +A metric was added for emails sent by Synapse, broken down by type: `synapse_emails_sent_total`. Contributed by Remi Rampin.