Skip to content

Commit 7bcabc7

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

File tree

10 files changed

+108
-0
lines changed

10 files changed

+108
-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
3+
4+
resources:
5+
jobs:
6+
my_job:
7+
name: my_job
8+
tasks:
9+
- task_key: alert_task
10+
alert_task:
11+
workspace_path: ./my_alert.dbalert.json
12+
warehouse_id: cafef00d
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"method": "GET",
3+
"path": "/.well-known/databricks-config"
4+
}
5+
{
6+
"method": "GET",
7+
"path": "/api/2.0/preview/scim/v2/Me"
8+
}
9+
{
10+
"method": "GET",
11+
"path": "/api/2.0/workspace/get-status",
12+
"q": {
13+
"path": "/Workspace/Users/[USERNAME]/.bundle/alert-task/default/files"
14+
}
15+
}
16+
{
17+
"method": "POST",
18+
"path": "/api/2.0/workspace/mkdirs",
19+
"body": {
20+
"path": "/Workspace/Users/[USERNAME]/.bundle/alert-task/default/files"
21+
}
22+
}
23+
{
24+
"method": "GET",
25+
"path": "/api/2.0/workspace/get-status",
26+
"q": {
27+
"path": "/Workspace/Users/[USERNAME]/.bundle/alert-task/default/files"
28+
}
29+
}

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
>>> [CLI] bundle validate -o json
3+
{
4+
"warehouse_id": "cafef00d",
5+
"workspace_path": "/Workspace/Users/[USERNAME]/.bundle/alert-task/default/files/my_alert.dbalert.json"
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trace $CLI bundle validate -o json | jq '.resources.jobs.my_job.tasks[0].alert_task'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cloud = false
2+
Local = true

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)