user-dir updater worker

This commit is contained in:
Daniel Lovbrotte Olsen 2022-12-14 10:10:11 +01:00
parent bb105192c2
commit 43dbc17526
2 changed files with 30 additions and 5 deletions

View File

@ -137,6 +137,8 @@ in
default = 0; default = 0;
}; };
useUserDirectoryWorker = lib.mkEnableOption "user directory worker";
instances = lib.mkOption { instances = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule ({config, ...}: { type = lib.types.attrsOf (lib.types.submodule ({config, ...}: {
@ -170,6 +172,7 @@ in
"initial-sync" = "synapse.app.generic_worker"; "initial-sync" = "synapse.app.generic_worker";
"normal-sync" = "synapse.app.generic_worker"; "normal-sync" = "synapse.app.generic_worker";
"event-persist" = "synapse.app.generic_worker"; "event-persist" = "synapse.app.generic_worker";
"user-dir" = "synapse.app.generic_worker";
}.${t}; }.${t};
defaultApp = if (!isAuto) defaultApp = if (!isAuto)
then "synapse.app.generic_worker" then "synapse.app.generic_worker"
@ -230,6 +233,7 @@ in
"initial-sync" = [ "client" ]; "initial-sync" = [ "client" ];
"normal-sync" = [ "client" ]; "normal-sync" = [ "client" ];
"event-persist" = [ "replication" ]; "event-persist" = [ "replication" ];
"user-dir" = [ "client" ];
}.${t}; }.${t};
in lib.mkOption { in lib.mkOption {
type = lib.types.listOf (lib.types.submodule { type = lib.types.listOf (lib.types.submodule {
@ -620,11 +624,22 @@ in
(i: { (i: {
isAuto = true; type = "event-persist"; index = i; isAuto = true; type = "event-persist"; index = i;
settings.worker_listeners = [{ port = cfg.workers.workerStartingPort + cfg.workers.federationReceivers + cfg.workers.initialSyncers + cfg.workers.normalSyncers + i - 1;}] settings.worker_listeners = [{ port = cfg.workers.workerStartingPort + cfg.workers.federationReceivers + cfg.workers.initialSyncers + cfg.workers.normalSyncers + i - 1;}]
++ lib.optional wcfg.enableMetrics { port = cfg.workers.metricsStartingPort + cfg.workers.federationSenders + cfg.workers.federationReceivers + cfg.workers.initialSyncers + cfg.workers.normalSyncers + i; ++ lib.optional wcfg.enableMetrics { port = cfg.workers.metricsStartingPort + cfg.workers.federationSenders + cfg.workers.federationReceivers + cfg.workers.initialSyncers + cfg.workers.normalSyncers + i;
resources = [ { names = [ "metrics" ]; } ]; resources = [ { names = [ "metrics" ]; } ];
}; };
}); });
}) })
(lib.mkIf cfg.workers.useUserDirectoryWorker {
services.matrix-synapse-next.workers.instances."auto-user-dir" = {
isAuto = true; type = "user-dir"; index = 1;
settings.worker_listeners = [{ port = cfg.workers.workerStartingPort + cfg.workers.federationReceivers + cfg.workers.initialSyncers + cfg.workers.normalSyncers + cfg.workers.eventPersisters + 1 - 1;}]
++ lib.optional wcfg.enableMetrics { port = cfg.workers.metricsStartingPort + cfg.workers.federationSenders + cfg.workers.federationReceivers + cfg.workers.initialSyncers + cfg.workers.normalSyncers + cfg.workers.eventPersisters + 1;
resources = [ { names = [ "metrics"]; } ];
};
};
services.matrix-synapse-next.settings.update_user_directory_from_worker = "auto-user-dir";
})
]) ])
({ ({

View File

@ -103,7 +103,7 @@ in
~^/_matrix/client/(api/v1|r0|v3|unstable)/presence/ synapse_client_presence; ~^/_matrix/client/(api/v1|r0|v3|unstable)/presence/ synapse_client_presence;
# User directory search requests; # User directory search requests;
~^/_matrix/client/(r0|v3|unstable)/user_directory/search$ synapse_client_search; ~^/_matrix/client/(r0|v3|unstable)/user_directory/search$ synapse_client_user-dir;
} }
#Plugboard for url -> workers #Plugboard for url -> workers
@ -115,6 +115,8 @@ in
synapse_federation synapse_worker_federation; synapse_federation synapse_worker_federation;
synapse_federation_transaction synapse_worker_federation; synapse_federation_transaction synapse_worker_federation;
synapse_client_user-dir synapse_worker_user-dir;
} }
# from https://github.com/tswfi/synapse/commit/b3704b936663cc692241e978dce4ac623276b1a6 # from https://github.com/tswfi/synapse/commit/b3704b936663cc692241e978dce4ac623276b1a6
@ -166,7 +168,7 @@ in
socketAddresses = generateSocketAddresses "client" initialSyncers; socketAddresses = generateSocketAddresses "client" initialSyncers;
in if initialSyncers != [ ] then in if initialSyncers != [ ] then
lib.genAttrs socketAddresses (_: { }) lib.genAttrs socketAddresses (_: { })
else config.services.nginx.upstreams.synapse_master.server; else config.services.nginx.upstreams.synapse_master.servers;
extraConfig = '' extraConfig = ''
hash $mxid_localpart consistent; hash $mxid_localpart consistent;
''; '';
@ -179,13 +181,21 @@ in
socketAddresses = generateSocketAddresses "client" normalSyncers; socketAddresses = generateSocketAddresses "client" normalSyncers;
in if normalSyncers != [ ] then in if normalSyncers != [ ] then
lib.genAttrs socketAddresses (_: { }) lib.genAttrs socketAddresses (_: { })
else config.services.nginx.upstreams.synapse_master.server; else config.services.nginx.upstreams.synapse_master.servers;
extraConfig = '' extraConfig = ''
hash $mxid_localpart consistent; hash $mxid_localpart consistent;
''; '';
}; };
services.nginx.upstreams.synapse_worker_user-dir = {
servers = let
workers = getWorkersOfType "user-dir";
socketAddresses = generateSocketAddresses "client" workers;
in if workers != [ ] then
lib.genAttrs socketAddresses (_: { })
else config.services.nginx.upstreams.synapse_master.servers;
};
services.nginx.virtualHosts."${cfg.public_baseurl}" = { services.nginx.virtualHosts."${cfg.public_baseurl}" = {
enableACME = true; enableACME = true;