Services
Initialization of the ZenML services module.
A service is a process or set of processes that outlive a pipeline run.
BaseService
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 |
Source code in src/zenml/services/service.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 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 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 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 490 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 |
|
is_failed
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
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
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. |
__init__(**attrs)
Initialize the service instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**attrs
|
Any
|
keyword arguments. |
{}
|
Source code in src/zenml/services/service.py
187 188 189 190 191 192 193 194 195 196 197 |
|
__repr__()
String representation of the service.
Returns:
Type | Description |
---|---|
str
|
A string representation of the service. |
Source code in src/zenml/services/service.py
509 510 511 512 513 514 515 |
|
__str__()
String representation of the service.
Returns:
Type | Description |
---|---|
str
|
A string representation of the service. |
Source code in src/zenml/services/service.py
517 518 519 520 521 522 523 |
|
check_status()
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
242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
deprovision(force=False)
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
411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
from_json(json_str)
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
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
from_model(model)
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
199 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 |
|
get_healthcheck_url()
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
496 497 498 499 500 501 502 503 504 505 506 507 |
|
get_logs(follow=False, tail=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
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
get_prediction_url()
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
481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
|
get_service_status_message()
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
309 310 311 312 313 314 315 316 317 318 319 320 |
|
poll_service_status(timeout=0)
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
322 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 |
|
provision()
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
401 402 403 404 405 406 407 408 409 |
|
start(timeout=0)
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
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
|
stop(timeout=0, force=False)
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
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 |
|
update(config)
Update the service configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
ServiceConfig
|
the new service configuration. |
required |
Source code in src/zenml/services/service.py
426 427 428 429 430 431 432 |
|
update_status()
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
273 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 |
|
BaseServiceEndpoint
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 |
Source code in src/zenml/services/service_endpoint.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 |
|
__init__(*args, **kwargs)
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
110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
check_status()
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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
is_active()
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
157 158 159 160 161 162 163 164 165 166 167 168 |
|
is_inactive()
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
170 171 172 173 174 175 176 177 178 179 180 181 |
|
update_status()
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
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
BaseServiceEndpointHealthMonitor
Bases: BaseTypedModel
Base class used for service endpoint health monitors.
Attributes:
Name | Type | Description |
---|---|---|
config |
ServiceEndpointHealthMonitorConfig
|
health monitor configuration for endpoint |
Source code in src/zenml/services/service_monitor.py
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 |
|
check_endpoint_status(endpoint)
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
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/container/container_service.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 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 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 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 490 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 531 532 533 534 535 536 537 538 539 |
|
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
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
property
Initialize and/or return the docker client.
Returns:
Type | Description |
---|---|
DockerClient
|
The docker client. |
check_status()
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
211 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 |
|
deprovision(force=False)
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
482 483 484 485 486 487 488 |
|
get_logs(follow=False, tail=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
490 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 |
|
get_service_status_message()
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
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
provision()
Provision the service.
Source code in src/zenml/services/container/container_service.py
478 479 480 |
|
run()
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
531 532 533 534 535 536 537 538 539 |
|
ContainerServiceConfig
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/container/container_service.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
ContainerServiceEndpoint
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/container/container_service_endpoint.py
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
prepare_for_start()
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. |
Source code in src/zenml/services/container/container_service_endpoint.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
ContainerServiceEndpointStatus
Bases: ServiceEndpointStatus
Local daemon service endpoint status.
Source code in src/zenml/services/container/container_service_endpoint.py
58 59 |
|
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 |
Source code in src/zenml/services/container/container_service.py
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 98 99 100 101 102 103 104 105 |
|
config_file
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
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 |
Source code in src/zenml/services/service_monitor.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 |
|
check_endpoint_status(endpoint)
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)
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. |
Source code in src/zenml/services/service_monitor.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
LocalDaemonService
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/local/local_service.py
190 191 192 193 194 195 196 197 198 199 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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 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 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 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 490 491 492 493 494 495 496 497 498 |
|
check_status()
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
272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
deprovision(force=False)
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
428 429 430 431 432 433 434 |
|
get_logs(follow=False, tail=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
449 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 |
|
get_service_status_message()
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
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
provision()
Provision the service.
Source code in src/zenml/services/local/local_service.py
424 425 426 |
|
run()
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
490 491 492 493 494 495 496 497 498 |
|
start(timeout=0)
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
436 437 438 439 440 441 442 443 444 445 446 447 |
|
LocalDaemonServiceConfig
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/local/local_service.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
LocalDaemonServiceEndpoint
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/local/local_service_endpoint.py
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
prepare_for_start()
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. |
Source code in src/zenml/services/local/local_service_endpoint.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
LocalDaemonServiceEndpointStatus
Bases: ServiceEndpointStatus
Local daemon service endpoint status.
Source code in src/zenml/services/local/local_service_endpoint.py
61 62 |
|
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). |
Source code in src/zenml/services/local/local_service.py
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 185 186 187 |
|
config_file
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
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
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
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
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. |
Source code in src/zenml/services/service.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 |
|
__init__(**data)
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
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
get_service_labels()
Get the service labels.
Returns:
Type | Description |
---|---|
Dict[str, str]
|
a dictionary of service labels. |
Source code in src/zenml/services/service.py
148 149 150 151 152 153 154 155 156 157 158 |
|
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 |
Source code in src/zenml/services/service_endpoint.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
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.
Source code in src/zenml/services/service_monitor.py
37 38 39 40 41 42 43 |
|
ServiceEndpointProtocol
Bases: StrEnum
Possible endpoint protocol values.
Source code in src/zenml/services/service_endpoint.py
28 29 30 31 32 33 |
|
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 |
Source code in src/zenml/services/service_endpoint.py
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 |
|
uri
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
Bases: StrEnum
Possible states for the service and service endpoint.
Source code in src/zenml/services/service_status.py
25 26 27 28 29 30 31 32 33 |
|
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 |
Source code in src/zenml/services/service_status.py
36 37 38 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 |
|
clear_error()
Clear the last error message.
Source code in src/zenml/services/service_status.py
75 76 77 |
|
update_state(new_state=None, error='')
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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
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 |
Source code in src/zenml/services/service_type.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
TCPEndpointHealthMonitor
Bases: BaseServiceEndpointHealthMonitor
TCP service endpoint health monitor.
Attributes:
Name | Type | Description |
---|---|---|
config |
TCPEndpointHealthMonitorConfig
|
health monitor configuration for TCP endpoint |
Source code in src/zenml/services/service_monitor.py
191 192 193 194 195 196 197 198 199 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 |
|
check_endpoint_status(endpoint)
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
Bases: ServiceEndpointHealthMonitorConfig
TCP service endpoint health monitor configuration.
Source code in src/zenml/services/service_monitor.py
187 188 |
|