Skip to content
Open
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
1 change: 1 addition & 0 deletions .nextchanges/bundles/4104.md
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))
68 changes: 68 additions & 0 deletions acceptance/bundle/validate/for_each_task/databricks.yml
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"
2 changes: 2 additions & 0 deletions acceptance/bundle/validate/for_each_task/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
55 changes: 55 additions & 0 deletions acceptance/bundle/validate/for_each_task/output.txt
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!
3 changes: 3 additions & 0 deletions acceptance/bundle/validate/for_each_task/script
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
2 changes: 2 additions & 0 deletions acceptance/bundle/validate/for_each_task/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Databricks notebook source
print("test")
1 change: 1 addition & 0 deletions bundle/config/validate/fast_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (f *fastValidate) Apply(ctx context.Context, rb *bundle.Bundle) diag.Diagno
// Fast mutators with only in-memory checks
JobClusterKeyDefined(),
JobTaskClusterSpec(),
ForEachTask(),

// Blocking mutators. Deployments will fail if these checks fail.
ValidateArtifactPath(),
Expand Down
82 changes: 82 additions & 0 deletions bundle/config/validate/for_each_task.go
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 {
Comment thread
idelafuente-oc marked this conversation as resolved.
Resolved
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},
}
}