Skip to content
Merged
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/air/run-url-workspace-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `air run` now prints the job run URL with the `?o=<workspace-id>` suffix, matching `air get` and `air list`; `dashboard_url` in `air run -o json` and the `--watch` events gains it too. When `air list` cannot resolve the workspace ID, its links now omit `?o=` instead of ending in `?o=0`. ([#7573](https://github.com/databricks/cli/pull/7573))
2 changes: 1 addition & 1 deletion acceptance/air/run-submit-databricks-ai/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
>>> [CLI] air run -f run.yaml
Submitting experiment: databricks-ai-v5-smoke
Submitted workload with Job Run ID: 555
View job run at: [DATABRICKS_URL]/jobs/runs/555
View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID]

Tip: use --watch when submitting a run to stream logs to your terminal.
Stream logs after submission using:
Expand Down
2 changes: 1 addition & 1 deletion acceptance/air/run-submit-deps/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
>>> [CLI] air run -f run.yaml
Submitting experiment: deps-smoke
Submitted workload with Job Run ID: 555
View job run at: [DATABRICKS_URL]/jobs/runs/555
View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID]

Tip: use --watch when submitting a run to stream logs to your terminal.
Stream logs after submission using:
Expand Down
2 changes: 1 addition & 1 deletion acceptance/air/run-submit-overrides/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Override: changing parameters.model.hidden_size from 1024 to 2048
Override: setting parameters.optimizer.learning_rate to 0.001
Submitting experiment: overrides-smoke
Submitted workload with Job Run ID: 555
View job run at: [DATABRICKS_URL]/jobs/runs/555
View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID]

Tip: use --watch when submitting a run to stream logs to your terminal.
Stream logs after submission using:
Expand Down
6 changes: 3 additions & 3 deletions acceptance/air/run-submit/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Submitting experiment: submit-smoke
Uploading [SNAPSHOT_TARBALL]...
Submitted workload with Job Run ID: 555
View job run at: [DATABRICKS_URL]/jobs/runs/555
View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID]

Tip: use --watch when submitting a run to stream logs to your terminal.
Stream logs after submission using:
Expand Down Expand Up @@ -112,7 +112,7 @@ Stream logs after submission using:
>>> [CLI] air run -f b300.yaml
Submitting experiment: b300-submit-smoke
Submitted workload with Job Run ID: 555
View job run at: [DATABRICKS_URL]/jobs/runs/555
View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID]

Tip: use --watch when submitting a run to stream logs to your terminal.
Stream logs after submission using:
Expand Down Expand Up @@ -163,7 +163,7 @@ Stream logs after submission using:
>>> [CLI] air run -f rtx6000.yaml
Submitting experiment: rtx6000-submit-smoke
Submitted workload with Job Run ID: 555
View job run at: [DATABRICKS_URL]/jobs/runs/555
View job run at: [DATABRICKS_URL]/jobs/runs/555?o=[WORKSPACE_ID]

Tip: use --watch when submitting a run to stream logs to your terminal.
Stream logs after submission using:
Expand Down
9 changes: 7 additions & 2 deletions cmd/air/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,14 @@ func roundMillisToSeconds(ms int64) int64 {

// dashboardURL builds {host}/jobs/runs/{id}?o={workspace_id}, matching Python
// (cli_entrypoint.py:1911). The ?o= workspace id deep-links to the right
// workspace on multi-workspace accounts.
// workspace on multi-workspace accounts; an unknown (zero) workspace id omits
// it rather than linking to ?o=0.
func dashboardURL(host string, runID, workspaceID int64) string {
return fmt.Sprintf("%s/jobs/runs/%d?o=%d", strings.TrimRight(host, "/"), runID, workspaceID)
url := fmt.Sprintf("%s/jobs/runs/%d", strings.TrimRight(host, "/"), runID)
if workspaceID == 0 {
return url
}
return fmt.Sprintf("%s?o=%d", url, workspaceID)
}

// formatDuration turns a number of seconds into a compact human string such as
Expand Down
1 change: 1 addition & 0 deletions cmd/air/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func TestDurationSeconds(t *testing.T) {
func TestDashboardURL(t *testing.T) {
// The ?o= workspace id and a trailing-slash-trimmed host, matching Python.
assert.Equal(t, "https://example.test/jobs/runs/123?o=42", dashboardURL("https://example.test/", 123, 42))
assert.Equal(t, "https://example.test/jobs/runs/123", dashboardURL("https://example.test/", 123, 0))
}

func TestLatestAttemptNumber(t *testing.T) {
Expand Down
37 changes: 33 additions & 4 deletions cmd/air/runsubmit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/filer"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/client"
"github.com/databricks/databricks-sdk-go/service/compute"
Expand Down Expand Up @@ -330,9 +331,10 @@ func stageRunArtifacts(ctx context.Context, launchWriter fileWriter, items []upl
// submitWorkload runs the submit happy path: validate the config while uploading
// the launch artifacts, ensure the experiment directory, assemble the Jobs
// payload, and submit it. It
// returns the new run_id and its dashboard URL. showProgress enables the stderr
// returns the new run_id and its dashboard URL, which carries the ?o= workspace
// hint only when the workspace ID could be resolved. showProgress enables the stderr
// staging spinner (text mode only).
func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *runConfig, configPath, idempotencyKey string, showProgress bool) (runID int64, dashboardURL string, err error) {
func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *runConfig, configPath, idempotencyKey string, showProgress bool) (runID int64, runURL string, err error) {
start := time.Now()
var snap snapshotResult
defer func() { logRunEvent(ctx, cfg, snap, runID, time.Since(start), err) }()
Expand Down Expand Up @@ -387,6 +389,11 @@ func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *run
return stageErr
})
})
var workspaceID int64
group.Go(func() error {
workspaceID = workspaceIDForRunLink(stagingCtx, w)
return nil
})
if err := group.Wait(); err != nil {
return 0, "", err
}
Expand Down Expand Up @@ -446,8 +453,30 @@ func submitWorkload(ctx context.Context, w *databricks.WorkspaceClient, cfg *run
return 0, "", err
}

