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

Introduce Client.register_plugin() #8169

Merged
merged 32 commits into from Sep 8, 2023

Conversation

hendrikmakait
Copy link
Member

@hendrikmakait hendrikmakait commented Sep 6, 2023

This PR introduces Client.register_plugin() as the new method to use for registering plugins. Following #8150, it does not allow duck-typed plugins but dispatches based on the inherited plugin class.

It also deprecates Client.register_scheduler_plugin() and Client.register_worker_plugin() in favor of Client.register_plugin(). Within Client.register_worker_plugin(), it also adjusts the dispatching logic. With this PR, typing takes precedence, which means that the plugin will get registered based on its inherited plugin class, regardless of the nanny keyword and - most notably - if a SchedulerPlugin is used, it will be registered as a scheduler plugin. This fixes the migration problem for #8142.

  • Tests added / passed
  • Passes pre-commit run --all-files

@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2023

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

       21 files  +       19         21 suites  +19   10h 39m 18s ⏱️ + 10h 26m 24s
  3 813 tests +  1 973    3 702 ✔️ +  2 057     107 💤  -      88  4 +4 
36 859 runs  +34 984  35 054 ✔️ +33 409  1 800 💤 +1 570  5 +5 

For more details on these failures, see this check.

Results for commit 696ab82. ± Comparison against base commit b5729b0.

This pull request removes 4 and adds 1977 tests. Note that renamed tests count towards both.
distributed.diagnostics.tests.test_nanny_plugin ‑ test_duck_typed_nanny_plugin_is_deprecated
distributed.diagnostics.tests.test_scheduler_plugin ‑ test_register_scheduler_plugin
distributed.diagnostics.tests.test_scheduler_plugin ‑ test_register_scheduler_plugin_pickle_disabled
distributed.diagnostics.tests.test_worker_plugin ‑ test_duck_typed_worker_plugin_is_deprecated
distributed.cli.tests.test_dask_scheduler ‑ test_dashboard
distributed.cli.tests.test_dask_scheduler ‑ test_dashboard_allowlist
distributed.cli.tests.test_dask_scheduler ‑ test_dashboard_non_standard_ports
distributed.cli.tests.test_dask_scheduler ‑ test_dashboard_port_zero
distributed.cli.tests.test_dask_scheduler ‑ test_defaults
distributed.cli.tests.test_dask_scheduler ‑ test_hostport
distributed.cli.tests.test_dask_scheduler ‑ test_idle_timeout
distributed.cli.tests.test_dask_scheduler ‑ test_interface
distributed.cli.tests.test_dask_scheduler ‑ test_multiple_protocols
distributed.cli.tests.test_dask_scheduler ‑ test_multiple_workers
…

♻️ This comment has been updated with latest results.

@@ -7483,17 +7491,24 @@ def stop_task_metadata(self, name: str | None = None) -> dict:
self.remove_plugin(name=plugin.name)
return {"metadata": plugin.metadata, "state": plugin.state}

async def register_worker_plugin(self, comm, plugin, name=None):
Copy link
Member Author

Choose a reason for hiding this comment

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

Can the comm keyword be removed safely?

Copy link
Member

Choose a reason for hiding this comment

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

no, it can't #8189

self._register_worker_plugin, plugin=plugin, name=name, nanny=nanny
)
method: Callable
if isinstance(plugin, WorkerPlugin):
Copy link
Member Author

Choose a reason for hiding this comment

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

As opposed to #8150, this PR changes the precedence between the nanny keyword and typing.

UserWarning,
stacklevel=2,
)
elif isinstance(plugin, SchedulerPlugin): # type: ignore[unreachable]
Copy link
Member Author

Choose a reason for hiding this comment

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

It also takes the decision to override registration in case a scheduler plugin is used.

"""
Registers a lifecycle worker plugin for all current and future workers.

.. deprecated:: 2023.9.2
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm assuming we do another release in September.

@hendrikmakait hendrikmakait marked this pull request as ready for review September 7, 2023 16:38
@hendrikmakait
Copy link
Member Author

Note that this PR will likely fail if someone uses multiple inheritance, e.g. to subclass both SchedulerPlugin and WorkerPlugin. I don't think this is a pattern we'd want to encourage, but I've seen it being used at least once.

pass

n_existing_plugins = len(a.plugins)
assert not hasattr(a, "foo")
with pytest.warns(DeprecationWarning, match="duck-typed.*NannyPlugin"):
Copy link
Member

Choose a reason for hiding this comment

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

for the future, there is a specialized API in pytest for deprecated stuff, https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest-deprecated-call

distributed/client.py Outdated Show resolved Hide resolved
SchedulerUploadFile(filename, load=load), name=name
),
self.register_worker_plugin(UploadFile(filename, load=load), name=name),
# FIXME: Make scheduler plugin responsible for (de)registering worker plugin
Copy link
Member

Choose a reason for hiding this comment

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

ticket would be nice

Copy link
Member Author

Choose a reason for hiding this comment

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

@fjetter
Copy link
Member

fjetter commented Sep 8, 2023

changes look good. I could see use cases for multiple inheritance but what I can come up with is a "server plugin". Maybe thi is something to add later.
The deprecated paths are still available. Let's keep the deprecation warnings in for a bit to see where and if this causes issues

Co-authored-by: Florian Jetter <fjetter@users.noreply.github.com>
@hendrikmakait
Copy link
Member Author

hendrikmakait commented Sep 8, 2023

changes look good. I could see use cases for multiple inheritance but what I can come up with is a "server plugin". Maybe thi is something to add later.

+1 on a ServerPlugin that supports a subset of the existing APIs.

@hendrikmakait hendrikmakait merged commit 4e90a0a into dask:main Sep 8, 2023
21 of 28 checks passed
@hendrikmakait hendrikmakait deleted the client-register-plugin branch September 8, 2023 11:17
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.

None yet

2 participants