Skip to content

Alerter

zenml.alerter

Alerters allow you to send alerts from within your pipeline.

This is useful to immediately get notified when failures happen, and also for general monitoring / reporting.

Attributes

__all__ = ['BaseAlerter', 'BaseAlerterConfig', 'BaseAlerterFlavor', 'BaseAlerterStepParameters'] module-attribute

Classes

BaseAlerter(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)

Bases: StackComponent, ABC

Base class for all ZenML alerters.

Source code in src/zenml/stack/stack_component.py
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
def __init__(
    self,
    name: str,
    id: UUID,
    config: StackComponentConfig,
    flavor: str,
    type: StackComponentType,
    user: Optional[UUID],
    created: datetime,
    updated: datetime,
    labels: Optional[Dict[str, Any]] = None,
    connector_requirements: Optional[ServiceConnectorRequirements] = None,
    connector: Optional[UUID] = None,
    connector_resource_id: Optional[str] = None,
    *args: Any,
    **kwargs: Any,
):
    """Initializes a StackComponent.

    Args:
        name: The name of the component.
        id: The unique ID of the component.
        config: The config of the component.
        flavor: The flavor of the component.
        type: The type of the component.
        user: The ID of the user who created the component.
        created: The creation time of the component.
        updated: The last update time of the component.
        labels: The labels of the component.
        connector_requirements: The requirements for the connector.
        connector: The ID of a connector linked to the component.
        connector_resource_id: The custom resource ID to access through
            the connector.
        *args: Additional positional arguments.
        **kwargs: Additional keyword arguments.

    Raises:
        ValueError: If a secret reference is passed as name.
    """
    if secret_utils.is_secret_reference(name):
        raise ValueError(
            "Passing the `name` attribute of a stack component as a "
            "secret reference is not allowed."
        )

    self.id = id
    self.name = name
    self._config = config
    self.flavor = flavor
    self.type = type
    self.user = user
    self.created = created
    self.updated = updated
    self.labels = labels
    self.connector_requirements = connector_requirements
    self.connector = connector
    self.connector_resource_id = connector_resource_id
    self._connector_instance: Optional[ServiceConnector] = None
Attributes
config: BaseAlerterConfig property

Returns the BaseAlerterConfig config.

Returns:

Type Description
BaseAlerterConfig

The configuration.

Functions
ask(question: str, params: Optional[BaseAlerterStepParameters] = None) -> bool

Post a message to a chat service and wait for approval.

This can be useful to easily get a human in the loop, e.g., when deploying models.

Parameters:

Name Type Description Default
question str

Question to ask (message to be posted).

required
params Optional[BaseAlerterStepParameters]

Optional parameters of this function.

None

Returns:

Name Type Description
bool bool

True if operation succeeded and was approved, else False.

Source code in src/zenml/alerter/base_alerter.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def ask(
    self, question: str, params: Optional[BaseAlerterStepParameters] = None
) -> bool:
    """Post a message to a chat service and wait for approval.

    This can be useful to easily get a human in the loop, e.g., when
    deploying models.

    Args:
        question: Question to ask (message to be posted).
        params: Optional parameters of this function.

    Returns:
        bool: True if operation succeeded and was approved, else False.
    """
    return True
post(message: str, params: Optional[BaseAlerterStepParameters] = None) -> bool

Post a message to a chat service.

Parameters:

Name Type Description Default
message str

Message to be posted.

required
params Optional[BaseAlerterStepParameters]

Optional parameters of this function.

None

Returns:

Name Type Description
bool bool

True if operation succeeded, else False.

Source code in src/zenml/alerter/base_alerter.py
46
47
48
49
50
51
52
53
54
55
56
57
58
def post(
    self, message: str, params: Optional[BaseAlerterStepParameters] = None
) -> bool:
    """Post a message to a chat service.

    Args:
        message: Message to be posted.
        params: Optional parameters of this function.

    Returns:
        bool: True if operation succeeded, else False.
    """
    return True

BaseAlerterConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)

Bases: StackComponentConfig

Base config for alerters.

Source code in src/zenml/stack/stack_component.py
 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
 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
