Skip to content

Pass stimulus_id to SchedulerPlugin.remove_worker and SchedulerPlugin.transition#7974

Merged
hendrikmakait merged 17 commits intodask:mainfrom
hendrikmakait:stimuli-in-plugin-hooks
Jul 19, 2023
Merged

Pass stimulus_id to SchedulerPlugin.remove_worker and SchedulerPlugin.transition#7974
hendrikmakait merged 17 commits intodask:mainfrom
hendrikmakait:stimuli-in-plugin-hooks

Conversation

@hendrikmakait
Copy link
Copy Markdown
Member

@hendrikmakait hendrikmakait commented Jul 6, 2023

Addresses #7973 by implementing the bare minimum to support #7970

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

@hendrikmakait hendrikmakait changed the title Pass stimulus_id in SchedulerPlugin.remove_worker and SchedulerPlugin.transition` Pass stimulus_id to SchedulerPlugin.remove_worker and SchedulerPlugin.transition Jul 6, 2023
Copy link
Copy Markdown
Member

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

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

Thanks @hendrikmakait. This will break existing plugins that have a transition and/or remove_worker method. Can we make stimulus_id optional such that existing plugins continue to work?

@hendrikmakait
Copy link
Copy Markdown
Member Author

Thanks @hendrikmakait. This will break existing plugins that have a transition and/or remove_worker method. Can we make stimulus_id optional such that existing plugins continue to work?

I'm not sure if we can do this nicely. The problem is that some plugins might accept it as a keyword, others might not, so (I think) we'd have to resort to introspection, which is rather cumbersome.

if (
"stimulus_id"
in inspect.signature(plugin.transition).parameters
):
plugin.transition(
key,
start,
actual_finish,
stimulus_id=stimulus_id,
**kwargs,
)
else:
plugin.transition(key, start, actual_finish, **kwargs)
implements this. I think I'd be fine with adding such a code for a deprecation cycle and issue a DeprecationWarning if stimulus_id is not supported, but I'd rather want to avoid this long-term.

@hendrikmakait hendrikmakait marked this pull request as draft July 6, 2023 17:28
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jul 6, 2023

Unit Test Results

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

       13 files   -          7         13 suites   - 7   6h 31m 30s ⏱️ - 4h 48m 26s
  3 718 tests +         2    3 607 ✔️ ±         0     108 💤 +    2  3 ±0 
23 565 runs   - 12 377  22 465 ✔️  - 11 723  1 097 💤  - 652  3  - 2 

For more details on these failures, see this check.

Results for commit de43494. ± Comparison against base commit 8e3e0f6.

This pull request skips 2 tests.
distributed.deploy.tests.test_subprocess ‑ test_raise_on_windows
distributed.tests.test_metrics ‑ test_monotonic

♻️ This comment has been updated with latest results.

@hendrikmakait
Copy link
Copy Markdown
Member Author

@jrbourbeau: I've added a FutureWarning for remove_worker. Since transition supports **kwargs, there's no strict need, though I'm wondering if we should still add a warning to alert users that the content of kwargs might change? I might be overthinking this.

@hendrikmakait hendrikmakait marked this pull request as ready for review July 7, 2023 10:13
@hendrikmakait hendrikmakait requested a review from jrbourbeau July 7, 2023 12:19
@fjetter
Copy link
Copy Markdown
Member

fjetter commented Jul 12, 2023

The entire purpose of kwargs is to tell people to implement their plugins in a forward compatible way. As long as we specify kwargs in the signature, we can freely add new paramters without affecting old users. Given our fragile plugin-API surface I suggest to keep kwargs and don't worry about any warnings for methods that had this in before.

Alerting about the content of kwargs seems counterintutive to me. If somebody cares aobut this, they should specify it as a proper argument

Comment on lines 169 to 171
def remove_worker(
self, scheduler: Scheduler, worker: str
self, scheduler: Scheduler, worker: str, *, stimulus_id: str
) -> None | Awaitable[None]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
def remove_worker(
self, scheduler: Scheduler, worker: str
self, scheduler: Scheduler, worker: str, *, stimulus_id: str
) -> None | Awaitable[None]:
def remove_worker(
self, scheduler: Scheduler, worker: str, stimulus_id: str, **kwargs
) -> None | Awaitable[None]:

I suggest to not force the keyword and allow kwargs for future compat reasons, see #7974 (comment)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Forcing the keyword while adding **kwargs would make a method with the signature MySchedulerPlugin.remove_worker(self, scheduler, worker, **kwargs) fully forward-compatible, so I'd suggest sticking with it unless we also want to require *args in the signature.

@hendrikmakait
Copy link
Copy Markdown
Member Author

The entire purpose of kwargs is to tell people to implement their plugins in a forward compatible way. As long as we specify kwargs in the signature, we can freely add new paramters without affecting old users. Given our fragile plugin-API surface I suggest to keep kwargs and don't worry about any warnings for methods that had this in before.

Alerting about the content of kwargs seems counterintutive to me. If somebody cares aobut this, they should specify it as a proper argument

Makes sense, I wasn't sure if the purpose of kwargs was to encourage forwrad-compatible implementations or to mimic the scheduler API. In the case of transition, Scheduler.transition itself takes kwargs because different transitions take different inputs.

I'll adjust this accordingly.

@hendrikmakait hendrikmakait requested a review from fjetter July 13, 2023 10:56
Copy link
Copy Markdown
Collaborator

@crusaderky crusaderky left a comment

Choose a reason for hiding this comment

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

Minor tweak on deprecation

Co-authored-by: crusaderky <crusaderky@gmail.com>
hendrikmakait and others added 2 commits July 17, 2023 14:31
Co-authored-by: crusaderky <crusaderky@gmail.com>
@hendrikmakait hendrikmakait requested a review from crusaderky July 17, 2023 16:55
@hendrikmakait
Copy link
Copy Markdown
Member Author

@crusaderky: All feedback has been addressed and a test added for **kwargs renaming. This is ready for another review.

@hendrikmakait hendrikmakait merged commit d9a3457 into dask:main Jul 19, 2023
@hendrikmakait hendrikmakait deleted the stimuli-in-plugin-hooks branch July 19, 2023 10:18
phofl pushed a commit to phofl/distributed that referenced this pull request Jul 24, 2023
…lugin.transition` (dask#7974)

Co-authored-by: crusaderky <crusaderky@gmail.com>
(cherry picked from commit d9a3457)
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.

4 participants