Skip to content

Commit 87a3046

Browse files
Add support for SQL Alerts in DABs (#3033)
## Changes This PR adds support for SQL alerts to DABs. A follow-up will add support for .dbalert.json files. ## Why #1615 Users can now define an alert in the DAB with syntax like: ``` bundle: name: alerts-basic-$UNIQUE_NAME resources: alerts: myalert: permissions: - level: CAN_RUN group_name: users custom_summary: "My alert" display_name: "My alert $UNIQUE_NAME" evaluation: comparison_operator: "EQUAL" notification: notify_on_ok: false retrigger_seconds: 1 source: aggregation: "MAX" display: "1" name: "1" threshold: value: double_value: 2 query_text: "select 2" schedule: pause_status: "UNPAUSED" quartz_cron_schedule: "44 19 */1 * * ?" timezone_id: "Europe/Amsterdam" warehouse_id: "dd43ee29fedd958d" ``` ## Tests Manually. And acceptance tests.
1 parent fd14d40 commit 87a3046

File tree

47 files changed

+1517
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1517
-2
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Release v0.269.0
44

55
### Notable Changes
6+
* Add support for SQL Alerts in DABs ([#3033](https://github.com/databricks/cli/pull/3033))
67

78
### CLI
89

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
bundle:
2+
name: alerts-basic-$UNIQUE_NAME
3+
4+
resources:
5+
alerts:
6+
myalert:
7+
permissions:
8+
- level: CAN_RUN
9+
group_name: users
10+
11+
custom_summary: "My alert"
12+
display_name: "My alert"
13+
evaluation:
14+
comparison_operator: "EQUAL"
15+
notification:
16+
notify_on_ok: false
17+
retrigger_seconds: 1
18+
source:
19+
aggregation: "MAX"
20+
display: "1"
21+
name: "1"
22+
threshold:
23+
value:
24+
double_value: 2
25+
query_text: "select 2"
26+
schedule:
27+
pause_status: "UNPAUSED"
28+
quartz_cron_schedule: "44 19 */1 * * ?"
29+
timezone_id: "Europe/Amsterdam"
30+
warehouse_id: "dd43ee29fedd958d"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = false
2+
Cloud = true
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/alerts-basic-[UNIQUE_NAME]/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> [CLI] alerts-v2 get-alert [NUMID]
9+
{
10+
"display_name": "My alert",
11+
"lifecycle_state": "ACTIVE"
12+
}
13+
14+
>>> [CLI] permissions get alertsv2 [NUMID]
15+
{
16+
"access_control_list": [
17+
{
18+
"all_permissions": [
19+
{
20+
"inherited": false,
21+
"permission_level": "CAN_RUN"
22+
}
23+
],
24+
"group_name": "users"
25+
}
26+
],
27+
"object_id": "/alertsv2/[NUMID]",
28+
"object_type": "alertv2"
29+
}
30+
31+
>>> [CLI] bundle destroy --auto-approve
32+
The following resources will be deleted:
33+
delete alert myalert
34+
35+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/alerts-basic-[UNIQUE_NAME]/default
36+
37+
Deleting files...
38+
Destroy complete!
39+
40+
>>> [CLI] alerts-v2 get-alert [NUMID]
41+
{
42+
"display_name": "My alert",
43+
"lifecycle_state": "TRASHED"
44+
}
45+
46+
>>> [CLI] bundle summary
47+
Name: alerts-basic-[UNIQUE_NAME]
48+
Target: default
49+
Workspace:
50+
User: [USERNAME]
51+
Path: /Workspace/Users/[USERNAME]/.bundle/alerts-basic-[UNIQUE_NAME]/default
52+
Resources:
53+
Alerts:
54+
myalert:
55+
Name: My alert
56+
URL: (not deployed)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
envsubst < databricks.yml.tmpl > databricks.yml
2+
3+
trace $CLI bundle deploy
4+
5+
alert_id=$($CLI bundle summary --output json | jq -r '.resources.alerts.myalert.id')
6+
7+
trace $CLI alerts-v2 get-alert $alert_id | jq '{display_name, lifecycle_state}'
8+
9+
trace $CLI permissions get alertsv2 $alert_id | jq '{access_control_list: [.access_control_list[] | select(any(.all_permissions[]; .permission_level == "CAN_RUN"))], object_id, object_type}'
10+
11+
trace $CLI bundle destroy --auto-approve
12+
13+
trace $CLI alerts-v2 get-alert $alert_id | jq '{display_name, lifecycle_state}'
14+
15+
trace $CLI bundle summary
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Cloud = true
2+
Local = false
3+
4+
# Permissions with alerts does not work with direct deployment yet.
5+
# So we skip this test on direct-exp until we have permissions support in
6+
# direct deployment.
7+
[EnvMatrix]
8+
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"display_name": "Test Alert",
3+
"query_text": "SELECT 1",
4+
"warehouse_id": "0123-456789-warehouse0",
5+
"custom_summary": "Test Alert Summary",
6+
"custom_description": "Test Alert Description"
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resources:
2+
alerts:
3+
my_alert:
4+
display_name: test-alert
5+
query_text: "SELECT 1"
6+
warehouse_id: "test-sql-warehouse"
7+
custom_summary: "test-alert-summary"
8+
custom_description: "test-alert-description"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
>>> [CLI] alerts-v2 create-alert --json @alert.json
3+
4+
>>> [CLI] bundle deployment bind my_alert [UUID] --auto-approve
5+
Updating deployment state...
6+
Successfully bound alert with an id '[UUID]'. Run 'bundle deploy' to deploy changes to your workspace
7+
8+
>>> [CLI] bundle summary
9+
Name: test-bundle-$UNIQUE_NAME
10+
Target: default
11+
Workspace:
12+
User: [USERNAME]
13+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle-$UNIQUE_NAME/default
14+
Resources:
15+
Alerts:
16+
my_alert:
17+
Name: test-alert
18+
URL: [DATABRICKS_URL]/sql/alerts-v2/[UUID]?o=[NUMID]
19+
20+
>>> [CLI] bundle deployment unbind my_alert
21+
Updating deployment state...
22+
23+
>>> [CLI] bundle summary
24+
Name: test-bundle-$UNIQUE_NAME
25+
Target: default
26+
Workspace:
27+
User: [USERNAME]
28+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle-$UNIQUE_NAME/default
29+
Resources:
30+
Alerts:
31+
my_alert:
32+
Name: test-alert
33+
URL: (not deployed)

0 commit comments

Comments
 (0)