Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Consolidates discovery of Prefect server Services to the base class #16913

Merged
merged 4 commits into from
Jan 30, 2025

Conversation

chrisguidry
Copy link
Collaborator

@chrisguidry chrisguidry commented Jan 30, 2025

Following on the work in #16898 to unify Prefect's Service
implementations, this moves the discovery routine from the CLI to the
base Service implementation. This also includes a couple of
additional niceties:

  • Each service is now responsible for knowing which Setting enables
    it. This eventually means that when adding a new service, we won't
    need to modify the api/server.py lifespan or the CLI. The
    conditional toggling of services on and off will be handled by asking
    the service if it should be enabled.

  • The way service names are handled is more uniform across all the
    subclasses. I also cleaned up the descriptions of all services to
    make them more punchy and imperative.

  • The table of services uses the setting name as part of how it shows
    whether the service is enabled, which means folks shouldn't have to
    hunt through the code or docs to find the setting.

image

We do still have an explicit listing of all the known service modules,
because I wasn't too keen to go down the rabbithole of automatic
discovery from entrypoints or anything like that. Definitely open to
ideas on a better place for that.

This version doesn't unify how the api/server.py lifespan starts
services, but that will be coming in a future update.

Checklist

  • This pull request references any related issue by including "closes <link to issue>"
    • If no issue exists and your change is not a small fix, please create an issue first.
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json.
  • If this pull request adds functions or classes, it includes helpful docstrings.

self.logger = get_logger(f"server.services.{self.name.lower()}")


class LoopService(Service, abc.ABC):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note I moved the base LoopService implementation here

@chrisguidry chrisguidry force-pushed the consolidate-services-discovery branch from 2eece0a to 0d92cca Compare January 30, 2025 18:56
)


def _known_service_modules() -> list[ModuleType]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is that spot where we still have to explicitly expose all the service modules (I moved this from the CLI module). This essentially serves as a "registry" of the services

@chrisguidry chrisguidry force-pushed the consolidate-services-discovery branch from 0d92cca to 72599c9 Compare January 30, 2025 18:59
@chrisguidry chrisguidry marked this pull request as ready for review January 30, 2025 19:00
Copy link

codspeed-hq bot commented Jan 30, 2025

CodSpeed Performance Report

Merging #16913 will not alter performance

Comparing consolidate-services-discovery (2c22c5a) with main (c590d61)

Summary

✅ 2 untouched benchmarks

Copy link
Collaborator

@zzstoatzz zzstoatzz left a comment

Choose a reason for hiding this comment

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

🤝

Following on the work in #16898 to unify Prefect's `Service`
implementations, this moves the discovery routine from the CLI to the
base `Service` implementation.  This also includes a couple of
additional niceties:

- Each service is now responsible for knowing which `Setting` enables
  it.  This eventually means that when adding a new service, we won't
  need to modify the `api/server.py` lifespan or the CLI.  The
  conditional toggling of services on and off will be handled by asking
  the service if it should be enabled.

- The way service names are handles is more uniform across all the
  subclasses.  I also cleaned up the descriptions of all services to
  make them more punchy and imperative.

- The table of services uses the setting name as part of how it shows
  whether the service is enabled, which means folks shouldn't have to
  hunt through the code or docs to find the setting.

We do still have an explicit listing of all the known service modules,
because I wasn't too keen to go down the rabbithole of automatic
discovery from entrypoints or anything like that.  Definitely open to
ideas on a better place for that.

This version doesn't unify how the `api/server.py` lifespan starts
services, but that will be coming in a future update.
@chrisguidry chrisguidry force-pushed the consolidate-services-discovery branch from 4503934 to 2c22c5a Compare January 30, 2025 21:29
@chrisguidry chrisguidry merged commit ffa9951 into main Jan 30, 2025
48 checks passed
@chrisguidry chrisguidry deleted the consolidate-services-discovery branch January 30, 2025 21:47
chrisguidry added a commit that referenced this pull request Jan 31, 2025
In the final step of the plan to unify how services are handled (
after #16898 and #16913), we tie everything together by having both the
API lifespan in `prefect server start` and the CLI `prefect server
services start` use the same service running logic.

At this point, when adding a new service, we should just need to add a
new subclass, implement its settings class, and then make sure its
module is represented in `server/services/base.py`.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants