-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the configure_workers_and_start.py
script used internally by Complement.
#16803
Conversation
…the extra config template
…arate function for that
Signed-off-by: Olivier Wilkinson (reivilibre) <[email protected]>
@@ -108,7 +106,6 @@ | |||
"worker_extra_conf": "", | |||
}, | |||
"media_repository": { | |||
"app": "synapse.app.generic_worker", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
and config.get("worker_app") != "synapse.app.media_repository" |
synapse.app.media_repository
seems to matter), you'd expect this to break things...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⇒ #16826
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
@@ -202,6 +210,9 @@ class WorkerTemplate: | |||
), | |||
"event_persister": WorkerTemplate( | |||
listener_resources={"replication"}, | |||
shared_extra_conf=lambda worker_name: { | |||
"stream_writers": {"events": [worker_name]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, if that works smoothly I will give it a go.
@@ -283,6 +283,31 @@ def flush_buffers() -> None: | |||
sys.stderr.flush() | |||
|
|||
|
|||
def merge_into(dest: Any, new: Any) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) <[email protected]>
Revival of matrix-org/synapse#16650
Base:
develop
Original 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_into
Remove 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_allowed
to the WorkerTemplate rather than having a separate function for thatUse
merge_into
when 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
merged
Tweak
instantiate_worker_template
, both in name, description and variable names