Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Dependency updates

### Bundles
* Add support for alerts to DABs ([#4004](https://github.com/databricks/cli/pull/4004))
* Allow `file://` URIs in job libraries to reference runtime filesystem paths (e.g., JARs pre-installed on clusters via init scripts). These paths are no longer treated as local files to upload. ([#3884](https://github.com/databricks/cli/pull/3884))

### API Changes
7 changes: 0 additions & 7 deletions acceptance/bundle/deployment/bind/alert/alert.json

This file was deleted.

29 changes: 29 additions & 0 deletions acceptance/bundle/deployment/bind/alert/alert.json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"display_name": "test-alert-$UNIQUE_NAME",
"query_text": "SELECT 1",
"warehouse_id": "$TEST_DEFAULT_WAREHOUSE_ID",
"custom_summary": "Test Alert Summary",
"custom_description": "Test Alert Description",
"evaluation": {
"comparison_operator": "EQUAL",
"notification": {
"notify_on_ok": false,
"retrigger_seconds": 1
},
"source": {
"aggregation": "MAX",
"display": "1",
"name": "1"
},
"threshold": {
"value": {
"double_value": 1
}
}
},
"schedule": {
"pause_status": "UNPAUSED",
"quartz_cron_schedule": "0 0 * * * ?",
"timezone_id": "UTC"
}
}
8 changes: 0 additions & 8 deletions acceptance/bundle/deployment/bind/alert/databricks.yml

This file was deleted.

19 changes: 19 additions & 0 deletions acceptance/bundle/deployment/bind/alert/databricks.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
bundle:
name: test-bind-alert-$UNIQUE_NAME

resources:
alerts:
my_alert:
display_name: test-alert
evaluation:
comparison_operator: EQUAL
source:
name: "1"
threshold:
value:
double_value: 2
query_text: select 2
schedule:
quartz_cron_schedule: "44 19 */1 * * ?"
timezone_id: Europe/Amsterdam
warehouse_id: aaaaaaaaaaaaaaaa
5 changes: 4 additions & 1 deletion acceptance/bundle/deployment/bind/alert/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions acceptance/bundle/deployment/bind/alert/output.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@

>>> [CLI] alerts-v2 create-alert --json @alert.json

>>> [CLI] bundle deployment bind my_alert [UUID] --auto-approve
>>> [CLI] bundle deployment bind my_alert [ALERT_ID] --auto-approve
Updating deployment state...
Successfully bound alert with an id '[UUID]'
Successfully bound alert with an id '[ALERT_ID]'
Run 'bundle deploy' to deploy changes to your workspace

>>> [CLI] bundle summary
Name: test-bundle-$UNIQUE_NAME
Name: test-bind-alert-[UNIQUE_NAME]
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle-$UNIQUE_NAME/default
Path: /Workspace/Users/[USERNAME]/.bundle/test-bind-alert-[UNIQUE_NAME]/default
Resources:
Alerts:
my_alert:
Name: test-alert
URL: [DATABRICKS_URL]/sql/alerts-v2/[UUID]?o=[NUMID]
URL: [DATABRICKS_URL]/sql/alerts-v2/[ALERT_ID]

>>> [CLI] bundle deployment unbind my_alert
Updating deployment state...

>>> [CLI] bundle summary
Name: test-bundle-$UNIQUE_NAME
Name: test-bind-alert-[UNIQUE_NAME]
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle-$UNIQUE_NAME/default
Path: /Workspace/Users/[USERNAME]/.bundle/test-bind-alert-[UNIQUE_NAME]/default
Resources:
Alerts:
my_alert:
Expand Down
4 changes: 4 additions & 0 deletions acceptance/bundle/deployment/bind/alert/script
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
envsubst < databricks.yml.tmpl > databricks.yml
envsubst < alert.json.tmpl > alert.json

alert_id=$(trace $CLI alerts-v2 create-alert --json @alert.json | jq -r '.id')
echo "$alert_id:ALERT_ID" >> ACC_REPLS
trace $CLI bundle deployment bind my_alert $alert_id --auto-approve
trace $CLI bundle summary

Expand Down
12 changes: 10 additions & 2 deletions acceptance/bundle/deployment/bind/alert/test.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Cloud = false
Local = false # Enable when releasing support for alerts.
Cloud = true
Local = false

BundleConfigTarget = "databricks.yml"

# On aws the host URL includes the workspace ID as well. Thus skipping it to keep the test simple.
CloudEnvs.aws = false

Ignore = [
"databricks.yml",
"alert.json",
]
7 changes: 7 additions & 0 deletions acceptance/bundle/refschema/out.fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ resources.alerts.*.schedule.timezone_id string ALL
resources.alerts.*.update_time string ALL
resources.alerts.*.url string INPUT
resources.alerts.*.warehouse_id string ALL
resources.alerts.*.permissions.object_id string ALL
resources.alerts.*.permissions.permissions []iam.AccessControlRequest ALL
resources.alerts.*.permissions.permissions[*] iam.AccessControlRequest ALL
resources.alerts.*.permissions.permissions[*].group_name string ALL
resources.alerts.*.permissions.permissions[*].permission_level iam.PermissionLevel ALL
resources.alerts.*.permissions.permissions[*].service_principal_name string ALL
resources.alerts.*.permissions.permissions[*].user_name string ALL
resources.apps.*.active_deployment *apps.AppDeployment ALL
resources.apps.*.active_deployment.create_time string ALL
resources.apps.*.active_deployment.creator string ALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ resources:
alerts:
myalert:
permissions:
- level: CAN_RUN
group_name: users
- level: CAN_MANAGE
user_name: deco-test-user@databricks.com

custom_summary: "My alert"
display_name: "My alert"
Expand All @@ -27,4 +27,4 @@ resources:
pause_status: "UNPAUSED"
quartz_cron_schedule: "44 19 */1 * * ?"
timezone_id: "Europe/Amsterdam"
warehouse_id: "dd43ee29fedd958d"
warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID
2 changes: 1 addition & 1 deletion acceptance/bundle/resources/alerts/basic/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 71 additions & 13 deletions acceptance/bundle/resources/alerts/basic/output.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,80 @@

>>> [CLI] bundle deploy
Warning: unknown field: alerts
at resources
in databricks.yml:5:3

Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/alerts-basic-[UNIQUE_NAME]/default/files...
Deploying resources...
Updating deployment state...
Deployment complete!
Warning: unknown field: alerts
at resources
in databricks.yml:5:3

>>> [CLI] alerts-v2 get-alert [ALERT_ID]
{
"display_name": "My alert",
"lifecycle_state": "ACTIVE",
"custom_summary": "My alert",
"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": "[TEST_DEFAULT_WAREHOUSE_ID]"
}

=== assert that permissions are applied
>>> [CLI] permissions get alertsv2 [ALERT_ID]
{
"user_name": "deco-test-user@databricks.com",
"all_permissions": [
{
"inherited": false,
"permission_level": "CAN_MANAGE"
}
]
}

=== assert that no permanent drift happens
>>> [CLI] bundle plan
Plan: 0 to add, 0 to change, 0 to delete, 2 unchanged

>>> [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.alerts.myalert

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/alerts-basic-[UNIQUE_NAME]/default

>>> [CLI] alerts-v2 get-alert null
Warning: unknown field: alerts
at resources
in databricks.yml:5:3
Deleting files...
Destroy complete!

Error: Resource sql.AlertV2 not found: null
>>> [CLI] alerts-v2 get-alert [ALERT_ID]
{
"display_name": "My alert",
"lifecycle_state": "DELETED"
}

Exit code: 1
>>> [CLI] bundle summary
Name: alerts-basic-[UNIQUE_NAME]
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/alerts-basic-[UNIQUE_NAME]/default
Resources:
Alerts:
myalert:
Name: My alert
URL: (not deployed)
10 changes: 8 additions & 2 deletions acceptance/bundle/resources/alerts/basic/script
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ trace $CLI bundle deploy

alert_id=$($CLI bundle summary --output json | jq -r '.resources.alerts.myalert.id')

trace $CLI alerts-v2 get-alert $alert_id | jq '{display_name, lifecycle_state}'
echo "$alert_id:ALERT_ID" >> ACC_REPLS

trace $CLI alerts-v2 get-alert $alert_id | jq '{display_name, lifecycle_state, custom_summary, evaluation, query_text, schedule, warehouse_id}'

title "assert that permissions are applied"
trace $CLI permissions get alertsv2 $alert_id | jq ".access_control_list.[]" -c | grep 'deco-test-user@databricks.com' | jq '{user_name, all_permissions}'

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}'
title "assert that no permanent drift happens"
trace $CLI bundle plan

trace $CLI bundle destroy --auto-approve

Expand Down
2 changes: 1 addition & 1 deletion acceptance/bundle/resources/alerts/basic/test.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Local = true
Cloud = false
Cloud = true
RecordRequests = false
Ignore = [".databricks"]
16 changes: 12 additions & 4 deletions acceptance/bundle/summary/modified_status/databricks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ resources:
alerts:
my_alert:
display_name: test-alert
query_text: "SELECT 1"
warehouse_id: "test-sql-warehouse"
custom_summary: "test-alert-summary"
custom_description: "test-alert-description"
evaluation:
comparison_operator: EQUAL
source:
name: "1"
threshold:
value:
double_value: 2
query_text: select 2
schedule:
quartz_cron_schedule: "44 19 */1 * * ?"
timezone_id: Europe/Amsterdam
warehouse_id: aaaaaaaaaaaaaaaa
Loading