dashboardURL = strings.TrimRight(w.Config.Host, "/") + "/jobs/runs/" + strconv.FormatInt(runID, 10)
return runID, dashboardURL, nil
return runID, dashboardURL(w.Config.Host, runID, workspaceID), nil
}

// workspaceIDLookupTimeout caps workspaceIDForRunLink.
const workspaceIDLookupTimeout = 10 * time.Second

// workspaceIDForRunLink returns the workspace ID for the run link's ?o= hint,
// or 0 when it cannot be resolved. The link is a convenience, so the lookup
// never fails a submission; it is capped, and callers run it before creating
// the run, so that it cannot hold back a new run's ID either.
func workspaceIDForRunLink(ctx context.Context, w *databricks.WorkspaceClient) int64 {
ctx, cancel := context.WithTimeout(ctx, workspaceIDLookupTimeout)
defer cancel()
id, err := auth.ResolveWorkspaceID(ctx, w)
if err != nil {
log.Debugf(ctx, "air run: could not resolve workspace ID for the run link: %v", err)
return 0
}
workspaceID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
log.Debugf(ctx, "air run: workspace ID %q for the run link is not numeric", id)
return 0
}
return workspaceID
}

func submittedContainers(cfg *runConfig, funcDir string) []submittedContainer {
Expand Down
44 changes: 43 additions & 1 deletion cmd/air/runsubmit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/fs"
"path"
"path/filepath"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -353,6 +354,8 @@ func TestStageRunArtifactsOverlapsLaunchAndSnapshot(t *testing.T) {
}

func TestSubmitWorkload(t *testing.T) {
// A workspace ID in the developer's environment would replace the test server's in the run link.
t.Setenv("DATABRICKS_WORKSPACE_ID", "")
server := testserver.New(t)
t.Cleanup(server.Close)

Expand Down Expand Up @@ -382,7 +385,7 @@ func TestSubmitWorkload(t *testing.T) {
runID, dashboardURL, err := submitWorkload(t.Context(), w, cfg, cfgPath, "idem-key", false)
require.NoError(t, err)
assert.Equal(t, int64(777), runID)
assert.Contains(t, dashboardURL, "/jobs/runs/777")
assert.Equal(t, server.URL+"/jobs/runs/777?o="+strconv.Itoa(testserver.TestWorkspaceID), dashboardURL)
assert.Equal(t, "idem-key", validatedToken)

// The submitted payload is a native ai_runtime_task pointing at the uploaded
Expand Down Expand Up @@ -714,6 +717,45 @@ containers:
}
}

// An unresolved workspace ID yields a link without ?o=, looked up before the run is created.
func TestSubmitWorkloadWithoutWorkspaceID(t *testing.T) {
server := testserver.New(t)
t.Cleanup(server.Close)

// Register before AddDefaultHandlers: the router is first-wins, so these must claim the routes ahead of the default handlers.
var workspaceIDLookups, lookupsBeforeSubmit atomic.Int32
server.Handle("GET", "/api/2.0/preview/scim/v2/Me", func(req testserver.Request) any {
// The workspace ID lookup is the /Me call without attributes; answering it
// without the X-Databricks-Org-Id header makes the lookup fail.
if req.URL.Query().Get("attributes") == "" {
workspaceIDLookups.Add(1)
}
return req.Workspace.MeUser(req.Token)
})
server.Handle("POST", "/api/2.2/jobs/runs/submit", func(req testserver.Request) any {
lookupsBeforeSubmit.Store(workspaceIDLookups.Load())
return jobs.SubmitRunResponse{RunId: 777}
})
stubValidateConfig(server)
testserver.AddDefaultHandlers(server)

w, err := databricks.NewWorkspaceClient(&databricks.Config{Host: server.URL, Token: "token"})
require.NoError(t, err)
// The test server's host metadata supplies a workspace ID; drop it to force the lookup.
w.Config.WorkspaceID = ""

cfgPath := writeConfigFile(t, "run.yaml", minimalConfig)
cfg, err := loadRunConfig(cfgPath)
require.NoError(t, err)

runID, runURL, err := submitWorkload(t.Context(), w, cfg, cfgPath, "idem-key", false)
require.NoError(t, err)
assert.Equal(t, int64(777), runID)
assert.Equal(t, server.URL+"/jobs/runs/777", runURL)
assert.Equal(t, int32(1), lookupsBeforeSubmit.Load(), "the workspace ID must be resolved before the run is created")
assert.Equal(t, int32(1), workspaceIDLookups.Load())
}

// A working-tree code_source is packaged into a tarball, uploaded via libs/filer,
// and its remote code_source_path attached to the submitted task.
func TestSubmitWorkloadWithCodeSource(t *testing.T) {
Expand Down
Loading