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

python: update Flux handle location in validator plugin API #6282

Merged
merged 3 commits into from
Sep 13, 2024

Conversation

grondo
Copy link
Contributor

@grondo grondo commented Sep 13, 2024

Currently, the Python validator plugin interface provides an on-demand Flux handle via the ValidatorJobInfo class. However, in retrospect, this was a big mistake. Since the ValidatorJobInfo object is created once per job, the handle is closed and must be reopened for each job passed to a validator plugin. Also, since the job info object is passed to multiple validators running in different threads, thread-local storage needs to be used, which complicates the implementation. Finally, the ValidatorJobInfo object is obviously not available when the plugin is configuring itself, which makes it impossible for plugins to contact Flux to configure themselves (or they have to open a handle themselves)

This PR instead provides a new flux attribute in the ValidatorPlugin class which opens and returns a Flux handle on first access. Because each plugin is run in its own thread, there is no longer a need to deal with TLS, simplifying the approach greatly. Finally, the handle is conveniently available any time the plugin is active, so the configure callback can now use it.

The handle provided by ValidatorJobInfo is then removed once the one internal user is updated. This could be a problem if there are out-of-tree validators out there (but I don't think that is likely at this point).

Problem: Validator plugins access a per-thread on-deman Flux handle
via the ValidatorJobInfo class. But objects of this class are not
available in the `configure` method, and also this means that a
handle may be created and destroyed for each job being validated,
instead of persisting for the lifetime of the plugin thread.

Add an on-demand handle in th ValidatorPlugin base class instead.
This will allow the plugin to access a Flux handle at any time,
as well as persisting for the lifetime of the plugin. Finally,
this handle doesn't have to be installed in thread-local storage,
since each plugin is run in a separate thread as it is.
Copy link
Member

@garlick garlick left a comment

Choose a reason for hiding this comment

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

LGTM!

Problem: The feasibility plugin uses the ValidatorJobInfo provided Flux
handle, but the ValidatorPlugin provided one is preferred.

Use the ValidatorPlugin provided handle instead.
Problem: Validator plugins should now be using the flux handle
provided by the ValidatorPlugin class instead of the one provided
by ValidatorJobInfo (which requires a handle be opened once per
job).

Remove the `flux` attribute from ValidatorJobInfo.
@grondo
Copy link
Contributor Author

grondo commented Sep 13, 2024

Thanks! Will set MWP.

@wihobbs
Copy link
Member

wihobbs commented Sep 13, 2024

@grondo can you clarify what you mean by "out of tree validators"? Is that any validator that's not stored alongside the rpm or in the builddir for the running flux?

@grondo
Copy link
Contributor Author

grondo commented Sep 13, 2024

can you clarify what you mean by "out of tree validators"? Is that any validator that's not stored alongside the rpm or in the builddir for the running flux?

By out-of-tree I meant any validator plugins being maintained outside of the flux-core source tree. If they use the flux handle in JobValidatorInfo then they'll need to be updated.

@wihobbs
Copy link
Member

wihobbs commented Sep 13, 2024

Ah, ok, thanks!

@mergify mergify bot merged commit 0473720 into flux-framework:master Sep 13, 2024
33 checks passed
Copy link

codecov bot commented Sep 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.34%. Comparing base (591b9f8) to head (698b49b).
Report is 4 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #6282       +/-   ##
===========================================
+ Coverage   53.78%   83.34%   +29.56%     
===========================================
  Files         473      522       +49     
  Lines       78410    85985     +7575     
===========================================
+ Hits        42176    71668    +29492     
+ Misses      36234    14317    -21917     
Files with missing lines Coverage Δ
...s/python/flux/job/validator/plugins/feasibility.py 100.00% <100.00%> (+53.84%) ⬆️
...rc/bindings/python/flux/job/validator/validator.py 95.29% <100.00%> (+23.86%) ⬆️

... and 444 files with indirect coverage changes

@grondo grondo deleted the validator-interface-update branch September 13, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants