Skip to content

Commit

Permalink
Add ability to subscribe to dashboards & alert SQL tasks in `databric…
Browse files Browse the repository at this point in the history
…ks_job`

It's now possible to subscribe to updates of individual dashboards & alerts in the SQL
tasks of Databricks Workflows

This fixes #2436
  • Loading branch information
alexott committed Jul 5, 2023
1 parent 2a6de53 commit 1e4e691
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
35 changes: 33 additions & 2 deletions docs/resources/job.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,15 @@ One of the `query`, `dashboard` or `alert` needs to be provided.
* `warehouse_id` - (Required) ID of the (the [databricks_sql_endpoint](sql_endpoint.md)) that will be used to execute the task. Only Serverless & Pro warehouses are supported right now.
* `parameters` - (Optional) (Map) parameters to be used for each run of this task. The SQL alert task does not support custom parameters.
* `query` - (Optional) block consisting of single string field: `query_id` - identifier of the Databricks SQL Query ([databricks_sql_query](sql_query.md)).
* `dashboard` - (Optional) block consisting of single string field: `dashboard_id` - identifier of the Databricks SQL Dashboard [databricks_sql_dashboard](sql_dashboard.md).
* `alert` - (Optional) block consisting of single string field: `alert_id` - identifier of the Databricks SQL Alert.
* `dashboard` - (Optional) block consisting of following fields:
* `dashboard_id` - (Required) (String) identifier of the Databricks SQL Dashboard [databricks_sql_dashboard](sql_dashboard.md).
* `subscriptions` - (Optional) a list of subscription blocks consisting out of one of the required fields: `user_name` for user emails or `destination_id` - for Alert destination's identifier.
* `custom_subject` - (Optional) string specifying a custom subject of email sent.
* `pause_subscriptions` - (Optional) flag that specifies if subscriptions are paused or not.
* `alert` - (Optional) block consisting of following fields:
* `alert_id` - (Required) (String) identifier of the Databricks SQL Alert.
* `subscriptions` - (Required) a list of subscription blocks consisting out of one of the required fields: `user_name` for user emails or `destination_id` - for Alert destination's identifier.
* `pause_subscriptions` - (Optional) flag that specifies if subscriptions are paused or not.
* `file` - (Optional) block consisting of single string field: `path` - a relative path to the file (inside the Git repository) with SQL commands to execute. *Requires `git_source` configuration block*.

Example
Expand All @@ -272,6 +279,30 @@ resource "databricks_job" "sql_aggregation_job" {
}
}
}
task {
task_key = "run_dashboard"
sql_task {
warehouse_id = databricks_sql_endpoint.sql_job_warehouse.id
dashboard {
dashboard_id = databricks_sql_dashboard.dash.id
subscriptions {
user_name = "user@domain.com"
}
}
}
}
task {
task_key = "run_alert"
sql_task {
warehouse_id = databricks_sql_endpoint.sql_job_warehouse.id
alert {
alert_id = databricks_sql_alert.alert.id
subscriptions {
user_name = "user@domain.com"
}
}
}
}
}
```

Expand Down
14 changes: 12 additions & 2 deletions jobs/resource_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,22 @@ type SqlQueryTask struct {
QueryID string `json:"query_id"`
}

type SqlSubscription struct {
UserName string `json:"user_name,omitempty"`
DestinationID string `json:"destination_id,omitempty"`
}

type SqlDashboardTask struct {
DashboardID string `json:"dashboard_id"`
DashboardID string `json:"dashboard_id"`
Subscriptions []SqlSubscription `json:"subscriptions,omitempty"`
CustomSubject string `json:"custom_subject,omitempty"`
PauseSubscriptions bool `json:"pause_subscriptions,omitempty"`
}

type SqlAlertTask struct {
AlertID string `json:"alert_id"`
AlertID string `json:"alert_id"`
Subscriptions []SqlSubscription `json:"subscriptions"`
PauseSubscriptions bool `json:"pause_subscriptions,omitempty"`
}

type SqlFileTask struct {
Expand Down

0 comments on commit 1e4e691

Please sign in to comment.