Skip to content

Commit

Permalink
Docs/Updated for slack alerts. (#1042)
Browse files Browse the repository at this point in the history
* Updated for slack alerts.

* Updated

* Updated with production example

* updated

* Updated chess production

* Updated
  • Loading branch information
dat-a-man authored Mar 5, 2024
1 parent 483d4ae commit cfb1f91
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/website/docs/examples/chess_production/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ def load_data_with_retry(pipeline, data):
```
<!--@@@DLT_SNIPPET_END ./code/chess-snippets.py::markdown_retry_cm-->

:::warning
To run this example you need to provide Slack incoming hook in `.dlt/secrets.toml`:
```python
[runtime]
slack_incoming_hook="https://hooks.slack.com/services/***"
```
Read [Using Slack to send messages.](https://dlthub.com/docs/running-in-production/running#using-slack-to-send-messages)
:::

### Run the pipeline

<!--@@@DLT_SNIPPET_START ./code/chess-snippets.py::markdown_pipeline-->
Expand Down
32 changes: 30 additions & 2 deletions docs/website/docs/running-in-production/alerting.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,33 @@ receiving rich information on executed pipelines, including encountered errors a

## Slack

Read [here](./running#using-slack-to-send-messages) about how to send
messages to Slack.
Alerts can be sent to a Slack channel via Slack's incoming webhook URL. The code snippet below demonstrates automated Slack notifications for database table updates using the `send_slack_message` function.

```python
# Import the send_slack_message function from the dlt library
from dlt.common.runtime.slack import send_slack_message

# Define the URL for your Slack webhook
hook = "https://hooks.slack.com/services/xxx/xxx/xxx"

# Iterate over each package in the load_info object
for package in info.load_packages:
# Iterate over each table in the schema_update of the current package
for table_name, table in package.schema_update.items():
# Iterate over each column in the current table
for column_name, column in table["columns"].items():
# Send a message to the Slack channel with the table
# and column update information
send_slack_message(
hook,
message=(
f"\tTable updated: {table_name}: "
f"Column changed: {column_name}: "
f"{column['data_type']}"
)
)
```
Refer to this [example](../../docs/examples/chess_production/) for a practical application of the method in a production environment.

Similarly, Slack notifications can be extended to include information on pipeline execution times, loading durations, schema modifications, and more. For comprehensive details on configuring and sending messages to Slack, please read [here](./running#using-slack-to-send-messages).

0 comments on commit cfb1f91

Please sign in to comment.