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/job-runs-cmdio-resource-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
direct: job_runs deploy progress lines now include the resource key (e.g. `Output from job_runs.foo: id=123: ...`) so concurrent runs are easier to tell apart.
4 changes: 2 additions & 2 deletions acceptance/bundle/resources/job_runs/basic/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Resources:
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/job-runs-basic/default/files...
Deploying resources...
job run [MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
job run [MY_RUN_ID]: SUCCESS
Output from job_runs.my_run: id=[MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
Output from job_runs.my_run: id=[MY_RUN_ID]: SUCCESS
Updating deployment state...
Deployment complete!

Expand Down
4 changes: 2 additions & 2 deletions acceptance/bundle/resources/job_runs/failed_run/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
job run [MY_RUN_ID]: Run URL: [RUN_URL]
Output from job_runs.my_run: id=[MY_RUN_ID]: Run URL: [RUN_URL]
Error: cannot create resources.job_runs.my_run: waiting after creating id=[MY_RUN_ID]: run did not succeed: FAILED: Task main failed with message: Workload failed, see run output for details.
task "main": RuntimeError: intentional failure
run page: [RUN_URL]
Expand Down Expand Up @@ -58,7 +58,7 @@ Updating deployment state...
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
job run [MY_RUN_ID_2]: Run URL: [RUN_URL]
Output from job_runs.my_run: id=[MY_RUN_ID_2]: Run URL: [RUN_URL]
Error: cannot recreate resources.job_runs.my_run: waiting after creating id=[MY_RUN_ID_2]: run did not succeed: FAILED: Task main failed with message: Workload failed, see run output for details.
task "main": RuntimeError: intentional failure
run page: [RUN_URL]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ Exit code: 1
>>> [CLI] bundle deploy --plan tmp.plan.json
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/job-runs-interrupted-run/default/files...
Deploying resources...
job run [MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
job run [MY_RUN_ID]: SUCCESS
Output from job_runs.my_run: id=[MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
Output from job_runs.my_run: id=[MY_RUN_ID]: SUCCESS
Updating deployment state...
Deployment complete!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/job-runs-job-parameters/default/files...
Deploying resources...
job run [MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
job run [MY_RUN_ID]: SUCCESS
Output from job_runs.my_run: id=[MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
Output from job_runs.my_run: id=[MY_RUN_ID]: SUCCESS
Updating deployment state...
Deployment complete!

Expand Down
8 changes: 4 additions & 4 deletions acceptance/bundle/resources/job_runs/redeploy/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/job-runs-redeploy/default/files...
Deploying resources...
job run [MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
job run [MY_RUN_ID]: SUCCESS
Output from job_runs.my_run: id=[MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
Output from job_runs.my_run: id=[MY_RUN_ID]: SUCCESS
Updating deployment state...
Deployment complete!

Expand Down Expand Up @@ -96,8 +96,8 @@ Resources:
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/job-runs-redeploy/default/files...
Deploying resources...
job run [MY_RUN_ID_2]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID_2]?o=[NUMID]
job run [MY_RUN_ID_2]: SUCCESS
Output from job_runs.my_run: id=[MY_RUN_ID_2]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID_2]?o=[NUMID]
Output from job_runs.my_run: id=[MY_RUN_ID_2]: SUCCESS
Updating deployment state...
Deployment complete!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/job-runs-retried-run-now/default/files...
Deploying resources...
job run [MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
job run [MY_RUN_ID]: SUCCESS
Output from job_runs.my_run: id=[MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID]
Output from job_runs.my_run: id=[MY_RUN_ID]: SUCCESS
Updating deployment state...
Deployment complete!

Expand Down
4 changes: 2 additions & 2 deletions acceptance/bundle/resources/job_runs/wait/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
Deploying resources...
job run [MY_RUN_ID]: Run URL: [RUN_URL]
job run [MY_RUN_ID]: SUCCESS
Output from job_runs.my_run: id=[MY_RUN_ID]: Run URL: [RUN_URL]
Output from job_runs.my_run: id=[MY_RUN_ID]: SUCCESS
Updating deployment state...
Deployment complete!

Expand Down
8 changes: 8 additions & 0 deletions bundle/direct/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"reflect"
"strings"

"github.com/databricks/cli/bundle/deployplan"
"github.com/databricks/cli/bundle/direct/dresources"
Expand All @@ -14,8 +15,14 @@ import (
"github.com/databricks/databricks-sdk-go/apierr"
)

func (d *DeploymentUnit) withResourceKey(ctx context.Context) context.Context {
// Match plan output (e.g. "job_runs.foo"), not the internal "resources." form.
return dresources.WithResourceKey(ctx, strings.TrimPrefix(d.ResourceKey, "resources."))
}

func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState) error {
ctx = log.WithPrefix(ctx, "destroying "+d.ResourceKey)
ctx = d.withResourceKey(ctx)
id := db.GetResourceID(d.ResourceKey)
if id == "" {
log.Infof(ctx, "Cannot delete %s: missing from state", d.ResourceKey)
Expand All @@ -27,6 +34,7 @@ func (d *DeploymentUnit) Destroy(ctx context.Context, db *dstate.DeploymentState

func (d *DeploymentUnit) Deploy(ctx context.Context, db *dstate.DeploymentState, newState any, actionType deployplan.ActionType, planEntry *deployplan.PlanEntry) error {
ctx = log.WithPrefix(ctx, "deploying "+d.ResourceKey)
ctx = d.withResourceKey(ctx)
if actionType == deployplan.Create {
return d.Create(ctx, db, newState)
}
Expand Down
8 changes: 5 additions & 3 deletions bundle/direct/dresources/job_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,13 @@ func runIsTerminal(state jobs.RunLifeCycleState) bool {
state == jobs.RunLifeCycleStateInternalError
}

// reportRunLine names the run, since resources deploy concurrently onto one stream.
// reportRunLine names the resource and run id so concurrent deploys stay readable.
// Deploy attaches the key via [WithResourceKey].
func reportRunLine(ctx context.Context, runID int64, msg string) {
if cmdio.HasIO(ctx) {
cmdio.LogString(ctx, fmt.Sprintf("job run %d: %s", runID, msg))
if !cmdio.HasIO(ctx) {
return
}
cmdio.LogString(ctx, fmt.Sprintf("Output from %s: id=%d: %s", ResourceKey(ctx), runID, msg))
}

// DoUpdate finishes the wait an interrupted deploy abandoned.
Expand Down
10 changes: 10 additions & 0 deletions bundle/direct/dresources/job_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/structs/structpath"
"github.com/databricks/cli/libs/testserver"
"github.com/databricks/databricks-sdk-go"
Expand Down Expand Up @@ -79,6 +80,15 @@ func TestJobRunWaitSucceeds(t *testing.T) {
assert.Equal(t, jobs.RunResultStateSuccess, remote.State.ResultState)
}

func TestReportRunLineIncludesResourceKey(t *testing.T) {
ctx, stderr := cmdio.NewTestContextWithStderr(t.Context())
ctx = WithResourceKey(ctx, "job_runs.my_run")

reportRunLine(ctx, 123, "SUCCESS")

assert.Equal(t, "Output from job_runs.my_run: id=123: SUCCESS\n", stderr.String())
}

func TestJobRunWaitFailsOnFailedResult(t *testing.T) {
client := jobRunClient(t, &jobs.RunState{
LifeCycleState: jobs.RunLifeCycleStateTerminated,
Expand Down
17 changes: 17 additions & 0 deletions bundle/direct/dresources/resource_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dresources

import "context"

type resourceKeyType struct{}

// WithResourceKey attaches the bundle resource key used in cmdio progress lines.
// key is the plan form without the "resources." prefix (e.g. "job_runs.foo").
func WithResourceKey(ctx context.Context, key string) context.Context {
return context.WithValue(ctx, resourceKeyType{}, key)
}

// ResourceKey returns the key attached by [WithResourceKey], or "" if none.
func ResourceKey(ctx context.Context) string {
key, _ := ctx.Value(resourceKeyType{}).(string)
return key
}
13 changes: 13 additions & 0 deletions bundle/direct/dresources/resource_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dresources

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestResourceKeyRoundTrip(t *testing.T) {
ctx := WithResourceKey(t.Context(), "job_runs.foo")
assert.Equal(t, "job_runs.foo", ResourceKey(ctx))
assert.Empty(t, ResourceKey(t.Context()))
}
Loading