Refactor the configure_workers_and_start.py script used internally by Complement.#16803
Refactor the configure_workers_and_start.py script used internally by Complement.#16803reivilibre wants to merge 20 commits intodevelopfrom
configure_workers_and_start.py script used internally by Complement.#16803Conversation
…the extra config template
…arate function for that
| "worker_extra_conf": "", | ||
| }, | ||
| "media_repository": { | ||
| "app": "synapse.app.generic_worker", |
There was a problem hiding this comment.
Hmm, the documentation still thinks that you should use synapse.app.media_repository to configure this: https://element-hq.github.io/synapse/latest/workers.html#synapseappmedia_repository
There was a problem hiding this comment.
Hrm, that's a headscratcher.
Complement does test the media endpoints and the tests pass.......?
But looking at
synapse/synapse/config/repository.py
Line 129 in f95cfd8
synapse.app.media_repository seems to matter), you'd expect this to break things...
erikjohnston
left a comment
There was a problem hiding this comment.
Seems mostly sane, though this is a large PR.
Is this just refactoring to make things easier or was this blocking something?
| """ | ||
| Merges `new` into `dest` with the following rules: | ||
|
|
||
| - dicts: values with the same key will be merged recursively |
There was a problem hiding this comment.
In general I'm very cautious about this, as deep merging can be quite a foot gun. Sometimes it makes sense to merge configuration dicts, sometimes it really doesn't and can be very surprising.
There was a problem hiding this comment.
do you have any examples of where it doesn't make sense? I can't remember ever seeing one (and I use NixOS which is all about merging config dicts...!), but on the other hand I have been bitten by dicts not being merged quite a few times :).
There was a problem hiding this comment.
The common case would be e.g. database config, where you'd have some config for a sqlite db and then it gets merged into config for a postgres db, and now you have a config with mixed parameters from both. I believe nixos gets around this by erroring out if the same key is set to different values in both dicts
There was a problem hiding this comment.
I mean yes I guess, but I don't consider that merging if two different values have been specified for the same key (it will raise an exception for this case, see https://github.com/element-hq/synapse/pull/16803/files#diff-30887e6a3a63f861b737500ca8243d3da5f0e7df016cc9cc020b8eeb61c2320cR355-R356).
| "event_persister": WorkerTemplate( | ||
| listener_resources={"replication"}, | ||
| shared_extra_conf=lambda worker_name: { | ||
| "stream_writers": {"events": [worker_name]} |
There was a problem hiding this comment.
Rather than trying to recursively merge stream writers, can we instead add a top level config to WorkerTemplate?
There was a problem hiding this comment.
yeah, if that works smoothly I will give it a go.
| sys.stderr.flush() | ||
|
|
||
|
|
||
| def merge_into(dest: Any, new: Any) -> None: |
There was a problem hiding this comment.
The name into makes me expect the second param is what is being changed, i.e dest into new. Maybe merge_update?
There was a problem hiding this comment.
tempted just to replace its use with merged and have merged leave the input untouched
8c71575 to
8c72abc
Compare
8c72abc to
c91ab4b
Compare
Pulled out of #16803 since the drive-by cleanup was maybe not as drive-by as I had hoped. <!-- Fixes: # <!-- --> <!-- Supersedes: # <!-- --> <!-- Follows: # <!-- --> <!-- Part of: # <!-- --> Base: `develop` <!-- git-stack-base-branch:develop --> <!-- This pull request is commit-by-commit review friendly. <!-- --> <!-- This pull request is intended for commit-by-commit review. <!-- --> Original commit schedule, with full messages: <ol> <li> Add a --generate-only option </li> </ol> --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
Revival of matrix-org/synapse#16650
Base:
developOriginal commit schedule, with full messages:
Remove obsolete
"app"from worker templatesConvert worker templates into dataclass
Use a lambda for the worker name rather than search and replace later
Collapse WORKERS_CONFIG by removing entries with defaults
Convert listener_resources and endpoint_patterns to Set[str]
Tweak comments
Add
merge_intoRemove special logic for adding stream_writers: just make it part of the extra config template
Rename function to add_worker_to_instance_map given reduction of scope
Add
sharding_allowedto the WorkerTemplate rather than having a separate function for thatUse
merge_intowhen adding workers to the shared configPromote mark_filepath to constant
Add a --generate-only option
Docstring on WorkerTemplate
Fix comment and mutation bug on merge_worker_template_configs
Update comment on
mergedTweak
instantiate_worker_template, both in name, description and variable names