LogoLogo
ProductResourcesGitHubStart free
  • Documentation
  • Learn
  • ZenML Pro
  • Stacks
  • API Reference
  • SDK Reference
  • Overview
  • Integrations
  • Stack Components
    • Orchestrators
      • Local Orchestrator
      • Local Docker Orchestrator
      • Kubeflow Orchestrator
      • Kubernetes Orchestrator
      • Google Cloud VertexAI Orchestrator
      • AWS Sagemaker Orchestrator
      • AzureML Orchestrator
      • Databricks Orchestrator
      • Tekton Orchestrator
      • Airflow Orchestrator
      • Skypilot VM Orchestrator
      • HyperAI Orchestrator
      • Lightning AI Orchestrator
      • Develop a custom orchestrator
    • Artifact Stores
      • Local Artifact Store
      • Amazon Simple Cloud Storage (S3)
      • Google Cloud Storage (GCS)
      • Azure Blob Storage
      • Develop a custom artifact store
    • Container Registries
      • Default Container Registry
      • DockerHub
      • Amazon Elastic Container Registry (ECR)
      • Google Cloud Container Registry
      • Azure Container Registry
      • GitHub Container Registry
      • Develop a custom container registry
    • Step Operators
      • Amazon SageMaker
      • AzureML
      • Google Cloud VertexAI
      • Kubernetes
      • Modal
      • Spark
      • Develop a Custom Step Operator
    • Experiment Trackers
      • Comet
      • MLflow
      • Neptune
      • Weights & Biases
      • Google Cloud VertexAI Experiment Tracker
      • Develop a custom experiment tracker
    • Image Builders
      • Local Image Builder
      • Kaniko Image Builder
      • AWS Image Builder
      • Google Cloud Image Builder
      • Develop a Custom Image Builder
    • Alerters
      • Discord Alerter
      • Slack Alerter
      • Develop a Custom Alerter
    • Annotators
      • Argilla
      • Label Studio
      • Pigeon
      • Prodigy
      • Develop a Custom Annotator
    • Data Validators
      • Great Expectations
      • Deepchecks
      • Evidently
      • Whylogs
      • Develop a custom data validator
    • Feature Stores
      • Feast
      • Develop a Custom Feature Store
    • Model Deployers
      • MLflow
      • Seldon
      • BentoML
      • Hugging Face
      • Databricks
      • vLLM
      • Develop a Custom Model Deployer
    • Model Registries
      • MLflow Model Registry
      • Develop a Custom Model Registry
  • Service Connectors
    • Introduction
    • Complete guide
    • Best practices
    • Connector Types
      • Docker Service Connector
      • Kubernetes Service Connector
      • AWS Service Connector
      • GCP Service Connector
      • Azure Service Connector
      • HyperAI Service Connector
  • Popular Stacks
    • AWS
    • Azure
    • GCP
    • Kubernetes
  • Deployment
    • 1-click Deployment
    • Terraform Modules
    • Register a cloud stack
    • Infrastructure as code
  • Contribute
    • Custom Stack Component
    • Custom Integration
Powered by GitBook
On this page
  • Base Abstraction
  • Building your own custom alerter

Was this helpful?

Edit on GitHub
  1. Stack Components
  2. Alerters

Develop a Custom Alerter

Learning how to develop a custom alerter.

PreviousSlack AlerterNextAnnotators

Last updated 1 month ago

Was this helpful?

Before diving into the specifics of this component type, it is beneficial to familiarize yourself with our . This guide provides an essential understanding of ZenML's component flavor concepts.

Base Abstraction

The base abstraction for alerters is very basic, as it only defines two abstract methods that subclasses should implement:

  • post() takes a string, posts it to the desired chat service, and returns True if the operation succeeded, else False.

  • ask() does the same as post(), but after sending the message, it waits until someone approves or rejects the operation from within the chat service (e.g., by sending "approve" / "reject" to the bot as a response). ask() then only returns True if the operation succeeded and was approved, else False.

