Skip to content

Commit 825581a

Browse files
Add relative path translation for alert_task.workspace_path in job tasks
Co-authored-by: Isaac
1 parent 9ded3b0 commit 825581a

File tree

9 files changed

+115
-0
lines changed

9 files changed

+115
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bundle:
2+
name: alert-task-$UNIQUE_NAME
3+
4+
resources:
5+
jobs:
6+
my_job:
7+
name: alert-task-$UNIQUE_NAME
8+
tasks:
9+
- task_key: alert_task
10+
alert_task:
11+
workspace_path: ./my_alert.dbalert.json
12+
warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"query_lines": ["SELECT 1"],
3+
"schedule": {
4+
"quartz_cron_schedule": "0 0 * * * ?",
5+
"timezone_id": "UTC"
6+
},
7+
"evaluation": {
8+
"comparison_operator": "EQUAL",
9+
"source": {
10+
"name": "1",
11+
"aggregation": "MAX"
12+
},
13+
"threshold": {
14+
"value": {
15+
"double_value": 1
16+
}
17+
}
18+
}
19+
}

acceptance/bundle/resources/jobs/alert-task/out.test.toml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/alert-task-[UNIQUE_NAME]/default/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
>>> [CLI] jobs get [JOB_ID]
9+
{
10+
"warehouse_id": "[TEST_DEFAULT_WAREHOUSE_ID]",
11+
"workspace_path": "/Workspace/Users/[USERNAME]/.bundle/alert-task-[UNIQUE_NAME]/default/files/my_alert.dbalert.json"
12+
}
13+
14+
>>> [CLI] bundle destroy --auto-approve
15+
The following resources will be deleted:
16+
delete resources.jobs.my_job
17+
18+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/alert-task-[UNIQUE_NAME]/default
19+
20+
Deleting files...
21+
Destroy complete!
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
envsubst < databricks.yml.tmpl > databricks.yml
2+
3+
cleanup() {
4+
trace $CLI bundle destroy --auto-approve
5+
}
6+
trap cleanup EXIT
7+
8+
trace $CLI bundle deploy
9+
10+
job_id=$($CLI bundle summary -o json | jq -r '.resources.jobs.my_job.id')
11+
echo "$job_id:JOB_ID" >> ACC_REPLS
12+
13+
trace $CLI jobs get $job_id | jq '.settings.tasks[0].alert_task'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Badness = "Terraform provider does not yet support alert_task. Enable terraform engine once the provider version is bumped."
2+
Local = true
3+
Cloud = true
4+
RecordRequests = false
5+
Ignore = ["databricks.yml", ".databricks"]
6+
7+
[EnvMatrix]
8+
DATABRICKS_BUNDLE_ENGINE = ["direct"]
9+
10+
[Env]
11+
MSYS_NO_PATHCONV = "1"

bundle/config/mutator/paths/job_paths_visitor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func jobTaskRewritePatterns(base dyn.Pattern) []jobRewritePattern {
3636
TranslateModeFile,
3737
noSkipRewrite,
3838
},
39+
{
40+
base.Append(dyn.Key("alert_task"), dyn.Key("workspace_path")),
41+
TranslateModeFile,
42+
noSkipRewrite,
43+
},
3944
{
4045
base.Append(dyn.Key("libraries"), dyn.AnyIndex(), dyn.Key("requirements")),
4146
TranslateModeFile,

bundle/config/mutator/paths/job_paths_visitor_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func TestVisitJobPaths(t *testing.T) {
4949
{Requirements: "requirements.txt"},
5050
},
5151
}
52+
task7 := jobs.Task{
53+
AlertTask: &jobs.AlertTask{
54+
WorkspacePath: "abc",
55+
},
56+
}
5257

5358
job0 := &resources.Job{
5459
JobSettings: jobs.JobSettings{
@@ -60,6 +65,7 @@ func TestVisitJobPaths(t *testing.T) {
6065
task4,
6166
task5,
6267
task6,
68+
task7,
6369
},
6470
},
6571
}
@@ -79,6 +85,7 @@ func TestVisitJobPaths(t *testing.T) {
7985
dyn.MustPathFromString("resources.jobs.job0.tasks[2].dbt_task.project_directory"),
8086
dyn.MustPathFromString("resources.jobs.job0.tasks[3].sql_task.file.path"),
8187
dyn.MustPathFromString("resources.jobs.job0.tasks[6].libraries[0].requirements"),
88+
dyn.MustPathFromString("resources.jobs.job0.tasks[7].alert_task.workspace_path"),
8289
}
8390

8491
assert.ElementsMatch(t, expected, actual)
@@ -125,10 +132,20 @@ func TestVisitJobPaths_foreach(t *testing.T) {
125132
},
126133
},
127134
}
135+
task1 := jobs.Task{
136+
ForEachTask: &jobs.ForEachTask{
137+
Task: jobs.Task{
138+
AlertTask: &jobs.AlertTask{
139+
WorkspacePath: "abc",
140+
},
141+
},
142+
},
143+
}
128144
job0 := &resources.Job{
129145
JobSettings: jobs.JobSettings{
130146
Tasks: []jobs.Task{
131147
task0,
148+
task1,
132149
},
133150
},
134151
}
@@ -144,6 +161,7 @@ func TestVisitJobPaths_foreach(t *testing.T) {
144161
actual := collectVisitedPaths(t, root, VisitJobPaths)
145162
expected := []dyn.Path{
146163
dyn.MustPathFromString("resources.jobs.job0.tasks[0].for_each_task.task.notebook_task.notebook_path"),
164+
dyn.MustPathFromString("resources.jobs.job0.tasks[1].for_each_task.task.alert_task.workspace_path"),
147165
}
148166

149167
assert.ElementsMatch(t, expected, actual)

bundle/config/mutator/translate_paths_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ func TestTranslatePathsInSubdirectories(t *testing.T) {
290290
touchEmptyFile(t, filepath.Join(dir, "pipeline", "my_python_file.py"))
291291
touchEmptyFile(t, filepath.Join(dir, "job", "my_sql_file.sql"))
292292
touchEmptyFile(t, filepath.Join(dir, "job", "my_dbt_project", "dbt_project.yml"))
293+
touchEmptyFile(t, filepath.Join(dir, "job", "my_alert.dbalert.json"))
293294

294295
b := &bundle.Bundle{
295296
SyncRootPath: dir,
@@ -329,6 +330,11 @@ func TestTranslatePathsInSubdirectories(t *testing.T) {
329330
ProjectDirectory: "./my_dbt_project",
330331
},
331332
},
333+
{
334+
AlertTask: &jobs.AlertTask{
335+
WorkspacePath: "./my_alert.dbalert.json",
336+
},
337+
},
332338
},
333339
},
334340
},
@@ -376,6 +382,11 @@ func TestTranslatePathsInSubdirectories(t *testing.T) {
376382
"/bundle/job/my_dbt_project",
377383
b.Config.Resources.Jobs["job"].Tasks[3].DbtTask.ProjectDirectory,
378384
)
385+
assert.Equal(
386+
t,
387+
"/bundle/job/my_alert.dbalert.json",
388+
b.Config.Resources.Jobs["job"].Tasks[4].AlertTask.WorkspacePath,
389+
)
379390

380391
assert.Equal(
381392
t,

0 commit comments

Comments
 (0)