SlackAlerter enables you to send messages to a dedicated Slack channel directly from within your pipelines.
The slack integration also contains the following two standard steps:
-
slack_alerter_post_step takes a string, posts it to Slack, and returns
Trueif the operation succeeded, elseFalse. -
slack_alerter_ask_step does the same as
slack_alerter_post_step, but after sending the message, it waits until someone approves or rejects the operation from within Slack (e.g., by sending “approve” / “reject” to the bot in response).slack_alerter_ask_stepthen only returnsTrueif the operation succeeded and was approved, elseFalse.
-
The
slack_alerter_post_stepallows you to get notified immediately when failures happen (e.g., model performance degradation, data drift, …), -
The
slack_alerter_ask_stepallows you to integrate a human-in-the-loop into your pipelines before executing critical steps, such as deploying new models.
How to use it
Requirements
Before you can use theSlackAlerter, you first need to install ZenML’s slack integration:
Setting Up a Slack Bot
In order to use theSlackAlerter, you first need to have a Slack workspace set up with a channel that you want your pipelines to post to.
Then, you need to create a Slack App with a bot in your workspace.
Make sure to give your Slack bot chat:write and chat:write.public permissions in the OAuth & Permissions tab under Scopes.
Registering a Slack Alerter in ZenML
Next, you need to register aslack alerter in ZenML and link it to the bot you just created. You can do this with the following command:
-
<SLACK_CHANNEL_ID>: Open your desired Slack channel in a browser, and copy out the last part of the URL starting withC..... -
<SLACK_TOKEN>: This is the Slack token of your bot. You can find it in the Slack app settings underOAuth & Permissions.
slack_alerter, you can add it to your stack like this:
How to Use the Slack Alerter
After you have aSlackAlerter configured in your stack, you can directly import the slack_alerter_post_step and slack_alerter_ask_step steps and use them in your pipelines.
Since these steps expect a string message as input (which needs to be the output of another step), you typically also need to define a dedicated formatter step that takes whatever data you want to communicate and generates the string message that the alerter should post.
As an example, adding slack_alerter_ask_step() into your pipeline could look like this: