Skip to content

feat: add message and event count metric#76

Closed
itsoyou wants to merge 15 commits into
syk/add-room-count-metricfrom
syk/add-message-and-event-count-metric
Closed

feat: add message and event count metric#76
itsoyou wants to merge 15 commits into
syk/add-room-count-metricfrom
syk/add-message-and-event-count-metric

Conversation

@itsoyou

@itsoyou itsoyou commented Jul 29, 2025

Copy link
Copy Markdown
Member

Expose message & event counts in synapse #3264

  • synapse_messages_by_source: select COUNT(*) from events where type = 'm.room.message' or type = 'm.room.encrypted' and sender like '@%:tim-alpha.staging.famedly.de';, where the like query matches local events vs remote events.
  • synapse_events_by_source: Same as the above but not filtered by type.
  • synapse_encrypted_by_source: Same as the above, but only m.room.encrypted messages.
  • each of those having a local and a remote label:

@itsoyou
itsoyou requested a review from a team as a code owner July 29, 2025 12:41
@itsoyou
itsoyou changed the base branch from master to syk/add-room-count-metric July 29, 2025 12:41
@itsoyou itsoyou changed the title Syk/add message and event count metric feat: add message and event count metric Jul 29, 2025
@itsoyou
itsoyou force-pushed the syk/add-message-and-event-count-metric branch from e950583 to 3dce890 Compare August 1, 2025 10:31
@itsoyou
itsoyou force-pushed the syk/add-room-count-metric branch from 6e65f57 to 88bd92b Compare August 5, 2025 09:11
self._clock.looping_call(self.set_known_rooms_gauge, HOUR_IN_MS)
self._clock.looping_call(self.set_locally_joined_rooms_gauge, HOUR_IN_MS)
# update message metrics every 60 minutes
self._clock.looping_call(self.set_messages_by_source_gauge, HOUR_IN_MS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want message metrics at least every 5 minutes. Otherwise this will have too large jumps and not be that useful.

@itsoyou
itsoyou force-pushed the syk/add-message-and-event-count-metric branch from 3dce890 to 0716acb Compare August 7, 2025 15:31
@itsoyou
itsoyou marked this pull request as draft August 7, 2025 15:39
@itsoyou
itsoyou marked this pull request as ready for review August 8, 2025 14:44
@itsoyou
itsoyou requested a review from nico-famedly August 8, 2025 14:44
Comment thread synapse/metrics/common_usage_metrics.py
@jason-famedly

Copy link
Copy Markdown
Member

Query plan looks like this on my system(6.25 million rows):
image

This might be scary later. There are no indexes on either sender or type. Perhaps Nico would have some idea what he would like here. It only runs every 5 minutes, and even a few seconds isn't that awful(Mine took just over 1 second, for reference)

@itsoyou

itsoyou commented Aug 11, 2025

Copy link
Copy Markdown
Member Author

Query plan looks like this on my system(6.25 million rows): image

This might be scary later. There are no indexes on either sender or type. Perhaps Nico would have some idea what he would like here. It only runs every 5 minutes, and even a few seconds isn't that awful(Mine took just over 1 second, for reference)

Thank you Jason for checking this! A second does not sounds so good. I think if we time-range the metrics, it would show much better performance.
d.g. here there are already some related query exists, but with daily count. @nico-famedly is that okay if we have label for time-range like 24h, 7days, 30days? Otherwise, we should create indexes.

@nico-famedly

Copy link
Copy Markdown
Member

I think we want totals, so that we can create a time series manually. Running it every 5 minutes is probably fine, but creating an index doesn't sound too terrible either, but likely will have to happen as a background job?

@itsoyou

itsoyou commented Aug 11, 2025

Copy link
Copy Markdown
Member Author

I think we want totals, so that we can create a time series manually. Running it every 5 minutes is probably fine, but creating an index doesn't sound too terrible either, but likely will have to happen as a background job?

If we have to update metric on every events, I would consider adding count logic, since the table is pretty big.(Probably nice to have a sync logic to check if the value is equal to DB.) Otherwise if it's not too time-critical, I like to fetch info every 5 minutes from DB. Is there better approach to do it other than background job?

@nico-famedly

Copy link
Copy Markdown
Member

I think we want totals, so that we can create a time series manually. Running it every 5 minutes is probably fine, but creating an index doesn't sound too terrible either, but likely will have to happen as a background job?

If we have to update metric on every events, I would consider adding count logic, since the table is pretty big.(Probably nice to have a sync logic to check if the value is equal to DB.) Otherwise if it's not too time-critical, I like to fetch info every 5 minutes from DB. Is there better approach to do it other than background job?

Both approaches sound fine to me :)

@itsoyou
itsoyou force-pushed the syk/add-room-count-metric branch from 85ee9b1 to 56313f0 Compare September 30, 2025 14:51
@itsoyou

itsoyou commented Sep 30, 2025

Copy link
Copy Markdown
Member Author

closing with #146

@itsoyou itsoyou closed this Sep 30, 2025
@itsoyou
itsoyou deleted the syk/add-message-and-event-count-metric branch March 9, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants