Skip to content

[serve] Add REST API#22578

Merged
edoakes merged 38 commits intoray-project:masterfrom
shrekris-anyscale:rest_api_only
Feb 24, 2022
Merged

[serve] Add REST API#22578
edoakes merged 38 commits intoray-project:masterfrom
shrekris-anyscale:rest_api_only

Conversation

@shrekris-anyscale
Copy link
Copy Markdown
Contributor

Why are these changes needed?

This change adds the GET, PUT, and DELETE commands for Serve’s REST API. The dashboard receives these commands and issues corresponding requests to the Serve controller.

Related issue number

Closes #21880.

Checks

  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
      • This change adds unit tests in test_serve_head.py to assess the REST API’s behavior. It also adds new tests to test_schema.py to assess updated behavior in the JSON schemas.

Copy link
Copy Markdown
Collaborator

@edoakes edoakes left a comment

Choose a reason for hiding this comment

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

Looks good, just a few small comments.

Assume you'll add the status endpoint in a follow up?


return DeploymentSchema(
name=d.name,
import_path=d.func_or_class,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hmm what will happen if this is a serialized class? we should make the change to only support import_paths in the controller so this makes sense

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question, that would cause an issue only when using both the REST API and the Python API at the same time. I can add handling to avoid setting the import path to a serialized function/class.

Making the controller only use import paths is a good idea, and I believe we’re making that change as a part of the controller unification. Since it’s somewhat extensive, I’d rather include it in a follow-up change.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yes sounds good, file an issue for it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, filed it here.

@routes.delete("/api/serve/deployments/")
@optional_utils.init_ray_and_catch_exceptions(connect_to_serve=True)
async def delete_all_deployments(self, req: Request) -> Response:
serve.shutdown()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this actually what we want to do or should we instead just delete the deployments themselves? this behavior seems ok to me given that we aren't accepting namespaces or anything

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think serve.shutdown() makes sense because then a DELETE request deletes the entire serve instance, not just the deployments. I've renamed the function to delete_serve_instance to reflect that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok works for me

Comment on lines +57 to +63
all_deployments = serve.list_deployments()
all_names = set(all_deployments.keys())
names_to_delete = all_names.difference(new_names)
for name in names_to_delete:
all_deployments[name].delete()

return Response()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this logic should live in the deploy_group API?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since deletions don’t need to be atomic, I think it’s ok to keep them out of deploy_group. It makes deploy_group more widely usable since it remains a way to atomically deploy a set of deployments.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok, this is fine for now we can revisit it. not too important w/o upgrade in tandem

@edoakes edoakes added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Feb 23, 2022
@shrekris-anyscale
Copy link
Copy Markdown
Contributor Author

Thanks for the review! Yes, I’m planning to add statuses in a follow up.

Copy link
Copy Markdown
Collaborator

@edoakes edoakes left a comment

Choose a reason for hiding this comment

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

LGTM for first cut, we can continue to iterate on the points I brought up below.

@shrekris-anyscale shrekris-anyscale removed the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Feb 24, 2022
@edoakes edoakes merged commit a9ede4e into ray-project:master Feb 24, 2022
simonsays1980 pushed a commit to simonsays1980/ray that referenced this pull request Feb 27, 2022
This change adds the GET, PUT, and DELETE commands for Serve’s REST API. The dashboard receives these commands and issues corresponding requests to the Serve controller.
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] [Serve] [Declarative API] REST API

2 participants