Alerter
zenml.alerter
special
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.
alerter_step
alerter_step (BaseStep)
Post a given message to the registered alerter component of the active stack.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
Runtime configuration for the slack alerter. |
required | |
context |
StepContext of the ZenML repository. |
required | |
message |
Message to be posted. |
required |
Returns:
Type | Description |
---|---|
True if operation succeeded, else False. |
CONFIG_CLASS (BaseStepConfig)
pydantic-model
Step config definition for all alerters.
Source code in zenml/alerter/alerter_step.py
class BaseAlerterStepConfig(BaseStepConfig):
"""Step config definition for all alerters."""
entrypoint(config, context, message)
staticmethod
Post a given message to the registered alerter component of the active stack.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
BaseAlerterStepConfig |
Runtime configuration for the slack alerter. |
required |
context |
StepContext |
StepContext of the ZenML repository. |
required |
message |
str |
Message to be posted. |
required |
Returns:
Type | Description |
---|---|
bool |
True if operation succeeded, else False. |
Source code in zenml/alerter/alerter_step.py
@step
def alerter_step(
config: BaseAlerterStepConfig, context: StepContext, message: str
) -> bool:
"""Post a given message to the registered alerter component of the
active stack.
Args:
config: Runtime configuration for the slack alerter.
context: StepContext of the ZenML repository.
message: Message to be posted.
Returns:
True if operation succeeded, else False.
Raises:
ValueError if active stack has no slack alerter.
"""
# TODO: duplicate code with examples/feast_feature_store/run.py
if not context.stack:
raise DoesNotExistException(
"No active stack is available. "
"Please make sure that you have registered and set a stack."
)
if not context.stack.alerter:
raise ValueError(
"The active stack needs to have an alerter component registered "
"to be able to use `alerter_step`. "
"You can create a new stack with e.g. a Slack alerter component or update "
"your existing stack to add this component, e.g.:\n\n"
" 'zenml alerter register slack_alerter --flavor=slack' ...\n"
" 'zenml stack register stack-name -al slack_alerter ...'\n"
)
return context.stack.alerter.post(message, config)
base_alerter
BaseAlerter (StackComponent, ABC)
pydantic-model
Base class for all ZenML alerters.
Source code in zenml/alerter/base_alerter.py
class BaseAlerter(StackComponent, ABC):
"""Base class for all ZenML alerters."""
# Class configuration
TYPE: ClassVar[StackComponentType] = StackComponentType.ALERTER
FLAVOR: ClassVar[str]
def post(
self, message: str, config: Optional[BaseAlerterStepConfig]
) -> bool:
"""Post a message to some ChatOps service.
Args:
message: Message to be posted.
config: Optional runtime configuration of this function.
Returns:
True if operation succeeded, else False
"""
return True
def ask(
self, question: str, config: Optional[BaseAlerterStepConfig]
) -> Any:
"""Ask a question and get a synchronous response.
Args:
question: Question to ask.
config: Optional runtime configuration of this function.
Returns:
The response from the request.
"""
return None
ask(self, question, config)
Ask a question and get a synchronous response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
question |
str |
Question to ask. |
required |
config |
Optional[zenml.steps.step_interfaces.base_alerter_step.BaseAlerterStepConfig] |
Optional runtime configuration of this function. |
required |
Returns:
Type | Description |
---|---|
Any |
The response from the request. |
Source code in zenml/alerter/base_alerter.py
def ask(
self, question: str, config: Optional[BaseAlerterStepConfig]
) -> Any:
"""Ask a question and get a synchronous response.
Args:
question: Question to ask.
config: Optional runtime configuration of this function.
Returns:
The response from the request.
"""
return None
post(self, message, config)
Post a message to some ChatOps service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str |
Message to be posted. |
required |
config |
Optional[zenml.steps.step_interfaces.base_alerter_step.BaseAlerterStepConfig] |
Optional runtime configuration of this function. |
required |
Returns:
Type | Description |
---|---|
bool |
True if operation succeeded, else False |
Source code in zenml/alerter/base_alerter.py
def post(
self, message: str, config: Optional[BaseAlerterStepConfig]
) -> bool:
"""Post a message to some ChatOps service.
Args:
message: Message to be posted.
config: Optional runtime configuration of this function.
Returns:
True if operation succeeded, else False
"""
return True