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
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ linters:
- legacy
- std-error-handling
rules:
- path-except: bundle/direct/dresources
- path-except: bundle/direct/dresources|bundle/config/mutator/load_dbalert_files.go
linters:
- exhaustruct
- path: bundle/direct/dresources/.*_test.go
Expand Down
1 change: 1 addition & 0 deletions acceptance/bundle/refschema/out.fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ resources.alerts.*.evaluation.threshold.value *sql.AlertV2OperandValue ALL
resources.alerts.*.evaluation.threshold.value.bool_value bool ALL
resources.alerts.*.evaluation.threshold.value.double_value float64 ALL
resources.alerts.*.evaluation.threshold.value.string_value string ALL
resources.alerts.*.file_path string INPUT
resources.alerts.*.id string ALL
resources.alerts.*.lifecycle resources.Lifecycle INPUT
resources.alerts.*.lifecycle.prevent_destroy bool INPUT
Expand Down
32 changes: 32 additions & 0 deletions acceptance/bundle/resources/alerts/with_file/alert.dbalert.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"custom_summary": "My alert from file",
"evaluation": {
"source": {
"name": "1",
"display": "1",
"aggregation": "MAX"
},
"comparison_operator": "EQUAL",
"threshold": {
"value": {
"double_value": 2.0
}
},
"notification": {
"retrigger_seconds": 1,
"notify_on_ok": false
}
},
"schedule": {
"quartz_cron_schedule": "44 19 */1 * * ?",
"timezone_id": "Europe/Amsterdam"
},
"query_lines": [
"select 2"
],
"custom_description_lines": [
"My alert from file",
"with multiple lines",
"and a third line"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: alerts-with-file-$UNIQUE_NAME

resources:
alerts:
myalert:
warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID
display_name: "myalert"
file_path: ./alert.dbalert.json
5 changes: 5 additions & 0 deletions acceptance/bundle/resources/alerts/with_file/out.test.toml

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

100 changes: 100 additions & 0 deletions acceptance/bundle/resources/alerts/with_file/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@

>>> [CLI] bundle validate -o json
{
"custom_description": "My alert from file\nwith multiple lines\nand a third line\n",
"custom_summary": "My alert from file",
"display_name": "myalert",
"evaluation": {
"comparison_operator": "EQUAL",
"notification": {
"notify_on_ok": false,
"retrigger_seconds": 1
},
"source": {
"aggregation": "MAX",
"display": "1",
"name": "1"
},
"threshold": {
"value": {
"double_value": 2
}
}
},
"file_path": "alert.dbalert.json",
"parent_path": "/Workspace/Users/[USERNAME]/.bundle/alerts-with-file-[UNIQUE_NAME]/default/resources",
"query_text": "select 2\n",
"schedule": {
"quartz_cron_schedule": "44 19 */1 * * ?",
"timezone_id": "Europe/Amsterdam"
},
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
}

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/alerts-with-file-[UNIQUE_NAME]/default/files...
Deploying resources...
Updating deployment state...
Deployment complete!

>>> [CLI] alerts-v2 get-alert [ALERT_ID]
{
"display_name": "myalert",
"lifecycle_state": "ACTIVE",
"custom_summary": "My alert from file",
"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\n",
"schedule": {
"quartz_cron_schedule": "44 19 */1 * * ?",
"timezone_id": "Europe/Amsterdam"
},
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]"
}

=== assert that the uploaded alert file is the same as the local one
>>> [CLI] workspace export /Workspace/Users/[USERNAME]/.bundle/alerts-with-file-[UNIQUE_NAME]/default/resources/myalert.dbalert.json

>>> diff exported_alert.dbalert.json alert.dbalert.json --strip-trailing-cr

>>> [CLI] alerts-v2 get-alert [ALERT_ID]
{
"display_name": "myalert",
"lifecycle_state": "ACTIVE"
}

>>> [CLI] bundle summary
Name: alerts-with-file-[UNIQUE_NAME]
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/alerts-with-file-[UNIQUE_NAME]/default
Resources:
Alerts:
myalert:
Name: myalert
URL: [DATABRICKS_URL]/sql/alerts-v2/[ALERT_ID]