def __init__(
    self, warn_about_plain_text_secrets: bool = False, **kwargs: Any
) -> None:
    """Ensures that secret references don't clash with pydantic validation.

    StackComponents allow the specification of all their string attributes
    using secret references of the form `{{secret_name.key}}`. This however
    is only possible when the stack component does not perform any explicit
    validation of this attribute using pydantic validators. If this were
    the case, the validation would run on the secret reference and would
    fail or in the worst case, modify the secret reference and lead to
    unexpected behavior. This method ensures that no attributes that require
    custom pydantic validation are set as secret references.

    Args:
        warn_about_plain_text_secrets: If true, then warns about using
            plain-text secrets.
        **kwargs: Arguments to initialize this stack component.

    Raises:
        ValueError: If an attribute that requires custom pydantic validation
            is passed as a secret reference, or if the `name` attribute
            was passed as a secret reference.
    """
    for key, value in kwargs.items():
        try:
            field = self.__class__.model_fields[key]
        except KeyError:
            # Value for a private attribute or non-existing field, this
            # will fail during the upcoming pydantic validation
            continue

        if value is None:
            continue

        if not secret_utils.is_secret_reference(value):
            if (
                secret_utils.is_secret_field(field)
                and warn_about_plain_text_secrets
            ):
                logger.warning(
                    "You specified a plain-text value for the sensitive "
                    f"attribute `{key}` for a `{self.__class__.__name__}` "
                    "stack component. This is currently only a warning, "
                    "but future versions of ZenML will require you to pass "
                    "in sensitive information as secrets. Check out the "
                    "documentation on how to configure your stack "
                    "components with secrets here: "
                    "https://docs.zenml.io/getting-started/deploying-zenml/secret-management"
                )
            continue

        if pydantic_utils.has_validators(
            pydantic_class=self.__class__, field_name=key
        ):
            raise ValueError(
                f"Passing the stack component attribute `{key}` as a "
                "secret reference is not allowed as additional validation "
                "is required for this attribute."
            )

    super().__init__(**kwargs)

BaseAlerterFlavor

Bases: Flavor, ABC

Base class for all ZenML alerter flavors.

Attributes
config_class: Type[BaseAlerterConfig] property

Returns BaseAlerterConfig class.

Returns:

Type Description
Type[BaseAlerterConfig]

The BaseAlerterConfig class.

implementation_class: Type[BaseAlerter] property

Implementation class.

Returns:

Type Description
Type[BaseAlerter]

The implementation class.

type: StackComponentType property

Returns the flavor type.

Returns:

Type Description
StackComponentType

The flavor type.

BaseAlerterStepParameters

Bases: BaseModel

Step parameters definition for all alerters.

Modules

base_alerter

Base class for all ZenML alerters.

Classes
BaseAlerter(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)

Bases: StackComponent, ABC

Base class for all ZenML alerters.

Source code in src/zenml/stack/stack_component.py
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
def __init__(
    self,
    name: str,
    id: UUID,
    config: StackComponentConfig,
    flavor: str,
    type: StackComponentType,
    user: Optional[UUID],
    created: datetime,
    updated: datetime,
    labels: Optional[Dict[str, Any]] = None,
    connector_requirements: Optional[ServiceConnectorRequirements] = None,
    connector: Optional[UUID] = None,
    connector_resource_id: Optional[str] = None,
    *args: Any,
    **kwargs: Any,
):
    """Initializes a StackComponent.

    Args:
        name: The name of the component.
        id: The unique ID of the component.
        config: The config of the component.
        flavor: The flavor of the component.
        type: The type of the component.
        user: The ID of the user who created the component.
        created: The creation time of the component.
        updated: The last update time of the component.
        labels: The labels of the component.
        connector_requirements: The requirements for the connector.
        connector: The ID of a connector linked to the component.
        connector_resource_id: The custom resource ID to access through
            the connector.
        *args: Additional positional arguments.
        **kwargs: Additional keyword arguments.

    Raises:
        ValueError: If a secret reference is passed as name.
    """
    if secret_utils.is_secret_reference(name):
        raise ValueError(
            "Passing the `name` attribute of a stack component as a "
            "secret reference is not allowed."
        )

    self.id = id
    self.name = name
    self._config = config
    self.flavor = flavor
    self.type = type
    self.user = user
    self.created = created
    self.updated = updated
    self.labels = labels
    self.connector_requirements = connector_requirements
    self.connector = connector
    self.connector_resource_id = connector_resource_id
    self._connector_instance: Optional[ServiceConnector] = None
Attributes
config: BaseAlerterConfig property

Returns the BaseAlerterConfig config.

Returns:

Type Description
BaseAlerterConfig

The configuration.

Functions
ask(question: str, params: Optional[BaseAlerterStepParameters] = None) -> bool

