Skip to content

Commit 10a9275

Browse files
Add example for alerts in YAML (#135)
1 parent 9470825 commit 10a9275

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

knowledge_base/alerts/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SQL Alerts with Databricks Asset Bundles
2+
3+
This example shows how to define SQL alerts using Databricks Asset Bundles. The alert monitors daily NYC Taxi revenue and triggers when it exceeds a threshold.
4+
5+
For more information about SQL alerts, see the [Databricks documentation](https://docs.databricks.com/aws/en/sql/user/alerts/).
6+
7+
## Usage
8+
9+
1. Modify `databricks.yml`:
10+
- Update the `host` field to your Databricks workspace URL
11+
- Update the `warehouse` field to the name of your SQL warehouse
12+
13+
2. Modify `resources/nyc_taxi_daily_revenue.alert.yml`:
14+
- Update the `user_name` field under `permissions` to your email address
15+
16+
3. Deploy the alert:
17+
```sh
18+
databricks bundle deploy
19+
```
20+
21+
## Key Configuration
22+
23+
The alert configuration in `resources/nyc_taxi_daily_revenue.alert.yml` includes:
24+
25+
- **query_text**: SQL query that returns the metric to monitor
26+
- **evaluation**: Defines how to evaluate the query results
27+
- `comparison_operator`: GREATER_THAN, LESS_THAN, EQUAL, etc.
28+
- `source.aggregation`: MAX, MIN, AVG, or SUM
29+
- `threshold.value`: The value to compare against
30+
- **schedule**: Uses Quartz cron syntax (e.g., `"0 0 8 * * ?"` for daily at 8 AM)
31+
- **warehouse_id**: The SQL warehouse to execute the query
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
bundle:
2+
name: alerts
3+
4+
include:
5+
- resources/*.yml
6+
7+
variables:
8+
# The "warehouse_id" variable is used to reference the warehouse used by the alert.
9+
warehouse_id:
10+
lookup:
11+
# Replace this with the name of your SQL warehouse.
12+
warehouse: "Shared Unity Catalog Severless"
13+
14+
workspace:
15+
host: https://myworkspace.databricks.com
16+
17+
18+
targets:
19+
dev:
20+
default: true
21+
mode: development
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
resources:
2+
alerts:
3+
nyc_taxi_daily_revenue:
4+
permissions:
5+
- level: CAN_MANAGE
6+
user_name: user@company.com
7+
8+
custom_summary: "Alert when NYC Taxi daily revenue exceeds threshold"
9+
display_name: "NYC Taxi Daily Revenue Alert"
10+
11+
# The SQL query that the alert will evaluate
12+
query_text: |
13+
SELECT
14+
to_date(tpep_pickup_datetime) as date,
15+
SUM(fare_amount) as amount
16+
FROM
17+
`samples`.`nyctaxi`.`trips`
18+
GROUP BY
19+
ALL
20+
ORDER BY
21+
1 DESC
22+
23+
# The warehouse to use for running the query
24+
warehouse_id: ${var.warehouse_id}
25+
26+
evaluation:
27+
# Comparison operator for the threshold
28+
comparison_operator: "GREATER_THAN"
29+
30+
# Notification settings
31+
notification:
32+
notify_on_ok: false
33+
retrigger_seconds: 3600 # Re-trigger after 1 hour if condition persists
34+
35+
# Source defines which column and aggregation to evaluate
36+
source:
37+
aggregation: "MAX"
38+
display: "amount"
39+
name: "amount"
40+
41+
# Threshold to compare against
42+
threshold:
43+
value:
44+
double_value: 1000000.0 # Alert if daily revenue exceeds $1M
45+
46+
# Schedule for running the alert
47+
schedule:
48+
pause_status: "UNPAUSED"
49+
quartz_cron_schedule: "0 0 8 * * ?" # Run daily at 8 AM UTC
50+
timezone_id: "UTC"

0 commit comments

Comments
 (0)