From 33f9d2adeea36e659aea8c508e7f3ca0c88dce28 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 21 Dec 2025 02:54:49 -0500 Subject: [PATCH] add synapse sync worker --- logrotate.d/synapse | 2 +- nginx/nginx.conf | 11 ++++++++++- synapse/workers/sync.yaml | 11 +++++++++++ synapse/workers/sync_log_config.yaml | 23 +++++++++++++++++++++++ syslog-ng/conf.d/synapse.conf | 10 ++++++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 synapse/workers/sync.yaml create mode 100644 synapse/workers/sync_log_config.yaml diff --git a/logrotate.d/synapse b/logrotate.d/synapse index e4a9753..88fec45 100644 --- a/logrotate.d/synapse +++ b/logrotate.d/synapse @@ -1,4 +1,4 @@ -/var/log/synapse/main.log /var/log/synapse/background.log /var/log/synapse/client_reader.log /var/log/synapse/federation_reader.log /var/log/synapse/federation_sender1.log /var/log/synapse/federation_sender2.log /var/log/synapse/federation_sender3.log /var/log/synapse/federation_sender4.log /var/log/synapse/media_repository.log /var/log/synapse/pusher.log /var/log/synapse/stream_writer.log { +/var/log/synapse/main.log /var/log/synapse/background.log /var/log/synapse/client_reader.log /var/log/synapse/federation_reader.log /var/log/synapse/federation_sender1.log /var/log/synapse/federation_sender2.log /var/log/synapse/federation_sender3.log /var/log/synapse/federation_sender4.log /var/log/synapse/media_repository.log /var/log/synapse/pusher.log /var/log/synapse/stream_writer.log /var/log/synapse/sync.log { missingok maxsize 1G nodelaycompress diff --git a/nginx/nginx.conf b/nginx/nginx.conf index ed83fc4..965a07a 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -88,6 +88,11 @@ http { server unix:/run/synapse/main_public.sock max_conns=4096 max_fails=0; } + upstream synapse-sync { + zone synapse-sync 32k; + server unix:/run/synapse/sync_public.sock max_conns=4096 max_fails=0; + } + upstream synapse-client_reader { zone synapse-client_reader 32k; server unix:/run/synapse/client_reader_public.sock max_conns=4096 max_fails=0; @@ -185,7 +190,11 @@ http { proxy_pass http://synapse-main; - location ~ ^/_matrix/client/(?:r0|v3)/sync$|^/_matrix/client/(?:api/v1|r0|v3)/events$|^/_matrix/client/(?:api/v1|r0|v3)/initialSync$|^/_matrix/client/(?:api/v1|r0|v3)/rooms/[^/]+/initialSync$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/createRoom$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/publicRooms$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/joined_members$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/context/.*$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/members$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/state$|^/_matrix/client/v1/rooms/.*/hierarchy$|^/_matrix/client/(?:v1|unstable)/rooms/.*/relations/|^/_matrix/client/v1/rooms/.*/threads$|^/_matrix/client/unstable/im.nheko.summary/rooms/.*/summary$|^/_matrix/client/unstable/im.nheko.summary/summary/.*$|^/_matrix/client/(?:r0|v3|unstable)/account/3pid$|^/_matrix/client/(?:r0|v3|unstable)/account/whoami$|^/_matrix/client/(?:r0|v3|unstable)/account/deactivate$|^/_matrix/client/(?:r0|v3)/delete_devices$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/devices(?:/|$)|^/_matrix/client/versions$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/voip/turnServer$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/event/|^/_matrix/client/(?:api/v1|r0|v3|unstable)/joined_rooms$|^/_matrix/client/v1/rooms/.*/timestamp_to_event$|^/_matrix/client/(?:api/v1|r0|v3|unstable/.*)/rooms/.*/aliases|^/_matrix/client/(?:api/v1|r0|v3|unstable)/search$|^/_matrix/client/(?:r0|v3|unstable)/user/.*/filter(?:/|$)|^/_matrix/client/(?:api/v1|r0|v3|unstable)/directory/room/.*$|^/_matrix/client/(?:r0|v3|unstable)/capabilities$|^/_matrix/client/(?:r0|v3|unstable)/notifications$|^/_synapse/admin/v1/rooms/[^/]+$|^/_matrix/client/(?:r0|v3|unstable)/keys/query$|^/_matrix/client/(?:r0|v3|unstable)/keys/changes$|^/_matrix/client/(?:r0|v3|unstable)/keys/claim$|^/_matrix/client/(?:r0|v3|unstable)/room_keys/|^/_matrix/client/(?:r0|v3|unstable)/keys/upload|^/_matrix/client/(?:api/v1|r0|v3|unstable)/keys/device_signing/upload$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/keys/signatures/upload$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/login$|^/_matrix/client/(?:r0|v3|unstable)/register$|^/_matrix/client/(?:r0|v3|unstable)/register/available$|^/_matrix/client/v1/register/m.login.registration_token/validity$|^/_matrix/client/(?:r0|v3|unstable)/password_policy$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/redact|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/send|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/state/|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/(?:join|invite|leave|ban|unban|kick)$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/join/|^/_matrix/client/(?:api/v1|r0|v3|unstable)/knock/|^/_matrix/client/(?:api/v1|r0|v3|unstable)/profile/|^/_matrix/client/(?:r0|v3|unstable)/user_directory/search$|^/_matrix/client/unstable/org.matrix.msc4140/delayed_events(?:/.*/restart)?$|^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/messages$ { + location ~ ^/_matrix/client/(?:r0|v3)/sync$|^/_matrix/client/(?:api/v1|r0|v3)/events$|^/_matrix/client/(?:api/v1|r0|v3)/initialSync$|^/_matrix/client/(?:api/v1|r0|v3)/rooms/[^/]+/initialSync$ { + proxy_pass http://synapse-sync; + } + + location ~ ^/_matrix/client/(?:api/v1|r0|v3|unstable)/createRoom$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/publicRooms$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/joined_members$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/context/.*$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/members$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/state$|^/_matrix/client/v1/rooms/.*/hierarchy$|^/_matrix/client/(?:v1|unstable)/rooms/.*/relations/|^/_matrix/client/v1/rooms/.*/threads$|^/_matrix/client/unstable/im.nheko.summary/rooms/.*/summary$|^/_matrix/client/unstable/im.nheko.summary/summary/.*$|^/_matrix/client/(?:r0|v3|unstable)/account/3pid$|^/_matrix/client/(?:r0|v3|unstable)/account/whoami$|^/_matrix/client/(?:r0|v3|unstable)/account/deactivate$|^/_matrix/client/(?:r0|v3)/delete_devices$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/devices(?:/|$)|^/_matrix/client/versions$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/voip/turnServer$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/event/|^/_matrix/client/(?:api/v1|r0|v3|unstable)/joined_rooms$|^/_matrix/client/v1/rooms/.*/timestamp_to_event$|^/_matrix/client/(?:api/v1|r0|v3|unstable/.*)/rooms/.*/aliases|^/_matrix/client/(?:api/v1|r0|v3|unstable)/search$|^/_matrix/client/(?:r0|v3|unstable)/user/.*/filter(?:/|$)|^/_matrix/client/(?:api/v1|r0|v3|unstable)/directory/room/.*$|^/_matrix/client/(?:r0|v3|unstable)/capabilities$|^/_matrix/client/(?:r0|v3|unstable)/notifications$|^/_synapse/admin/v1/rooms/[^/]+$|^/_matrix/client/(?:r0|v3|unstable)/keys/query$|^/_matrix/client/(?:r0|v3|unstable)/keys/changes$|^/_matrix/client/(?:r0|v3|unstable)/keys/claim$|^/_matrix/client/(?:r0|v3|unstable)/room_keys/|^/_matrix/client/(?:r0|v3|unstable)/keys/upload|^/_matrix/client/(?:api/v1|r0|v3|unstable)/keys/device_signing/upload$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/keys/signatures/upload$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/login$|^/_matrix/client/(?:r0|v3|unstable)/register$|^/_matrix/client/(?:r0|v3|unstable)/register/available$|^/_matrix/client/v1/register/m.login.registration_token/validity$|^/_matrix/client/(?:r0|v3|unstable)/password_policy$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/redact|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/send|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/state/|^/_matrix/client/(?:api/v1|r0|v3|unstable)/rooms/.*/(?:join|invite|leave|ban|unban|kick)$|^/_matrix/client/(?:api/v1|r0|v3|unstable)/join/|^/_matrix/client/(?:api/v1|r0|v3|unstable)/knock/|^/_matrix/client/(?:api/v1|r0|v3|unstable)/profile/|^/_matrix/client/(?:r0|v3|unstable)/user_directory/search$|^/_matrix/client/unstable/org.matrix.msc4140/delayed_events(?:/.*/restart)?$|^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/messages$ { proxy_pass http://synapse-client_reader; } diff --git a/synapse/workers/sync.yaml b/synapse/workers/sync.yaml new file mode 100644 index 0000000..f958caa --- /dev/null +++ b/synapse/workers/sync.yaml @@ -0,0 +1,11 @@ +worker_app: synapse.app.generic_worker +worker_name: sync + +worker_listeners: + - path: /run/synapse/sync_public.sock + mode: 0660 + type: http + resources: + - names: [client] + +worker_log_config: /etc/synapse/workers/sync_log_config.yaml diff --git a/synapse/workers/sync_log_config.yaml b/synapse/workers/sync_log_config.yaml new file mode 100644 index 0000000..2f93cb2 --- /dev/null +++ b/synapse/workers/sync_log_config.yaml @@ -0,0 +1,23 @@ +version: 1 + +formatters: + syslog_fmt: + format: '%(name)s: [%(request)s] %(message)s' + +filters: + context: + (): synapse.logging.context.LoggingContextFilter + request: "" + +handlers: + syslog: + class: logging.handlers.SysLogHandler + formatter: syslog_fmt + filters: [context] + address: /run/synapse-sync-log + +root: + level: INFO + handlers: [syslog] + +disable_existing_loggers: False diff --git a/syslog-ng/conf.d/synapse.conf b/syslog-ng/conf.d/synapse.conf index 1d11779..f288e41 100644 --- a/syslog-ng/conf.d/synapse.conf +++ b/syslog-ng/conf.d/synapse.conf @@ -31,6 +31,9 @@ source s_synapse_pusher { source s_synapse_stream_writer { unix-dgram("/run/synapse-stream_writer-log" group("synapse") perm(0660)); }; +source s_synapse_sync { + unix-dgram("/run/synapse-sync-log" group("synapse") perm(0660)); +}; destination d_synapse_main { file("/var/log/synapse/main.log" template("${ISODATE} ${LEVEL} ${MESSAGE}\n")); @@ -65,6 +68,9 @@ destination d_synapse_pusher { destination d_synapse_stream_writer { file("/var/log/synapse/stream_writer.log" template("${ISODATE} ${LEVEL} ${MESSAGE}\n")); }; +destination d_synapse_sync { + file("/var/log/synapse/sync.log" template("${ISODATE} ${LEVEL} ${MESSAGE}\n")); +}; log { source(s_synapse_main); @@ -110,3 +116,7 @@ log { source(s_synapse_stream_writer); destination(d_synapse_stream_writer); }; +log { + source(s_synapse_sync); + destination(d_synapse_sync); +};