Repository navigation
for_each_task checks on databricks bundle validate #4104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
idelafuente-oc
wants to merge
8
commits into
databricks:main
Choose a base branch
from
idelafuente-oc:validate/for_each_task_validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf52646
Adds for each validation
idelafuente-oc 8fa76f0
fix: github action lint
idelafuente-oc 8f183d5
feat: acceptance tests for for each tasks validation
idelafuente-oc aa0c72c
refactor: simplifies unit test
idelafuente-oc 8d36728
revert: deletes unit test
idelafuente-oc dd98f35
Address for-each task validation review feedback
idelafuente-oc 2dbb22a
Clarify for-each task diagnostics
idelafuente-oc b3d3709
Merge branch 'main' into validate/for_each_task_validation
idelafuente-oc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Validate retry settings on `for_each_task` parent tasks, reporting unsupported retries as errors and ignored retry settings as warnings. ([#4104](https://github.com/databricks/cli/pull/4104)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| bundle: | ||
| name: "for_each_task_validation" | ||
|
|
||
| resources: | ||
| jobs: | ||
| aaa_job: | ||
| name: "Job A" | ||
| tasks: | ||
| - task_key: "parent_task" | ||
| for_each_task: | ||
| inputs: "[1, 2, 3]" | ||
| task: | ||
| task_key: "child_task" | ||
| notebook_task: | ||
| notebook_path: "test.py" | ||
| test_job: | ||
| name: "Test Job" | ||
| tasks: | ||
| - task_key: "parent_task" | ||
| for_each_task: | ||
| inputs: "[1, 2, 3]" | ||
| task: | ||
| task_key: "child_task" | ||
| notebook_task: | ||
| notebook_path: "test.py" | ||
|
|
||
| targets: | ||
| max_retries: | ||
| resources: | ||
| jobs: | ||
| aaa_job: | ||
| tasks: | ||
| - task_key: "parent_task" | ||
| max_retries: 3 | ||
| test_job: | ||
| tasks: | ||
| - task_key: "parent_task" | ||
| max_retries: 3 | ||
|
|
||
| retry_fields: | ||
| resources: | ||
| jobs: | ||
| test_job: | ||
| tasks: | ||
| - task_key: "parent_task" | ||
| min_retry_interval_millis: 1000 | ||
| retry_on_timeout: true | ||
|
|
||
| valid: | ||
| resources: | ||
| jobs: | ||
| test_job: | ||
| tasks: | ||
| - task_key: "parent_task" | ||
| max_retries: 0 | ||
| min_retry_interval_millis: 0 | ||
| retry_on_timeout: false | ||
| for_each_task: | ||
| task: | ||
| max_retries: 3 | ||
| min_retry_interval_millis: 1000 | ||
| retry_on_timeout: true | ||
| - task_key: "regular_task" | ||
| max_retries: 3 | ||
| min_retry_interval_millis: 1000 | ||
| retry_on_timeout: true | ||
| notebook_task: | ||
| notebook_path: "test.py" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Cloud = false | ||
| EnvMatrix.DMS = ["", "true"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
|
|
||
| >>> [CLI] bundle validate -t max_retries | ||
| Error: max_retries is not supported on a for_each_task parent task | ||
| at resources.jobs.aaa_job.tasks[0].max_retries | ||
| in databricks.yml:34:28 | ||
|
|
||
| When using for_each_task, max_retries must be defined on the nested task (for_each_task.task.max_retries), not on the parent task. | ||
|
|
||
| Error: max_retries is not supported on a for_each_task parent task | ||
| at resources.jobs.test_job.tasks[0].max_retries | ||
| in databricks.yml:38:28 | ||
|
|
||
| When using for_each_task, max_retries must be defined on the nested task (for_each_task.task.max_retries), not on the parent task. | ||
|
|
||
| Name: for_each_task_validation | ||
| Target: max_retries | ||
| Workspace: | ||
| User: [USERNAME] | ||
| Path: /Workspace/Users/[USERNAME]/.bundle/for_each_task_validation/max_retries | ||
|
|
||
| Found 2 errors | ||
|
|
||
| Exit code: 1 | ||
|
|
||
| >>> [CLI] bundle validate -t retry_fields | ||
| Warning: min_retry_interval_millis has no effect on a for_each_task parent task | ||
| at resources.jobs.test_job.tasks[0].min_retry_interval_millis | ||
| in databricks.yml:46:42 | ||
|
|
||
| min_retry_interval_millis is ignored on a for_each_task parent task. | ||
| Define it on the nested task (for_each_task.task.min_retry_interval_millis) instead. | ||
|
|
||
| Warning: retry_on_timeout has no effect on a for_each_task parent task | ||
| at resources.jobs.test_job.tasks[0].retry_on_timeout | ||
| in databricks.yml:47:33 | ||
|
|
||
| retry_on_timeout is ignored on a for_each_task parent task. | ||
| Define it on the nested task (for_each_task.task.retry_on_timeout) instead. | ||
|
|
||
| Name: for_each_task_validation | ||
| Target: retry_fields | ||
| Workspace: | ||
| User: [USERNAME] | ||
| Path: /Workspace/Users/[USERNAME]/.bundle/for_each_task_validation/retry_fields | ||
|
|
||
| Found 2 warnings | ||
|
|
||
| >>> [CLI] bundle validate -t valid | ||
| Name: for_each_task_validation | ||
| Target: valid | ||
| Workspace: | ||
| User: [USERNAME] | ||
| Path: /Workspace/Users/[USERNAME]/.bundle/for_each_task_validation/valid | ||
|
|
||
| Validation OK! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| errcode trace $CLI bundle validate -t max_retries | ||
| trace $CLI bundle validate -t retry_fields | ||
| trace $CLI bundle validate -t valid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Databricks notebook source | ||
| print("test") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package validate | ||
|
|
||
| import ( | ||
| "cmp" | ||
| "context" | ||
| "fmt" | ||
| "slices" | ||
|
|
||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/libs/diag" | ||
| "github.com/databricks/cli/libs/structs/structpath" | ||
| "github.com/databricks/databricks-sdk-go/service/jobs" | ||
| ) | ||
|
|
||
| // ForEachTask reports retry settings set on a for_each_task parent instead of its nested task. | ||
| func ForEachTask() bundle.ReadOnlyMutator { | ||
| return &forEachTask{} | ||
| } | ||
|
|
||
| type forEachTask struct{ bundle.RO } | ||
|
|
||
| func (v *forEachTask) Name() string { | ||
| return "validate:for_each_task" | ||
| } | ||
|
|
||
| func (v *forEachTask) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { | ||
| diags := diag.Diagnostics{} | ||
|
|
||
| for resourceName, job := range b.Config.Resources.Jobs { | ||
| for taskIndex, task := range job.Tasks { | ||
| if task.ForEachTask != nil { | ||
| taskPath := structpath.NewPath(nil, "resources", "jobs", resourceName, "tasks", taskIndex) | ||
| diags = diags.Extend(validateForEachTask(b, task, taskPath)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Map iteration order is randomized; sort by path for stable output. | ||
| slices.SortFunc(diags, func(x, y diag.Diagnostic) int { | ||
| return cmp.Compare(x.Paths[0].String(), y.Paths[0].String()) | ||
| }) | ||
|
|
||
| return diags | ||
| } | ||
|
|
||
| func validateForEachTask(b *bundle.Bundle, task jobs.Task, taskPath *structpath.PathNode) diag.Diagnostics { | ||
| diags := diag.Diagnostics{} | ||
|
|
||
| // The Jobs API rejects nonzero max_retries on the parent. It accepts the other | ||
| // retry settings, but they have no effect because the parent cannot be retried. | ||
| if task.MaxRetries != 0 { | ||
| diags = diags.Append(invalidRetryFieldDiag(b, taskPath, "max_retries", diag.Error)) | ||
| } | ||
|
|
||
| if task.MinRetryIntervalMillis != 0 { | ||
| diags = diags.Append(invalidRetryFieldDiag(b, taskPath, "min_retry_interval_millis", diag.Warning)) | ||
| } | ||
|
|
||
| if task.RetryOnTimeout { | ||
| diags = diags.Append(invalidRetryFieldDiag(b, taskPath, "retry_on_timeout", diag.Warning)) | ||
| } | ||
|
|
||
| return diags | ||
| } | ||
|
|
||
| func invalidRetryFieldDiag(b *bundle.Bundle, taskPath *structpath.PathNode, fieldName string, severity diag.Severity) diag.Diagnostic { | ||
| fieldPath := structpath.NewDotString(taskPath, fieldName) | ||
| summary := fieldName + " is not supported on a for_each_task parent task" | ||
| detail := fmt.Sprintf("When using for_each_task, %s must be defined on the nested task (for_each_task.task.%s), not on the parent task.", fieldName, fieldName) | ||
| if severity == diag.Warning { | ||
| summary = fieldName + " has no effect on a for_each_task parent task" | ||
| detail = fmt.Sprintf("%s is ignored on a for_each_task parent task.\nDefine it on the nested task (for_each_task.task.%s) instead.", fieldName, fieldName) | ||
| } | ||
|
|
||
| return diag.Diagnostic{ | ||
| Severity: severity, | ||
| Summary: summary, | ||
| Detail: detail, | ||
| Locations: b.Config.GetLocationsOf(fieldPath), | ||
| Paths: []*structpath.PathNode{fieldPath}, | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.