Skip to content
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

Closed
wants to merge 20 commits into from

Conversation

reivilibre
Copy link
Contributor

Revival of matrix-org/synapse#16650

Base: develop

Original commit schedule, with full messages:

  1. Remove obsolete "app" from worker templates

  2. Convert worker templates into dataclass

  3. Use a lambda for the worker name rather than search and replace later

  4. Collapse WORKERS_CONFIG by removing entries with defaults

  5. Convert listener_resources and endpoint_patterns to Set[str]

  6. Tweak comments

  7. Add merge_into

  8. Remove special logic for adding stream_writers: just make it part of the extra config template

  9. Rename function to add_worker_to_instance_map given reduction of scope

  10. Add sharding_allowed to the WorkerTemplate rather than having a separate function for that

  11. Use merge_into when adding workers to the shared config

  12. Promote mark_filepath to constant

  13. Add a --generate-only option

  14. Docstring on WorkerTemplate

  15. Fix comment and mutation bug on merge_worker_template_configs

  16. Update comment on merged

  17. Tweak instantiate_worker_template, both in name, description and variable names

@reivilibre reivilibre marked this pull request as ready for review January 10, 2024 14:36
@reivilibre reivilibre requested a review from a team as a code owner January 10, 2024 14:36
@@ -108,7 +106,6 @@
"worker_extra_conf": "",
},
"media_repository": {
"app": "synapse.app.generic_worker",
Copy link
Member

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

Copy link
Contributor Author

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

and config.get("worker_app") != "synapse.app.media_repository"
(the only place where synapse.app.media_repository seems to matter), you'd expect this to break things...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#16826

Copy link
Member

@erikjohnston erikjohnston left a 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?

docker/configure_workers_and_start.py Show resolved Hide resolved
"""
Merges `new` into `dest` with the following rules:

- dicts: values with the same key will be merged recursively
Copy link
Member

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.

Copy link
Contributor Author

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 :).

Copy link
Member

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

Copy link
Contributor Author

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]}
Copy link
Member

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?

Copy link
Contributor Author

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:
Copy link
Member

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?

Copy link
Contributor Author

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

docker/configure_workers_and_start.py Outdated Show resolved Hide resolved
reivilibre added a commit that referenced this pull request Jan 22, 2024
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]>
@reivilibre reivilibre closed this Jun 3, 2024
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.

2 participants