Services
zenml.services
Initialization of the ZenML services module.
A service is a process or set of processes that outlive a pipeline run.
Attributes
__all__ = ['ServiceConfig', 'ServiceStatus', 'ServiceEndpointProtocol', 'ServiceEndpointConfig', 'ServiceEndpointStatus', 'BaseServiceEndpoint', 'BaseService', 'ServiceEndpointHealthMonitorConfig', 'BaseServiceEndpointHealthMonitor', 'HTTPEndpointHealthMonitorConfig', 'HTTPEndpointHealthMonitor', 'TCPEndpointHealthMonitorConfig', 'TCPEndpointHealthMonitor', 'ContainerService', 'ContainerServiceConfig', 'ContainerServiceStatus', 'ContainerServiceEndpoint', 'ContainerServiceEndpointConfig', 'ContainerServiceEndpointStatus', 'LocalDaemonService', 'LocalDaemonServiceConfig', 'LocalDaemonServiceStatus', 'LocalDaemonServiceEndpointConfig', 'LocalDaemonServiceEndpointStatus', 'LocalDaemonServiceEndpoint']
module-attribute
Classes
BaseService(**attrs: Any)
Bases: BaseTypedModel
Base service class.
This class implements generic functionality concerning the life-cycle management and tracking of an external service (e.g. process, container, Kubernetes deployment etc.).
Attributes:
Name | Type | Description |
---|---|---|
SERVICE_TYPE |
ServiceType
|
a service type descriptor with information describing the service class. Every concrete service class must define this. |
admin_state |
ServiceState
|
the administrative state of the service. |
uuid |
UUID
|
unique UUID identifier for the service instance. |
config |
ServiceConfig
|
service configuration |
status |
ServiceStatus
|
service status |
endpoint |
Optional[BaseServiceEndpoint]
|
optional service endpoint |
Initialize the service instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**attrs
|
Any
|
keyword arguments. |
{}
|
Source code in src/zenml/services/service.py
188 189 190 191 192 193 194 195 196 197 198 |
|
Attributes
is_failed: bool
property
Check if the service is currently failed.
This method will actively poll the external service to get its status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service is in a failure state, otherwise False. |
is_running: bool
property
Check if the service is currently running.
This method will actively poll the external service to get its status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service is running and active (i.e. the endpoints are |
bool
|
responsive, if any are configured), otherwise False. |
is_stopped: bool
property
Check if the service is currently stopped.
This method will actively poll the external service to get its status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service is stopped, otherwise False. |
Functions
check_status() -> Tuple[ServiceState, str]
abstractmethod
Check the the current operational state of the external service.
This method should be overridden by subclasses that implement concrete service tracking functionality.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external service and a message |
str
|
providing additional information about that state (e.g. a |
Tuple[ServiceState, str]
|
description of the error if one is encountered while checking the |
Tuple[ServiceState, str]
|
service status). |
Source code in src/zenml/services/service.py
243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
deprovision(force: bool = False) -> None
Deprovisions all resources used by the service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
if True, the service will be deprovisioned even if it is in a failed state. |
False
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
if the service does not implement deprovisioning functionality. |
Source code in src/zenml/services/service.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
|
from_json(json_str: str) -> BaseTypedModel
classmethod
Loads a service from a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_str
|
str
|
the JSON string to load from. |
required |
Returns:
Type | Description |
---|---|
BaseTypedModel
|
The loaded service object. |
Source code in src/zenml/services/service.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
from_model(model: ServiceResponse) -> BaseService
classmethod
Loads a service from a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
ServiceResponse
|
The ServiceResponse to load from. |
required |
Returns:
Type | Description |
---|---|
BaseService
|
The loaded service object. |
Raises:
Type | Description |
---|---|
ValueError
|
if the service source is not found in the model. |
Source code in src/zenml/services/service.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
get_healthcheck_url() -> Optional[str]
Gets the healthcheck URL for the endpoint.
Returns:
Type | Description |
---|---|
Optional[str]
|
the healthcheck URL for the endpoint |
Source code in src/zenml/services/service.py
497 498 499 500 501 502 503 504 505 506 507 508 |
|
get_logs(follow: bool = False, tail: Optional[int] = None) -> Generator[str, bool, None]
abstractmethod
Retrieve the service logs.
This method should be overridden by subclasses that implement concrete service tracking functionality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow
|
bool
|
if True, the logs will be streamed as they are written |
False
|
tail
|
Optional[int]
|
only retrieve the last NUM lines of log output. |
None
|
Returns:
Type | Description |
---|---|
None
|
A generator that can be accessed to get the service logs. |
Source code in src/zenml/services/service.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
get_prediction_url() -> Optional[str]
Gets the prediction URL for the endpoint.
Returns:
Type | Description |
---|---|
Optional[str]
|
the prediction URL for the endpoint |
Source code in src/zenml/services/service.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
|
get_service_status_message() -> str
Get a service status message.
Returns:
Type | Description |
---|---|
str
|
A message providing information about the current operational |
str
|
state of the service. |
Source code in src/zenml/services/service.py
310 311 312 313 314 315 316 317 318 319 320 321 |
|
poll_service_status(timeout: int = 0) -> bool
Polls the external service status.
It does this until the service operational state matches the administrative state, the service enters a failed state, or the timeout is reached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int
|
maximum time to wait for the service operational state to match the administrative state, in seconds |
0
|
Returns:
Type | Description |
---|---|
bool
|
True if the service operational state matches the administrative |
bool
|
state, False otherwise. |
Source code in src/zenml/services/service.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
provision() -> None
Provisions resources to run the service.
Raises:
Type | Description |
---|---|
NotImplementedError
|
if the service does not implement provisioning functionality |
Source code in src/zenml/services/service.py
402 403 404 405 406 407 408 409 410 |
|
start(timeout: int = 0) -> None
Start the service and optionally wait for it to become active.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int
|
amount of time to wait for the service to become active. If set to 0, the method will return immediately after checking the service status. |
0
|
Source code in src/zenml/services/service.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
stop(timeout: int = 0, force: bool = False) -> None
Stop the service and optionally wait for it to shutdown.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int
|
amount of time to wait for the service to shutdown. If set to 0, the method will return immediately after checking the service status. |
0
|
force
|
bool
|
if True, the service will be stopped even if it is not currently running. |
False
|
Source code in src/zenml/services/service.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
|
update(config: ServiceConfig) -> None
Update the service configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
ServiceConfig
|
the new service configuration. |
required |
Source code in src/zenml/services/service.py
427 428 429 430 431 432 433 |
|
update_status() -> None
Update the status of the service.
Check the current operational state of the external service and update the local operational status information to reflect it.
This method should be overridden by subclasses that implement concrete service status tracking functionality.
Source code in src/zenml/services/service.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
BaseServiceEndpoint(*args: Any, **kwargs: Any)
Bases: BaseTypedModel
Base service class.
This class implements generic functionality concerning the life-cycle management and tracking of an external service endpoint (e.g. a HTTP/HTTPS API or generic TCP endpoint exposed by a service).
Attributes:
Name | Type | Description |
---|---|---|
admin_state |
ServiceState
|
the administrative state of the service endpoint |
config |
ServiceEndpointConfig
|
service endpoint configuration |
status |
ServiceEndpointStatus
|
service endpoint status |
monitor |
Optional[BaseServiceEndpointHealthMonitor]
|
optional service endpoint health monitor |
Initialize the service endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
positional arguments. |
()
|
**kwargs
|
Any
|
keyword arguments. |
{}
|
Source code in src/zenml/services/service_endpoint.py
111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
Functions
check_status() -> Tuple[ServiceState, str]
Check the the current operational state of the external service endpoint.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external service endpoint and a |
str
|
message providing additional information about that state |
Tuple[ServiceState, str]
|
(e.g. a description of the error, if one is encountered while |
Tuple[ServiceState, str]
|
checking the service status). |
Source code in src/zenml/services/service_endpoint.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
is_active() -> bool
Check if the service endpoint is active.
This means that it is responsive and can receive requests). This method will use the configured health monitor to actively check the endpoint status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service endpoint is active, otherwise False. |
Source code in src/zenml/services/service_endpoint.py
158 159 160 161 162 163 164 165 166 167 168 169 |
|
is_inactive() -> bool
Check if the service endpoint is inactive.
This means that it is unresponsive and cannot receive requests. This method will use the configured health monitor to actively check the endpoint status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service endpoint is inactive, otherwise False. |
Source code in src/zenml/services/service_endpoint.py
171 172 173 174 175 176 177 178 179 180 181 182 |
|
update_status() -> None
Check the the current operational state of the external service endpoint.
It updates the local operational status information accordingly.
Source code in src/zenml/services/service_endpoint.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
BaseServiceEndpointHealthMonitor
Bases: BaseTypedModel
Base class used for service endpoint health monitors.
Attributes:
Name | Type | Description |
---|---|---|
config |
ServiceEndpointHealthMonitorConfig
|
health monitor configuration for endpoint |
Functions
check_endpoint_status(endpoint: BaseServiceEndpoint) -> Tuple[ServiceState, str]
abstractmethod
Check the the current operational state of the external service endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint
|
BaseServiceEndpoint
|
service endpoint to check |
required |
This method should be overridden by subclasses that implement concrete service endpoint tracking functionality.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external service endpoint and an |
str
|
optional error message, if an error is encountered while checking |
Tuple[ServiceState, str]
|
the service endpoint status. |
Source code in src/zenml/services/service_monitor.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
ContainerService(**attrs: Any)
Bases: BaseService
A service represented by a containerized process.
This class extends the base service class with functionality concerning the life-cycle management and tracking of external services implemented as docker containers.
To define a containerized service, subclass this class and implement the
run
method. Upon start
, the service will spawn a container that
ends up calling the run
method.
For example,
from zenml.services import ServiceType, ContainerService, ContainerServiceConfig
import time
class SleepingServiceConfig(ContainerServiceConfig):
wake_up_after: int
class SleepingService(ContainerService):
SERVICE_TYPE = ServiceType(
name="sleeper",
description="Sleeping container",
type="container",
flavor="sleeping",
)
config: SleepingServiceConfig
def run(self) -> None:
time.sleep(self.config.wake_up_after)
service = SleepingService(config=SleepingServiceConfig(wake_up_after=10))
service.start()
NOTE: the SleepingService
class and its parent module have to be
discoverable as part of a ZenML Integration
, otherwise the daemon will
fail with the following error:
TypeError: Cannot load service with unregistered service type:
name='sleeper' type='container' flavor='sleeping' description='Sleeping container'
Attributes:
Name | Type | Description |
---|---|---|
config |
ContainerServiceConfig
|
service configuration |
status |
ContainerServiceStatus
|
service status |
endpoint |
Optional[ContainerServiceEndpoint]
|
optional service endpoint |
Source code in src/zenml/services/service.py
188 189 190 191 192 193 194 195 196 197 198 |
|
Attributes
container: Optional[Container]
property
Get the docker container for the service.
Returns:
Type | Description |
---|---|
Optional[Container]
|
The docker container for the service, or None if the container |
Optional[Container]
|
does not exist. |
container_id: str
property
Get the ID of the docker container for a service.
Returns:
Type | Description |
---|---|
str
|
The ID of the docker container for the service. |
docker_client: DockerClient
property
Initialize and/or return the docker client.
Returns:
Type | Description |
---|---|
DockerClient
|
The docker client. |
Functions
check_status() -> Tuple[ServiceState, str]
Check the the current operational state of the docker container.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the docker container and a message |
str
|
providing additional information about that state (e.g. a |
Tuple[ServiceState, str]
|
description of the error, if one is encountered). |
Source code in src/zenml/services/container/container_service.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
deprovision(force: bool = False) -> None
Deprovision the service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
if True, the service container will be forcefully stopped |
False
|
Source code in src/zenml/services/container/container_service.py
483 484 485 486 487 488 489 |
|
get_logs(follow: bool = False, tail: Optional[int] = None) -> Generator[str, bool, None]
Retrieve the service logs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow
|
bool
|
if True, the logs will be streamed as they are written |
False
|
tail
|
Optional[int]
|
only retrieve the last NUM lines of log output. |
None
|
Yields:
Type | Description |
---|---|
str
|
A generator that can be accessed to get the service logs. |
Source code in src/zenml/services/container/container_service.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
|
get_service_status_message() -> str
Get a message about the current operational state of the service.
Returns:
Type | Description |
---|---|
str
|
A message providing information about the current operational |
str
|
state of the service. |
Source code in src/zenml/services/container/container_service.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
provision() -> None
Provision the service.
Source code in src/zenml/services/container/container_service.py
479 480 481 |
|
run() -> None
abstractmethod
Run the containerized service logic associated with this service.
Subclasses must implement this method to provide the containerized
service functionality. This method will be executed in the context of
the running container, not in the context of the process that calls the
start
method.
Source code in src/zenml/services/container/container_service.py
532 533 534 535 536 537 538 539 540 |
|
ContainerServiceConfig(**data: Any)
Bases: ServiceConfig
containerized service configuration.
Attributes:
Name | Type | Description |
---|---|---|
root_runtime_path |
Optional[str]
|
the root path where the service stores its files. |
singleton |
bool
|
set to True to store the service files directly in the
|
image |
str
|
the container image to use for the service. |
Source code in src/zenml/services/service.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
ContainerServiceEndpoint(*args: Any, **kwargs: Any)
Bases: BaseServiceEndpoint
A service endpoint exposed by a containerized process.
This class extends the base service endpoint class with functionality concerning the life-cycle management and tracking of endpoints exposed by external services implemented as containerized processes.
Attributes:
Name | Type | Description |
---|---|---|
config |
ContainerServiceEndpointConfig
|
service endpoint configuration |
status |
ContainerServiceEndpointStatus
|
service endpoint status |
monitor |
Optional[Union[HTTPEndpointHealthMonitor, TCPEndpointHealthMonitor]]
|
optional service endpoint health monitor |
Source code in src/zenml/services/service_endpoint.py
111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
Functions
prepare_for_start() -> None
Prepare the service endpoint for starting.
This method is called before the service is started.
Source code in src/zenml/services/container/container_service_endpoint.py
121 122 123 124 125 126 127 128 129 |
|
ContainerServiceEndpointConfig
Bases: ServiceEndpointConfig
Local daemon service endpoint configuration.
Attributes:
Name | Type | Description |
---|---|---|
protocol |
ServiceEndpointProtocol
|
the TCP protocol implemented by the service endpoint |
port |
Optional[int]
|
preferred TCP port value for the service endpoint. If the port
is in use when the service is started, setting |
allocate_port |
bool
|
set to True to allocate a free TCP port for the service endpoint automatically. |
ContainerServiceEndpointStatus
ContainerServiceStatus
Bases: ServiceStatus
containerized service status.
Attributes:
Name | Type | Description |
---|---|---|
runtime_path |
Optional[str]
|
the path where the service files (e.g. the configuration file used to start the service daemon and the logfile) are located |
Attributes
config_file: Optional[str]
property
Get the path to the service configuration file.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the configuration file, or None, if the |
Optional[str]
|
service has never been started before. |
log_file: Optional[str]
property
Get the path to the log file where the service output is/has been logged.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the log file, or None, if the service has never been |
Optional[str]
|
started before. |
HTTPEndpointHealthMonitor
Bases: BaseServiceEndpointHealthMonitor
HTTP service endpoint health monitor.
Attributes:
Name | Type | Description |
---|---|---|
config |
HTTPEndpointHealthMonitorConfig
|
health monitor configuration for HTTP endpoint |
Functions
check_endpoint_status(endpoint: BaseServiceEndpoint) -> Tuple[ServiceState, str]
Run a HTTP endpoint API healthcheck.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint
|
BaseServiceEndpoint
|
service endpoint to check. |
required |
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external HTTP endpoint and an |
str
|
optional message describing that state (e.g. an error message, |
Tuple[ServiceState, str]
|
if an error is encountered while checking the HTTP endpoint |
Tuple[ServiceState, str]
|
status). |
Source code in src/zenml/services/service_monitor.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
get_healthcheck_uri(endpoint: BaseServiceEndpoint) -> Optional[str]
Get the healthcheck URI for the given service endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint
|
BaseServiceEndpoint
|
service endpoint to get the healthcheck URI for |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
The healthcheck URI for the given service endpoint or None, if |
Optional[str]
|
the service endpoint doesn't have a healthcheck URI. |
Source code in src/zenml/services/service_monitor.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
HTTPEndpointHealthMonitorConfig
Bases: ServiceEndpointHealthMonitorConfig
HTTP service endpoint health monitor configuration.
Attributes:
Name | Type | Description |
---|---|---|
healthcheck_uri_path |
str
|
URI subpath to use to perform service endpoint healthchecks. If not set, the service endpoint URI will be used instead. |
use_head_request |
bool
|
set to True to use a HEAD request instead of a GET when calling the healthcheck URI. |
http_status_code |
int
|
HTTP status code to expect in the health check response. |
http_timeout |
int
|
HTTP health check request timeout in seconds. |
LocalDaemonService(**attrs: Any)
Bases: BaseService
A service represented by a local daemon process.
This class extends the base service class with functionality concerning the life-cycle management and tracking of external services implemented as local daemon processes.
To define a local daemon service, subclass this class and implement the
run
method. Upon start
, the service will spawn a daemon process that
ends up calling the run
method.
For example,
from zenml.services import ServiceType, LocalDaemonService, LocalDaemonServiceConfig
import time
class SleepingDaemonConfig(LocalDaemonServiceConfig):
wake_up_after: int
class SleepingDaemon(LocalDaemonService):
SERVICE_TYPE = ServiceType(
name="sleeper",
description="Sleeping daemon",
type="daemon",
flavor="sleeping",
)
config: SleepingDaemonConfig
def run(self) -> None:
time.sleep(self.config.wake_up_after)
daemon = SleepingDaemon(config=SleepingDaemonConfig(wake_up_after=10))
daemon.start()
NOTE: the SleepingDaemon
class and its parent module have to be
discoverable as part of a ZenML Integration
, otherwise the daemon will
fail with the following error:
TypeError: Cannot load service with unregistered service type:
name='sleeper' type='daemon' flavor='sleeping' description='Sleeping daemon'
Attributes:
Name | Type | Description |
---|---|---|
config |
LocalDaemonServiceConfig
|
service configuration |
status |
LocalDaemonServiceStatus
|
service status |
endpoint |
Optional[LocalDaemonServiceEndpoint]
|
optional service endpoint |
Source code in src/zenml/services/service.py
188 189 190 191 192 193 194 195 196 197 198 |
|
Functions
check_status() -> Tuple[ServiceState, str]
Check the the current operational state of the daemon process.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the daemon process and a message |
str
|
providing additional information about that state (e.g. a |
Tuple[ServiceState, str]
|
description of the error, if one is encountered). |
Source code in src/zenml/services/local/local_service.py
273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
deprovision(force: bool = False) -> None
Deprovision the service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
if True, the service daemon will be forcefully stopped |
False
|
Source code in src/zenml/services/local/local_service.py
429 430 431 432 433 434 435 |
|
get_logs(follow: bool = False, tail: Optional[int] = None) -> Generator[str, bool, None]
Retrieve the service logs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow
|
bool
|
if True, the logs will be streamed as they are written |
False
|
tail
|
Optional[int]
|
only retrieve the last NUM lines of log output. |
None
|
Yields:
Type | Description |
---|---|
str
|
A generator that can be accessed to get the service logs. |
Source code in src/zenml/services/local/local_service.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
get_service_status_message() -> str
Get a message about the current operational state of the service.
Returns:
Type | Description |
---|---|
str
|
A message providing information about the current operational |
str
|
state of the service. |
Source code in src/zenml/services/local/local_service.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
provision() -> None
Provision the service.
Source code in src/zenml/services/local/local_service.py
425 426 427 |
|
run() -> None
abstractmethod
Run the service daemon process associated with this service.
Subclasses must implement this method to provide the service daemon
functionality. This method will be executed in the context of the
running daemon, not in the context of the process that calls the
start
method.
Source code in src/zenml/services/local/local_service.py
491 492 493 494 495 496 497 498 499 |
|
start(timeout: int = 0) -> None
Start the service and optionally wait for it to become active.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int
|
amount of time to wait for the service to become active. If set to 0, the method will return immediately after checking the service status. |
0
|
Source code in src/zenml/services/local/local_service.py
437 438 439 440 441 442 443 444 445 446 447 448 |
|
LocalDaemonServiceConfig(**data: Any)
Bases: ServiceConfig
Local daemon service configuration.
Attributes:
Name | Type | Description |
---|---|---|
silent_daemon |
bool
|
set to True to suppress the output of the daemon (i.e. redirect stdout and stderr to /dev/null). If False, the daemon output will be redirected to a logfile. |
root_runtime_path |
Optional[str]
|
the root path where the service daemon will store service configuration files |
singleton |
bool
|
set to True to store the service daemon configuration files
directly in the |
blocking |
bool
|
set to True to run the service the context of the current process and block until the service is stopped instead of running the service as a daemon process. Useful for operating systems that do not support daemon processes. |
Source code in src/zenml/services/service.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
LocalDaemonServiceEndpoint(*args: Any, **kwargs: Any)
Bases: BaseServiceEndpoint
A service endpoint exposed by a local daemon process.
This class extends the base service endpoint class with functionality concerning the life-cycle management and tracking of endpoints exposed by external services implemented as local daemon processes.
Attributes:
Name | Type | Description |
---|---|---|
config |
LocalDaemonServiceEndpointConfig
|
service endpoint configuration |
status |
LocalDaemonServiceEndpointStatus
|
service endpoint status |
monitor |
Optional[Union[HTTPEndpointHealthMonitor, TCPEndpointHealthMonitor]]
|
optional service endpoint health monitor |
Source code in src/zenml/services/service_endpoint.py
111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
Functions
prepare_for_start() -> None
Prepare the service endpoint for starting.
This method is called before the service is started.
Source code in src/zenml/services/local/local_service_endpoint.py
124 125 126 127 128 129 130 131 |
|
LocalDaemonServiceEndpointConfig
Bases: ServiceEndpointConfig
Local daemon service endpoint configuration.
Attributes:
Name | Type | Description |
---|---|---|
protocol |
ServiceEndpointProtocol
|
the TCP protocol implemented by the service endpoint |
port |
Optional[int]
|
preferred TCP port value for the service endpoint. If the port
is in use when the service is started, setting |
ip_address |
str
|
the IP address of the service endpoint. If not set, the default localhost IP address will be used. |
allocate_port |
bool
|
set to True to allocate a free TCP port for the service endpoint automatically. |
LocalDaemonServiceEndpointStatus
LocalDaemonServiceStatus
Bases: ServiceStatus
Local daemon service status.
Attributes:
Name | Type | Description |
---|---|---|
runtime_path |
Optional[str]
|
the path where the service daemon runtime files (the configuration file used to start the service daemon and the logfile) are located |
silent_daemon |
bool
|
flag indicating whether the output of the daemon is suppressed (redirected to /dev/null). |
Attributes
config_file: Optional[str]
property
Get the path to the configuration file used to start the service daemon.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the configuration file, or None, if the |
Optional[str]
|
service has never been started before. |
log_file: Optional[str]
property
Get the path to the log file where the service output is/has been logged.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the log file, or None, if the service has never been |
Optional[str]
|
started before, or if the service daemon output is suppressed. |
pid: Optional[int]
property
Return the PID of the currently running daemon.
Returns:
Type | Description |
---|---|
Optional[int]
|
The PID of the daemon, or None, if the service has never been |
Optional[int]
|
started before. |
pid_file: Optional[str]
property
Get the path to a daemon PID file.
This is where the last known PID of the daemon process is stored.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the PID file, or None, if the service has never been |
Optional[str]
|
started before. |
ServiceConfig(**data: Any)
Bases: BaseTypedModel
Generic service configuration.
Concrete service classes should extend this class and add additional attributes that they want to see reflected and used in the service configuration.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
name for the service instance |
description |
str
|
description of the service |
pipeline_name |
str
|
name of the pipeline that spun up the service |
pipeline_step_name |
str
|
name of the pipeline step that spun up the service |
run_name |
str
|
name of the pipeline run that spun up the service. |
Initialize the service configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**data
|
Any
|
keyword arguments. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if neither 'name' nor 'model_name' is set. |
Source code in src/zenml/services/service.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
Functions
get_service_labels() -> Dict[str, str]
Get the service labels.
Returns:
Type | Description |
---|---|
Dict[str, str]
|
a dictionary of service labels. |
Source code in src/zenml/services/service.py
149 150 151 152 153 154 155 156 157 158 159 |
|
ServiceEndpointConfig
Bases: BaseTypedModel
Generic service endpoint configuration.
Concrete service classes should extend this class and add additional attributes that they want to see reflected and use in the endpoint configuration.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
unique name for the service endpoint |
description |
str
|
description of the service endpoint |
ServiceEndpointHealthMonitorConfig
Bases: BaseTypedModel
Generic service health monitor configuration.
Concrete service classes should extend this class and add additional attributes that they want to see reflected and use in the health monitor configuration.
ServiceEndpointProtocol
ServiceEndpointStatus
Bases: ServiceStatus
Status information describing the operational state of a service endpoint.
For example, this could be a HTTP/HTTPS API or generic TCP endpoint exposed by a service. Concrete service classes should extend this class and add additional attributes that make up the operational state of the service endpoint.
Attributes:
Name | Type | Description |
---|---|---|
protocol |
ServiceEndpointProtocol
|
the TCP protocol used by the service endpoint |
hostname |
Optional[str]
|
the hostname where the service endpoint is accessible |
port |
Optional[int]
|
the current TCP port where the service endpoint is accessible |
Attributes
uri: Optional[str]
property
Get the URI of the service endpoint.
Returns:
Type | Description |
---|---|
Optional[str]
|
The URI of the service endpoint or None, if the service endpoint |
Optional[str]
|
operational status doesn't have the required information. |
ServiceState
ServiceStatus
Bases: BaseTypedModel
Information about the status of a service or process.
This information describes the operational status of an external process or service tracked by ZenML. This could be a process, container, Kubernetes deployment etc.
Concrete service classes should extend this class and add additional attributes that make up the operational state of the service.
Attributes:
Name | Type | Description |
---|---|---|
state |
ServiceState
|
the current operational state |
last_state |
ServiceState
|
the operational state prior to the last status update |
last_error |
str
|
the error encountered during the last status update |
Functions
clear_error() -> None
Clear the last error message.
Source code in src/zenml/services/service_status.py
64 65 66 |
|
update_state(new_state: Optional[ServiceState] = None, error: str = '') -> None
Update the current operational state to reflect a new state value and/or error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_state
|
Optional[ServiceState]
|
new operational state discovered by the last service status update |
None
|
error
|
str
|
error message describing an operational failure encountered during the last service status update |
''
|
Source code in src/zenml/services/service_status.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
ServiceType
Bases: BaseModel
Service type descriptor.
Attributes:
Name | Type | Description |
---|---|---|
type |
str
|
service type |
flavor |
str
|
service flavor |
name |
str
|
name of the service type |
description |
str
|
description of the service type |
logo_url |
str
|
logo of the service type |
TCPEndpointHealthMonitor
Bases: BaseServiceEndpointHealthMonitor
TCP service endpoint health monitor.
Attributes:
Name | Type | Description |
---|---|---|
config |
TCPEndpointHealthMonitorConfig
|
health monitor configuration for TCP endpoint |
Functions
check_endpoint_status(endpoint: BaseServiceEndpoint) -> Tuple[ServiceState, str]
Run a TCP endpoint healthcheck.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint
|
BaseServiceEndpoint
|
service endpoint to check. |
required |
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external TCP endpoint and an |
str
|
optional message describing that state (e.g. an error message, |
Tuple[ServiceState, str]
|
if an error is encountered while checking the TCP endpoint |
Tuple[ServiceState, str]
|
status). |
Source code in src/zenml/services/service_monitor.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
TCPEndpointHealthMonitorConfig
Modules
container
Initialization of a containerized ZenML service.
Modules
container_service
Implementation of a containerized ZenML service.
ContainerService(**attrs: Any)
Bases: BaseService
A service represented by a containerized process.
This class extends the base service class with functionality concerning the life-cycle management and tracking of external services implemented as docker containers.
To define a containerized service, subclass this class and implement the
run
method. Upon start
, the service will spawn a container that
ends up calling the run
method.
For example,
from zenml.services import ServiceType, ContainerService, ContainerServiceConfig
import time
class SleepingServiceConfig(ContainerServiceConfig):
wake_up_after: int
class SleepingService(ContainerService):
SERVICE_TYPE = ServiceType(
name="sleeper",
description="Sleeping container",
type="container",
flavor="sleeping",
)
config: SleepingServiceConfig
def run(self) -> None:
time.sleep(self.config.wake_up_after)
service = SleepingService(config=SleepingServiceConfig(wake_up_after=10))
service.start()
NOTE: the SleepingService
class and its parent module have to be
discoverable as part of a ZenML Integration
, otherwise the daemon will
fail with the following error:
TypeError: Cannot load service with unregistered service type:
name='sleeper' type='container' flavor='sleeping' description='Sleeping container'
Attributes:
Name | Type | Description |
---|---|---|
config |
ContainerServiceConfig
|
service configuration |
status |
ContainerServiceStatus
|
service status |
endpoint |
Optional[ContainerServiceEndpoint]
|
optional service endpoint |
Source code in src/zenml/services/service.py
188 189 190 191 192 193 194 195 196 197 198 |
|
container: Optional[Container]
property
Get the docker container for the service.
Returns:
Type | Description |
---|---|
Optional[Container]
|
The docker container for the service, or None if the container |
Optional[Container]
|
does not exist. |
container_id: str
property
Get the ID of the docker container for a service.
Returns:
Type | Description |
---|---|
str
|
The ID of the docker container for the service. |
docker_client: DockerClient
property
Initialize and/or return the docker client.
Returns:
Type | Description |
---|---|
DockerClient
|
The docker client. |
check_status() -> Tuple[ServiceState, str]
Check the the current operational state of the docker container.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the docker container and a message |
str
|
providing additional information about that state (e.g. a |
Tuple[ServiceState, str]
|
description of the error, if one is encountered). |
Source code in src/zenml/services/container/container_service.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
deprovision(force: bool = False) -> None
Deprovision the service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
if True, the service container will be forcefully stopped |
False
|
Source code in src/zenml/services/container/container_service.py
483 484 485 486 487 488 489 |
|
get_logs(follow: bool = False, tail: Optional[int] = None) -> Generator[str, bool, None]
Retrieve the service logs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow
|
bool
|
if True, the logs will be streamed as they are written |
False
|
tail
|
Optional[int]
|
only retrieve the last NUM lines of log output. |
None
|
Yields:
Type | Description |
---|---|
str
|
A generator that can be accessed to get the service logs. |
Source code in src/zenml/services/container/container_service.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
|
get_service_status_message() -> str
Get a message about the current operational state of the service.
Returns:
Type | Description |
---|---|
str
|
A message providing information about the current operational |
str
|
state of the service. |
Source code in src/zenml/services/container/container_service.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
provision() -> None
Provision the service.
Source code in src/zenml/services/container/container_service.py
479 480 481 |
|
run() -> None
abstractmethod
Run the containerized service logic associated with this service.
Subclasses must implement this method to provide the containerized
service functionality. This method will be executed in the context of
the running container, not in the context of the process that calls the
start
method.
Source code in src/zenml/services/container/container_service.py
532 533 534 535 536 537 538 539 540 |
|
ContainerServiceConfig(**data: Any)
Bases: ServiceConfig
containerized service configuration.
Attributes:
Name | Type | Description |
---|---|---|
root_runtime_path |
Optional[str]
|
the root path where the service stores its files. |
singleton |
bool
|
set to True to store the service files directly in the
|
image |
str
|
the container image to use for the service. |
Source code in src/zenml/services/service.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
ContainerServiceStatus
Bases: ServiceStatus
containerized service status.
Attributes:
Name | Type | Description |
---|---|---|
runtime_path |
Optional[str]
|
the path where the service files (e.g. the configuration file used to start the service daemon and the logfile) are located |
config_file: Optional[str]
property
Get the path to the service configuration file.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the configuration file, or None, if the |
Optional[str]
|
service has never been started before. |
log_file: Optional[str]
property
Get the path to the log file where the service output is/has been logged.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the log file, or None, if the service has never been |
Optional[str]
|
started before. |
container_service_endpoint
Implementation of a containerized service endpoint.
ContainerServiceEndpoint(*args: Any, **kwargs: Any)
Bases: BaseServiceEndpoint
A service endpoint exposed by a containerized process.
This class extends the base service endpoint class with functionality concerning the life-cycle management and tracking of endpoints exposed by external services implemented as containerized processes.
Attributes:
Name | Type | Description |
---|---|---|
config |
ContainerServiceEndpointConfig
|
service endpoint configuration |
status |
ContainerServiceEndpointStatus
|
service endpoint status |
monitor |
Optional[Union[HTTPEndpointHealthMonitor, TCPEndpointHealthMonitor]]
|
optional service endpoint health monitor |
Source code in src/zenml/services/service_endpoint.py
111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
prepare_for_start() -> None
Prepare the service endpoint for starting.
This method is called before the service is started.
Source code in src/zenml/services/container/container_service_endpoint.py
121 122 123 124 125 126 127 128 129 |
|
ContainerServiceEndpointConfig
Bases: ServiceEndpointConfig
Local daemon service endpoint configuration.
Attributes:
Name | Type | Description |
---|---|---|
protocol |
ServiceEndpointProtocol
|
the TCP protocol implemented by the service endpoint |
port |
Optional[int]
|
preferred TCP port value for the service endpoint. If the port
is in use when the service is started, setting |
allocate_port |
bool
|
set to True to allocate a free TCP port for the service endpoint automatically. |
ContainerServiceEndpointStatus
entrypoint
Implementation of a containerized service entrypoint.
This executable file is utilized as an entrypoint for all ZenML services that are implemented as locally running docker containers.
launch_service(service_config_file: str) -> None
Instantiate and launch a ZenML local service from its configuration file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_config_file
|
str
|
the path to the service configuration file. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
if the service configuration file is the wrong type. |
Source code in src/zenml/services/container/entrypoint.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
run(config_file: str) -> None
Runs a ZenML service as a docker container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_file
|
str
|
path to the configuration file for the service. |
required |
Source code in src/zenml/services/container/entrypoint.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
local
Initialization of a local ZenML service.
Modules
local_daemon_entrypoint
Implementation of a local daemon entrypoint.
This executable file is utilized as an entrypoint for all ZenML services that are implemented as locally running daemon processes.
run(config_file: str, log_file: str, pid_file: str) -> None
Runs a ZenML service as a daemon process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_file
|
str
|
path to the configuration file for the service. |
required |
log_file
|
str
|
path to the log file for the service. |
required |
pid_file
|
str
|
path to the PID file for the service. |
required |
Source code in src/zenml/services/local/local_daemon_entrypoint.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
local_service
Implementation of a local ZenML service.
LocalDaemonService(**attrs: Any)
Bases: BaseService
A service represented by a local daemon process.
This class extends the base service class with functionality concerning the life-cycle management and tracking of external services implemented as local daemon processes.
To define a local daemon service, subclass this class and implement the
run
method. Upon start
, the service will spawn a daemon process that
ends up calling the run
method.
For example,
from zenml.services import ServiceType, LocalDaemonService, LocalDaemonServiceConfig
import time
class SleepingDaemonConfig(LocalDaemonServiceConfig):
wake_up_after: int
class SleepingDaemon(LocalDaemonService):
SERVICE_TYPE = ServiceType(
name="sleeper",
description="Sleeping daemon",
type="daemon",
flavor="sleeping",
)
config: SleepingDaemonConfig
def run(self) -> None:
time.sleep(self.config.wake_up_after)
daemon = SleepingDaemon(config=SleepingDaemonConfig(wake_up_after=10))
daemon.start()
NOTE: the SleepingDaemon
class and its parent module have to be
discoverable as part of a ZenML Integration
, otherwise the daemon will
fail with the following error:
TypeError: Cannot load service with unregistered service type:
name='sleeper' type='daemon' flavor='sleeping' description='Sleeping daemon'
Attributes:
Name | Type | Description |
---|---|---|
config |
LocalDaemonServiceConfig
|
service configuration |
status |
LocalDaemonServiceStatus
|
service status |
endpoint |
Optional[LocalDaemonServiceEndpoint]
|
optional service endpoint |
Source code in src/zenml/services/service.py
188 189 190 191 192 193 194 195 196 197 198 |
|
check_status() -> Tuple[ServiceState, str]
Check the the current operational state of the daemon process.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the daemon process and a message |
str
|
providing additional information about that state (e.g. a |
Tuple[ServiceState, str]
|
description of the error, if one is encountered). |
Source code in src/zenml/services/local/local_service.py
273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
deprovision(force: bool = False) -> None
Deprovision the service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
if True, the service daemon will be forcefully stopped |
False
|
Source code in src/zenml/services/local/local_service.py
429 430 431 432 433 434 435 |
|
get_logs(follow: bool = False, tail: Optional[int] = None) -> Generator[str, bool, None]
Retrieve the service logs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow
|
bool
|
if True, the logs will be streamed as they are written |
False
|
tail
|
Optional[int]
|
only retrieve the last NUM lines of log output. |
None
|
Yields:
Type | Description |
---|---|
str
|
A generator that can be accessed to get the service logs. |
Source code in src/zenml/services/local/local_service.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
get_service_status_message() -> str
Get a message about the current operational state of the service.
Returns:
Type | Description |
---|---|
str
|
A message providing information about the current operational |
str
|
state of the service. |
Source code in src/zenml/services/local/local_service.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
provision() -> None
Provision the service.
Source code in src/zenml/services/local/local_service.py
425 426 427 |
|
run() -> None
abstractmethod
Run the service daemon process associated with this service.
Subclasses must implement this method to provide the service daemon
functionality. This method will be executed in the context of the
running daemon, not in the context of the process that calls the
start
method.
Source code in src/zenml/services/local/local_service.py
491 492 493 494 495 496 497 498 499 |
|
start(timeout: int = 0) -> None
Start the service and optionally wait for it to become active.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int
|
amount of time to wait for the service to become active. If set to 0, the method will return immediately after checking the service status. |
0
|
Source code in src/zenml/services/local/local_service.py
437 438 439 440 441 442 443 444 445 446 447 448 |
|
LocalDaemonServiceConfig(**data: Any)
Bases: ServiceConfig
Local daemon service configuration.
Attributes:
Name | Type | Description |
---|---|---|
silent_daemon |
bool
|
set to True to suppress the output of the daemon (i.e. redirect stdout and stderr to /dev/null). If False, the daemon output will be redirected to a logfile. |
root_runtime_path |
Optional[str]
|
the root path where the service daemon will store service configuration files |
singleton |
bool
|
set to True to store the service daemon configuration files
directly in the |
blocking |
bool
|
set to True to run the service the context of the current process and block until the service is stopped instead of running the service as a daemon process. Useful for operating systems that do not support daemon processes. |
Source code in src/zenml/services/service.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
LocalDaemonServiceStatus
Bases: ServiceStatus
Local daemon service status.
Attributes:
Name | Type | Description |
---|---|---|
runtime_path |
Optional[str]
|
the path where the service daemon runtime files (the configuration file used to start the service daemon and the logfile) are located |
silent_daemon |
bool
|
flag indicating whether the output of the daemon is suppressed (redirected to /dev/null). |
config_file: Optional[str]
property
Get the path to the configuration file used to start the service daemon.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the configuration file, or None, if the |
Optional[str]
|
service has never been started before. |
log_file: Optional[str]
property
Get the path to the log file where the service output is/has been logged.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the log file, or None, if the service has never been |
Optional[str]
|
started before, or if the service daemon output is suppressed. |
pid: Optional[int]
property
Return the PID of the currently running daemon.
Returns:
Type | Description |
---|---|
Optional[int]
|
The PID of the daemon, or None, if the service has never been |
Optional[int]
|
started before. |
pid_file: Optional[str]
property
Get the path to a daemon PID file.
This is where the last known PID of the daemon process is stored.
Returns:
Type | Description |
---|---|
Optional[str]
|
The path to the PID file, or None, if the service has never been |
Optional[str]
|
started before. |
local_service_endpoint
Implementation of a local service endpoint.
LocalDaemonServiceEndpoint(*args: Any, **kwargs: Any)
Bases: BaseServiceEndpoint
A service endpoint exposed by a local daemon process.
This class extends the base service endpoint class with functionality concerning the life-cycle management and tracking of endpoints exposed by external services implemented as local daemon processes.
Attributes:
Name | Type | Description |
---|---|---|
config |
LocalDaemonServiceEndpointConfig
|
service endpoint configuration |
status |
LocalDaemonServiceEndpointStatus
|
service endpoint status |
monitor |
Optional[Union[HTTPEndpointHealthMonitor, TCPEndpointHealthMonitor]]
|
optional service endpoint health monitor |
Source code in src/zenml/services/service_endpoint.py
111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
prepare_for_start() -> None
Prepare the service endpoint for starting.
This method is called before the service is started.
Source code in src/zenml/services/local/local_service_endpoint.py
124 125 126 127 128 129 130 131 |
|
LocalDaemonServiceEndpointConfig
Bases: ServiceEndpointConfig
Local daemon service endpoint configuration.
Attributes:
Name | Type | Description |
---|---|---|
protocol |
ServiceEndpointProtocol
|
the TCP protocol implemented by the service endpoint |
port |
Optional[int]
|
preferred TCP port value for the service endpoint. If the port
is in use when the service is started, setting |
ip_address |
str
|
the IP address of the service endpoint. If not set, the default localhost IP address will be used. |
allocate_port |
bool
|
set to True to allocate a free TCP port for the service endpoint automatically. |
LocalDaemonServiceEndpointStatus
service
Implementation of the ZenML Service class.
Classes
BaseDeploymentService(**attrs: Any)
Bases: BaseService
Base class for deployment services.
Source code in src/zenml/services/service.py
188 189 190 191 192 193 194 195 196 197 198 |
|
healthcheck_url: Optional[str]
property
Gets the healthcheck URL for the endpoint.
Returns:
Type | Description |
---|---|
Optional[str]
|
the healthcheck URL for the endpoint |
prediction_url: Optional[str]
property
Gets the prediction URL for the endpoint.
Returns:
Type | Description |
---|---|
Optional[str]
|
the prediction URL for the endpoint |
BaseService(**attrs: Any)
Bases: BaseTypedModel
Base service class.
This class implements generic functionality concerning the life-cycle management and tracking of an external service (e.g. process, container, Kubernetes deployment etc.).
Attributes:
Name | Type | Description |
---|---|---|
SERVICE_TYPE |
ServiceType
|
a service type descriptor with information describing the service class. Every concrete service class must define this. |
admin_state |
ServiceState
|
the administrative state of the service. |
uuid |
UUID
|
unique UUID identifier for the service instance. |
config |
ServiceConfig
|
service configuration |
status |
ServiceStatus
|
service status |
endpoint |
Optional[BaseServiceEndpoint]
|
optional service endpoint |
Initialize the service instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**attrs
|
Any
|
keyword arguments. |
{}
|
Source code in src/zenml/services/service.py
188 189 190 191 192 193 194 195 196 197 198 |
|
is_failed: bool
property
Check if the service is currently failed.
This method will actively poll the external service to get its status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service is in a failure state, otherwise False. |
is_running: bool
property
Check if the service is currently running.
This method will actively poll the external service to get its status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service is running and active (i.e. the endpoints are |
bool
|
responsive, if any are configured), otherwise False. |
is_stopped: bool
property
Check if the service is currently stopped.
This method will actively poll the external service to get its status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service is stopped, otherwise False. |
check_status() -> Tuple[ServiceState, str]
abstractmethod
Check the the current operational state of the external service.
This method should be overridden by subclasses that implement concrete service tracking functionality.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external service and a message |
str
|
providing additional information about that state (e.g. a |
Tuple[ServiceState, str]
|
description of the error if one is encountered while checking the |
Tuple[ServiceState, str]
|
service status). |
Source code in src/zenml/services/service.py
243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
deprovision(force: bool = False) -> None
Deprovisions all resources used by the service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
if True, the service will be deprovisioned even if it is in a failed state. |
False
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
if the service does not implement deprovisioning functionality. |
Source code in src/zenml/services/service.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
|
from_json(json_str: str) -> BaseTypedModel
classmethod
Loads a service from a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_str
|
str
|
the JSON string to load from. |
required |
Returns:
Type | Description |
---|---|
BaseTypedModel
|
The loaded service object. |
Source code in src/zenml/services/service.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
from_model(model: ServiceResponse) -> BaseService
classmethod
Loads a service from a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
ServiceResponse
|
The ServiceResponse to load from. |
required |
Returns:
Type | Description |
---|---|
BaseService
|
The loaded service object. |
Raises:
Type | Description |
---|---|
ValueError
|
if the service source is not found in the model. |
Source code in src/zenml/services/service.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
get_healthcheck_url() -> Optional[str]
Gets the healthcheck URL for the endpoint.
Returns:
Type | Description |
---|---|
Optional[str]
|
the healthcheck URL for the endpoint |
Source code in src/zenml/services/service.py
497 498 499 500 501 502 503 504 505 506 507 508 |
|
get_logs(follow: bool = False, tail: Optional[int] = None) -> Generator[str, bool, None]
abstractmethod
Retrieve the service logs.
This method should be overridden by subclasses that implement concrete service tracking functionality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow
|
bool
|
if True, the logs will be streamed as they are written |
False
|
tail
|
Optional[int]
|
only retrieve the last NUM lines of log output. |
None
|
Returns:
Type | Description |
---|---|
None
|
A generator that can be accessed to get the service logs. |
Source code in src/zenml/services/service.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
get_prediction_url() -> Optional[str]
Gets the prediction URL for the endpoint.
Returns:
Type | Description |
---|---|
Optional[str]
|
the prediction URL for the endpoint |
Source code in src/zenml/services/service.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
|
get_service_status_message() -> str
Get a service status message.
Returns:
Type | Description |
---|---|
str
|
A message providing information about the current operational |
str
|
state of the service. |
Source code in src/zenml/services/service.py
310 311 312 313 314 315 316 317 318 319 320 321 |
|
poll_service_status(timeout: int = 0) -> bool
Polls the external service status.
It does this until the service operational state matches the administrative state, the service enters a failed state, or the timeout is reached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int
|
maximum time to wait for the service operational state to match the administrative state, in seconds |
0
|
Returns:
Type | Description |
---|---|
bool
|
True if the service operational state matches the administrative |
bool
|
state, False otherwise. |
Source code in src/zenml/services/service.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
provision() -> None
Provisions resources to run the service.
Raises:
Type | Description |
---|---|
NotImplementedError
|
if the service does not implement provisioning functionality |
Source code in src/zenml/services/service.py
402 403 404 405 406 407 408 409 410 |
|
start(timeout: int = 0) -> None
Start the service and optionally wait for it to become active.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int
|
amount of time to wait for the service to become active. If set to 0, the method will return immediately after checking the service status. |
0
|
Source code in src/zenml/services/service.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
stop(timeout: int = 0, force: bool = False) -> None
Stop the service and optionally wait for it to shutdown.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout
|
int
|
amount of time to wait for the service to shutdown. If set to 0, the method will return immediately after checking the service status. |
0
|
force
|
bool
|
if True, the service will be stopped even if it is not currently running. |
False
|
Source code in src/zenml/services/service.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
|
update(config: ServiceConfig) -> None
Update the service configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
ServiceConfig
|
the new service configuration. |
required |
Source code in src/zenml/services/service.py
427 428 429 430 431 432 433 |
|
update_status() -> None
Update the status of the service.
Check the current operational state of the external service and update the local operational status information to reflect it.
This method should be overridden by subclasses that implement concrete service status tracking functionality.
Source code in src/zenml/services/service.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
ServiceConfig(**data: Any)
Bases: BaseTypedModel
Generic service configuration.
Concrete service classes should extend this class and add additional attributes that they want to see reflected and used in the service configuration.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
name for the service instance |
description |
str
|
description of the service |
pipeline_name |
str
|
name of the pipeline that spun up the service |
pipeline_step_name |
str
|
name of the pipeline step that spun up the service |
run_name |
str
|
name of the pipeline run that spun up the service. |
Initialize the service configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**data
|
Any
|
keyword arguments. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if neither 'name' nor 'model_name' is set. |
Source code in src/zenml/services/service.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
get_service_labels() -> Dict[str, str]
Get the service labels.
Returns:
Type | Description |
---|---|
Dict[str, str]
|
a dictionary of service labels. |
Source code in src/zenml/services/service.py
149 150 151 152 153 154 155 156 157 158 159 |
|
Functions
update_service_status(pre_status: Optional[ServiceState] = None, post_status: Optional[ServiceState] = None, error_status: ServiceState = ServiceState.ERROR) -> Callable[[T], T]
A decorator to update the service status before and after a method call.
This decorator is used to wrap service methods and update the service status before and after the method call. If the method raises an exception, the service status is updated to reflect the error state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pre_status
|
Optional[ServiceState]
|
the status to update before the method call. |
None
|
post_status
|
Optional[ServiceState]
|
the status to update after the method call. |
None
|
error_status
|
ServiceState
|
the status to update if the method raises an exception. |
ERROR
|
Returns:
Type | Description |
---|---|
Callable[[T], T]
|
Callable[..., Any]: The wrapped method with exception handling. |
Source code in src/zenml/services/service.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
Modules
service_endpoint
Implementation of a ZenML service endpoint.
Classes
BaseServiceEndpoint(*args: Any, **kwargs: Any)
Bases: BaseTypedModel
Base service class.
This class implements generic functionality concerning the life-cycle management and tracking of an external service endpoint (e.g. a HTTP/HTTPS API or generic TCP endpoint exposed by a service).
Attributes:
Name | Type | Description |
---|---|---|
admin_state |
ServiceState
|
the administrative state of the service endpoint |
config |
ServiceEndpointConfig
|
service endpoint configuration |
status |
ServiceEndpointStatus
|
service endpoint status |
monitor |
Optional[BaseServiceEndpointHealthMonitor]
|
optional service endpoint health monitor |
Initialize the service endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Any
|
positional arguments. |
()
|
**kwargs
|
Any
|
keyword arguments. |
{}
|
Source code in src/zenml/services/service_endpoint.py
111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
check_status() -> Tuple[ServiceState, str]
Check the the current operational state of the external service endpoint.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external service endpoint and a |
str
|
message providing additional information about that state |
Tuple[ServiceState, str]
|
(e.g. a description of the error, if one is encountered while |
Tuple[ServiceState, str]
|
checking the service status). |
Source code in src/zenml/services/service_endpoint.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
is_active() -> bool
Check if the service endpoint is active.
This means that it is responsive and can receive requests). This method will use the configured health monitor to actively check the endpoint status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service endpoint is active, otherwise False. |
Source code in src/zenml/services/service_endpoint.py
158 159 160 161 162 163 164 165 166 167 168 169 |
|
is_inactive() -> bool
Check if the service endpoint is inactive.
This means that it is unresponsive and cannot receive requests. This method will use the configured health monitor to actively check the endpoint status and will return the result.
Returns:
Type | Description |
---|---|
bool
|
True if the service endpoint is inactive, otherwise False. |
Source code in src/zenml/services/service_endpoint.py
171 172 173 174 175 176 177 178 179 180 181 182 |
|
update_status() -> None
Check the the current operational state of the external service endpoint.
It updates the local operational status information accordingly.
Source code in src/zenml/services/service_endpoint.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
ServiceEndpointConfig
Bases: BaseTypedModel
Generic service endpoint configuration.
Concrete service classes should extend this class and add additional attributes that they want to see reflected and use in the endpoint configuration.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
unique name for the service endpoint |
description |
str
|
description of the service endpoint |
ServiceEndpointProtocol
ServiceEndpointStatus
Bases: ServiceStatus
Status information describing the operational state of a service endpoint.
For example, this could be a HTTP/HTTPS API or generic TCP endpoint exposed by a service. Concrete service classes should extend this class and add additional attributes that make up the operational state of the service endpoint.
Attributes:
Name | Type | Description |
---|---|---|
protocol |
ServiceEndpointProtocol
|
the TCP protocol used by the service endpoint |
hostname |
Optional[str]
|
the hostname where the service endpoint is accessible |
port |
Optional[int]
|
the current TCP port where the service endpoint is accessible |
uri: Optional[str]
property
Get the URI of the service endpoint.
Returns:
Type | Description |
---|---|
Optional[str]
|
The URI of the service endpoint or None, if the service endpoint |
Optional[str]
|
operational status doesn't have the required information. |
Functions
service_monitor
Implementation of the service health monitor.
Classes
BaseServiceEndpointHealthMonitor
Bases: BaseTypedModel
Base class used for service endpoint health monitors.
Attributes:
Name | Type | Description |
---|---|---|
config |
ServiceEndpointHealthMonitorConfig
|
health monitor configuration for endpoint |
check_endpoint_status(endpoint: BaseServiceEndpoint) -> Tuple[ServiceState, str]
abstractmethod
Check the the current operational state of the external service endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint
|
BaseServiceEndpoint
|
service endpoint to check |
required |
This method should be overridden by subclasses that implement concrete service endpoint tracking functionality.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external service endpoint and an |
str
|
optional error message, if an error is encountered while checking |
Tuple[ServiceState, str]
|
the service endpoint status. |
Source code in src/zenml/services/service_monitor.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
HTTPEndpointHealthMonitor
Bases: BaseServiceEndpointHealthMonitor
HTTP service endpoint health monitor.
Attributes:
Name | Type | Description |
---|---|---|
config |
HTTPEndpointHealthMonitorConfig
|
health monitor configuration for HTTP endpoint |
check_endpoint_status(endpoint: BaseServiceEndpoint) -> Tuple[ServiceState, str]
Run a HTTP endpoint API healthcheck.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint
|
BaseServiceEndpoint
|
service endpoint to check. |
required |
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external HTTP endpoint and an |
str
|
optional message describing that state (e.g. an error message, |
Tuple[ServiceState, str]
|
if an error is encountered while checking the HTTP endpoint |
Tuple[ServiceState, str]
|
status). |
Source code in src/zenml/services/service_monitor.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
get_healthcheck_uri(endpoint: BaseServiceEndpoint) -> Optional[str]
Get the healthcheck URI for the given service endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint
|
BaseServiceEndpoint
|
service endpoint to get the healthcheck URI for |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
The healthcheck URI for the given service endpoint or None, if |
Optional[str]
|
the service endpoint doesn't have a healthcheck URI. |
Source code in src/zenml/services/service_monitor.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
HTTPEndpointHealthMonitorConfig
Bases: ServiceEndpointHealthMonitorConfig
HTTP service endpoint health monitor configuration.
Attributes:
Name | Type | Description |
---|---|---|
healthcheck_uri_path |
str
|
URI subpath to use to perform service endpoint healthchecks. If not set, the service endpoint URI will be used instead. |
use_head_request |
bool
|
set to True to use a HEAD request instead of a GET when calling the healthcheck URI. |
http_status_code |
int
|
HTTP status code to expect in the health check response. |
http_timeout |
int
|
HTTP health check request timeout in seconds. |
ServiceEndpointHealthMonitorConfig
Bases: BaseTypedModel
Generic service health monitor configuration.
Concrete service classes should extend this class and add additional attributes that they want to see reflected and use in the health monitor configuration.
TCPEndpointHealthMonitor
Bases: BaseServiceEndpointHealthMonitor
TCP service endpoint health monitor.
Attributes:
Name | Type | Description |
---|---|---|
config |
TCPEndpointHealthMonitorConfig
|
health monitor configuration for TCP endpoint |
check_endpoint_status(endpoint: BaseServiceEndpoint) -> Tuple[ServiceState, str]
Run a TCP endpoint healthcheck.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint
|
BaseServiceEndpoint
|
service endpoint to check. |
required |
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the external TCP endpoint and an |
str
|
optional message describing that state (e.g. an error message, |
Tuple[ServiceState, str]
|
if an error is encountered while checking the TCP endpoint |
Tuple[ServiceState, str]
|
status). |
Source code in src/zenml/services/service_monitor.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
TCPEndpointHealthMonitorConfig
Functions
service_status
Implementation of the ServiceStatus class.
Classes
ServiceStatus
Bases: BaseTypedModel
Information about the status of a service or process.
This information describes the operational status of an external process or service tracked by ZenML. This could be a process, container, Kubernetes deployment etc.
Concrete service classes should extend this class and add additional attributes that make up the operational state of the service.
Attributes:
Name | Type | Description |
---|---|---|
state |
ServiceState
|
the current operational state |
last_state |
ServiceState
|
the operational state prior to the last status update |
last_error |
str
|
the error encountered during the last status update |
clear_error() -> None
Clear the last error message.
Source code in src/zenml/services/service_status.py
64 65 66 |
|
update_state(new_state: Optional[ServiceState] = None, error: str = '') -> None
Update the current operational state to reflect a new state value and/or error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_state
|
Optional[ServiceState]
|
new operational state discovered by the last service status update |
None
|
error
|
str
|
error message describing an operational failure encountered during the last service status update |
''
|
Source code in src/zenml/services/service_status.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|