Skip to content

Add REST plugin for user-defined policies #2631

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Nadine-H
Copy link

@Nadine-H Nadine-H commented May 13, 2025

Resolves #2630.

Key notes:

  • The REST plugin is a builtin plugin, unlike how other plugins are defined and loaded in the dstack system.
  • The REST plugin has to be enabled through the dstack server config if the user wishes to hook up a plugin server.

@Nadine-H
Copy link
Author

Nadine-H commented May 14, 2025

Realized that setting up this plugin as an external package is unnecessarily complicating the installation process. I'm going to change it so that it's more builtin the server code.

@r4victor
Copy link
Collaborator

r4victor commented May 14, 2025

Realized that setting up this plugin as an external package is unnecessarily complicating the installation process. I'm going to change it so that it's more builtin the server code.

A good place for a built-in server plugins would be to put them in src/dstack/_internal/server/services/plugins/builtin/rest_plugin

May require renaming src/dstack/_internal/server/services/plugins.py to src/dstack/_internal/server/services/plugins/__init__.py

Let me know if you need help with refactoring.

@r4victor
Copy link
Collaborator

I'll create an openapi spec doc

@Nadine-H, Do you think of writing the spec manually or generating it automatically? Automatic generation is highly preferable because spec models are regularly updated with new properties and it won't be practical to maintain manually written spec.

@Nadine-H
Copy link
Author

I'll create an openapi spec doc

@Nadine-H, Do you think of writing the spec manually or generating it automatically? Automatic generation is highly preferable because spec models are regularly updated with new properties and it won't be practical to maintain manually written spec.

Automatic generation for sure. I set up a local FastAPI server to test the rest plugin and will share the openai.json with you shortly.

@Nadine-H Nadine-H marked this pull request as ready for review May 20, 2025 15:35
@Nadine-H Nadine-H requested a review from r4victor May 20, 2025 15:35
@Nadine-H Nadine-H changed the title Add REST plugin for pre-apply validations Add REST plugin for user-defined policies May 20, 2025
timeout=PLUGIN_REQUEST_TIMEOUT,
)
response.raise_for_status()
spec_json = json.loads(response.text)
Copy link

@dakota-shop dakota-shop May 20, 2025

Choose a reason for hiding this comment

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

How does the Plugin reject a Run from being applied? Do we want some exceptions (HTTP Status Codes) to be propagated to Dstack? Or should there be an errors element of the response body?

I'm leaning toward the latter since if we're monitoring the plugin server, it might be difficult to distinguish between "the plugin server thought this request was invalid" and "the plugin server could not answer the question".

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I misread your comment when you shared it internally. Yes - I agree on the latter option, that way the user knows if the action is on their end or if it's a system issue (a bug in dstack or plugin server)

Copy link
Author

Choose a reason for hiding this comment

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

Added a pydantic model for the plugin server response that includes an error field here. Expectation is if request is rejected, dstack should a 200 response from plugin server with an error.

@Nadine-H
Copy link
Author

Adding documentation to the guides as well

GatewaySpecRequest = SpecRequest[GatewaySpec]


class CustomApplyPolicy(ApplyPolicy):
Copy link
Contributor

Choose a reason for hiding this comment

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

@r4victor Should async policies be a thing, or are policies always running in an executor?

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.

[Feature]: Support REST-based plugins
4 participants