Then base abstraction looks something like this:

class BaseAlerter(StackComponent, ABC):
    """Base class for all ZenML alerters."""

    def post(
            self, message: str, params: Optional[BaseAlerterStepParameters]
    ) -> bool:
        """Post a message to a chat service."""
        return True

    def ask(
            self, question: str, params: Optional[BaseAlerterStepParameters]
    ) -> bool:
        """Post a message to a chat service and wait for approval."""
        return True

Building your own custom alerter

Creating your own custom alerter can be done in three steps:

  1. Create a class that inherits from the BaseAlerter and implement the post() and ask() methods.

    from typing import Optional
    
    from zenml.alerter import BaseAlerter, BaseAlerterStepParameters
    
    
    class MyAlerter(BaseAlerter):
        """My alerter class."""
    
        def post(
            self, message: str, config: Optional[BaseAlerterStepParameters]
        ) -> bool:
            """Post a message to a chat service."""
            ...
            return "Hey, I implemented an alerter."
    
        def ask(
            self, question: str, config: Optional[BaseAlerterStepParameters]
        ) -> bool:
            """Post a message to a chat service and wait for approval."""
            ...
            return True
  2. If you need to configure your custom alerter, you can also implement a config object.

    from zenml.alerter.base_alerter import BaseAlerterConfig
    
    
    class MyAlerterConfig(BaseAlerterConfig):
        my_param: str 
  3. Finally, you can bring the implementation and the configuration together in a new flavor object.

    from typing import Type, TYPE_CHECKING
    
    from zenml.alerter import BaseAlerterFlavor
    
    if TYPE_CHECKING:
        from zenml.stack import StackComponent, StackComponentConfig
    
    
    class MyAlerterFlavor(BaseAlerterFlavor):
        @property
        def name(self) -> str:
            return "my_alerter"
    
        @property
        def config_class(self) -> Type[StackComponentConfig]:
            from my_alerter_config import MyAlerterConfig
    
            return MyAlerterConfig
    
        @property
        def implementation_class(self) -> Type[StackComponent]:
            from my_alerter import MyAlerter
    
            return MyAlerter
    

Once you are done with the implementation, you can register your new flavor through the CLI. Please ensure you point to the flavor class via dot notation:

zenml alerter flavor register <path.to.MyAlerterFlavor>

For example, if your flavor class MyAlerterFlavor is defined in flavors/my_flavor.py, you'd register it by doing:

zenml alerter flavor register flavors.my_flavor.MyAlerterFlavor

If ZenML does not find an initialized ZenML repository in any parent directory, it will default to the current working directory, but usually, it's better to not have to rely on this mechanism and initialize zenml at the root.

Afterward, you should see the new custom alerter flavor in the list of available alerter flavors:

zenml alerter flavor list

It is important to draw attention to when and how these abstractions are coming into play in a ZenML workflow.

  • The MyAlerterFlavor class is imported and utilized upon the creation of the custom flavor through the CLI.

  • The MyAlerterConfig class is imported when someone tries to register/update a stack component with the my_alerter flavor. Especially, during the registration process of the stack component, the config will be used to validate the values given by the user. As Config objects are inherently pydantic objects, you can also add your own custom validators here.

  • The MyAlerter only comes into play when the component is ultimately in use.

The design behind this interaction lets us separate the configuration of the flavor from its implementation. This way we can register flavors and components even when the major dependencies behind their implementation are not installed in our local setting (assuming the MyAlerterFlavor and the MyAlerterConfig are implemented in a different module/path than the actual MyAlerter).

This is a slimmed-down version of the base implementation. To see the full docstrings and imports, please check .

ZenML resolves the flavor class by taking the path where you initialized zenml (via zenml init) as the starting point of resolution. Therefore, please ensure you follow of initializing zenml at the root of your repository.

general guide to writing custom component flavors in ZenML
the source code on GitHub
the best practice
ZenML Scarf