>>> [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-with-file-[UNIQUE_NAME]/default

Deleting files...
Destroy complete!
27 changes: 27 additions & 0 deletions acceptance/bundle/resources/alerts/with_file/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
envsubst < databricks.yml.tmpl > databricks.yml


cleanup() {
trace $CLI bundle destroy --auto-approve
}
trap cleanup EXIT

trace $CLI bundle validate -o json | jq .resources.alerts.myalert

trace $CLI bundle deploy

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

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}'

alert_path=$($CLI bundle summary --output json | jq -r '.resources.alerts.myalert.parent_path')/myalert.dbalert.json
title "assert that the uploaded alert file is the same as the local one"
trace $CLI workspace export $alert_path > exported_alert.dbalert.json
trace diff exported_alert.dbalert.json alert.dbalert.json --strip-trailing-cr
rm exported_alert.dbalert.json

trace $CLI alerts-v2 get-alert $alert_id | jq '{display_name, lifecycle_state}'

trace $CLI bundle summary
19 changes: 19 additions & 0 deletions acceptance/bundle/resources/alerts/with_file/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Local = false
Cloud = true
RecordRequests = false
Ignore = [".databricks"]

# redact ?o=[NUMID]. Different clouds can have different URL serialization, like [DATABRICKS_URL]/sql/alerts-v2/[ALERT_ID] vs [DATABRICKS_URL]/sql/alerts-v2/[ALERT_ID]?o=[NUMID].
[[Repls]]
Old = '\?o=\d+'
New = ''
Order = 0

[EnvMatrix]
DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"]

[Env]
# MSYS2 automatically converts absolute paths like /Users/$username/$UNIQUE_NAME to
# C:/Program Files/Git/Users/$username/UNIQUE_NAME before passing it to the CLI
# Setting this environment variable prevents that conversion on windows.
MSYS_NO_PATHCONV = "1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"custom_summary": "My alert from file",
"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_lines": [
"select 2"
],
"custom_description_lines": [
"My alert from file",
"with multiple lines",
"and a third line"
],
"schedule": {
"pause_status": "UNPAUSED",
"quartz_cron_schedule": "44 19 */1 * * ?",
"timezone_id": "Europe/Amsterdam"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bundle:
name: alerts-not-allowed-field

resources:
alerts:
myalert:
warehouse_id: "0123456789012345"
display_name: "My alert"
file_path: ./alert.dbalert.json
# This field is not allowed when file_path is specified

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future: We should allow override of the query text even when using a file_path, unless there will be another way to accept parameters like {catalog} and {schema} in the alert file.

query_text: "select 3"

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

>>> trace [CLI] bundle validate

>>> [CLI] bundle validate
Error: field query_text is not allowed in the bundle configuration.
at resources.alerts.myalert.query_text
in databricks.yml:11:19

When a .dbalert.json is specified, only the following fields are allowed in the bundle configuration: warehouse_id, display_name, file_path, permissions, lifecycle

Name: alerts-not-allowed-field
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/alerts-not-allowed-field/default

Found 1 error

Exit code: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
errcode trace trace $CLI bundle validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Local = true
RecordRequests = false
Ignore = [".databricks"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"custom_summary": "Alert for ${var.target}",
"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_lines": [
"select 2"
],
"custom_description_lines": [
"Alert for ${var.target}",
"with multiple lines",
"and a third line"
],
"schedule": {
"pause_status": "UNPAUSED",
"quartz_cron_schedule": "44 19 */1 * * ?",
"timezone_id": "Europe/Amsterdam"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: alerts-variable-error

resources:
alerts:
myalert:
warehouse_id: "0123456789012345"
display_name: "My alert"
file_path: ./alert.dbalert.json

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

>>> [CLI] bundle validate
Error: .alert file alert.dbalert.json must not contain variable interpolations.
at resources.alerts.myalert.file_path
in databricks.yml:9:18

Please inline the alert configuration in the bundle configuration to use variables

Name: alerts-variable-error
Target: default
Workspace:
User: [USERNAME]
Path: /Workspace/Users/[USERNAME]/.bundle/alerts-variable-error/default

Found 1 error

Exit code: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
errcode trace $CLI bundle validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Local = true
RecordRequests = false
Ignore = [".databricks"]
Loading