Post a message to a chat service and wait for approval.

This can be useful to easily get a human in the loop, e.g., when deploying models.

Parameters:

Name Type Description Default
question str

Question to ask (message to be posted).

required
params Optional[BaseAlerterStepParameters]

Optional parameters of this function.

None

Returns:

Name Type Description
bool bool

True if operation succeeded and was approved, else False.

Source code in src/zenml/alerter/base_alerter.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def ask(
    self, question: str, params: Optional[BaseAlerterStepParameters] = None
) -> bool:
    """Post a message to a chat service and wait for approval.

    This can be useful to easily get a human in the loop, e.g., when
    deploying models.

    Args:
        question: Question to ask (message to be posted).
        params: Optional parameters of this function.

    Returns:
        bool: True if operation succeeded and was approved, else False.
    """
    return True
post(message: str, params: Optional[BaseAlerterStepParameters] = None) -> bool

Post a message to a chat service.

Parameters:

Name Type Description Default
message str

Message to be posted.

required
params Optional[BaseAlerterStepParameters]

Optional parameters of this function.

None

Returns:

Name Type Description
bool bool

True if operation succeeded, else False.

Source code in src/zenml/alerter/base_alerter.py
46
47
48
49
50
51
52
53
54
55
56
57
58
def post(
    self, message: str, params: Optional[BaseAlerterStepParameters] = None
) -> bool:
    """Post a message to a chat service.

    Args:
        message: Message to be posted.
        params: Optional parameters of this function.

    Returns:
        bool: True if operation succeeded, else False.
    """
    return True
BaseAlerterConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)

Bases: StackComponentConfig

Base config for alerters.

Source code in src/zenml/stack/stack_component.py
 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
 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
def __init__(
    self, warn_about_plain_text_secrets: bool = False, **kwargs: Any
) -> None:
    """Ensures that secret references don't clash with pydantic validation.

    StackComponents allow the specification of all their string attributes
    using secret references of the form `{{secret_name.key}}`. This however
    is only possible when the stack component does not perform any explicit
    validation of this attribute using pydantic validators. If this were
    the case, the validation would run on the secret reference and would
    fail or in the worst case, modify the secret reference and lead to
    unexpected behavior. This method ensures that no attributes that require
    custom pydantic validation are set as secret references.

    Args:
        warn_about_plain_text_secrets: If true, then warns about using
            plain-text secrets.
        **kwargs: Arguments to initialize this stack component.

    Raises:
        ValueError: If an attribute that requires custom pydantic validation
            is passed as a secret reference, or if the `name` attribute
            was passed as a secret reference.
    """
    for key, value in kwargs.items():
        try:
            field = self.__class__.model_fields[key]
        except KeyError:
            # Value for a private attribute or non-existing field, this
            # will fail during the upcoming pydantic validation
            continue

        if value is None:
            continue

        if not secret_utils.is_secret_reference(value):
            if (
                secret_utils.is_secret_field(field)
                and warn_about_plain_text_secrets
            ):
                logger.warning(
                    "You specified a plain-text value for the sensitive "
                    f"attribute `{key}` for a `{self.__class__.__name__}` "
                    "stack component. This is currently only a warning, "
                    "but future versions of ZenML will require you to pass "
                    "in sensitive information as secrets. Check out the "
                    "documentation on how to configure your stack "
                    "components with secrets here: "
                    "https://docs.zenml.io/getting-started/deploying-zenml/secret-management"
                )
            continue

        if pydantic_utils.has_validators(
            pydantic_class=self.__class__, field_name=key
        ):
            raise ValueError(
                f"Passing the stack component attribute `{key}` as a "
                "secret reference is not allowed as additional validation "
                "is required for this attribute."
            )

    super().__init__(**kwargs)
BaseAlerterFlavor

Bases: Flavor, ABC

Base class for all ZenML alerter flavors.

Attributes
config_class: Type[BaseAlerterConfig] property

Returns BaseAlerterConfig class.

Returns:

Type Description
Type[BaseAlerterConfig]

The BaseAlerterConfig class.

implementation_class: Type[BaseAlerter] property

Implementation class.

Returns:

Type Description
Type[BaseAlerter]

The implementation class.

type: StackComponentType property

Returns the flavor type.

Returns:

Type Description
StackComponentType

The flavor type.

BaseAlerterStepParameters

Bases: BaseModel

Step parameters definition for all alerters.