diff --git a/.nextchanges/air/7568.md b/.nextchanges/air/7568.md new file mode 100644 index 00000000000..d4825707742 --- /dev/null +++ b/.nextchanges/air/7568.md @@ -0,0 +1 @@ +* Add experiment, duration, accelerator, and dashboard metadata to `air list --output json`. For retried runs, `started_at` now reports the latest attempt, matching `air get`. ([#7568](https://github.com/databricks/cli/pull/7568)) diff --git a/acceptance/air/list/output.txt b/acceptance/air/list/output.txt index 02f4f625742..4c0c7ed3542 100644 --- a/acceptance/air/list/output.txt +++ b/acceptance/air/list/output.txt @@ -19,7 +19,12 @@ "user": "[USERNAME]", "status": "SUCCESS", "started_at": "[TIMESTAMP]", - "is_sweep": false + "is_sweep": false, + "experiment_name": "qwen-train", + "duration_seconds": 12, + "accelerator_type": "GPU_8xH100", + "num_accelerators": 8, + "dashboard_url": "[DATABRICKS_URL]/jobs/runs/334747067049496?o=[WORKSPACE_ID]" } ] } @@ -45,7 +50,12 @@ "user": "[USERNAME]", "status": "SUCCESS", "started_at": "[TIMESTAMP]", - "is_sweep": false + "is_sweep": false, + "experiment_name": "qwen-train", + "duration_seconds": 12, + "accelerator_type": "GPU_8xH100", + "num_accelerators": 8, + "dashboard_url": "[DATABRICKS_URL]/jobs/runs/334747067049496?o=[WORKSPACE_ID]" } ] } diff --git a/cmd/air/list.go b/cmd/air/list.go index 4c75b286b19..a24e9f9f54b 100644 --- a/cmd/air/list.go +++ b/cmd/air/list.go @@ -37,16 +37,20 @@ type listData struct { // machine-readable output; fields tagged `json:"-"` are shown only in the // human-readable table. type listRow struct { - RunID string `json:"run_id"` - RunName string `json:"run_name"` - User string `json:"user"` - Status string `json:"status"` - DisplayStatus string `json:"-"` - StartedAt *string `json:"started_at"` - IsSweep bool `json:"is_sweep"` - - // Experiment, Duration, Progress, MLflowURL and Accelerators are table-only - // columns, omitted from JSON to match `air list --json`. + RunID string `json:"run_id"` + RunName string `json:"run_name"` + User string `json:"user"` + Status string `json:"status"` + DisplayStatus string `json:"-"` + StartedAt *string `json:"started_at"` + IsSweep bool `json:"is_sweep"` + ExperimentName *string `json:"experiment_name"` + DurationSeconds *int64 `json:"duration_seconds"` + AcceleratorType *string `json:"accelerator_type"` + NumAccelerators *int `json:"num_accelerators"` + DashboardURL string `json:"dashboard_url"` + + // The fields below are pre-rendered table cells or text-only enrichment. Experiment string `json:"-"` Duration string `json:"-"` // Progress is a best-effort estimate ("45% · ~2h 15m"), set only for a running diff --git a/cmd/air/list_cache.go b/cmd/air/list_cache.go index 722d1d95478..941327e93b1 100644 --- a/cmd/air/list_cache.go +++ b/cmd/air/list_cache.go @@ -14,7 +14,7 @@ import ( // TTL matches AICM's ~60-day retention, after which the run drops out of the // index anyway. const ( - listCacheComponent = "air-list-runs" + listCacheComponent = "air-list-runs-v2" listCacheTTL = 60 * 24 * time.Hour ) @@ -29,21 +29,26 @@ type listCacheKey struct { // table-only columns, which listRow tags json:"-" and so wouldn't survive a // direct marshal), the filter inputs, and the submit time. type cachedRun struct { - RunID string `json:"run_id"` - RunName string `json:"run_name"` - User string `json:"user"` - Status string `json:"status"` - StartedAt *string `json:"started_at"` - IsSweep bool `json:"is_sweep"` - Experiment string `json:"experiment"` - Duration string `json:"duration"` - MLflowURL string `json:"mlflow_url"` - MLflowLabel string `json:"mlflow_label"` - RunURL string `json:"run_url"` - ExperimentURL string `json:"experiment_url"` - Accelerators string `json:"accelerators"` - Fields filterFields `json:"filter_fields"` - SubmitTimeMs int64 `json:"submit_time_ms"` + RunID string `json:"run_id"` + RunName string `json:"run_name"` + User string `json:"user"` + Status string `json:"status"` + StartedAt *string `json:"started_at"` + IsSweep bool `json:"is_sweep"` + ExperimentName *string `json:"experiment_name"` + DurationSeconds *int64 `json:"duration_seconds"` + AcceleratorType *string `json:"accelerator_type"` + NumAccelerators *int `json:"num_accelerators"` + DashboardURL string `json:"dashboard_url"` + Experiment string `json:"experiment"` + Duration string `json:"duration"` + MLflowURL string `json:"mlflow_url"` + MLflowLabel string `json:"mlflow_label"` + RunURL string `json:"run_url"` + ExperimentURL string `json:"experiment_url"` + Accelerators string `json:"accelerators"` + Fields filterFields `json:"filter_fields"` + SubmitTimeMs int64 `json:"submit_time_ms"` // Tasks are the run's task runs (see retryTasks), which pick its MLflow link. Tasks []jobs.RunTask `json:"tasks"` @@ -52,7 +57,8 @@ type cachedRun struct { func (c cachedRun) toRow() listRow { return listRow{ RunID: c.RunID, RunName: c.RunName, User: c.User, Status: c.Status, - StartedAt: c.StartedAt, IsSweep: c.IsSweep, Experiment: c.Experiment, + StartedAt: c.StartedAt, IsSweep: c.IsSweep, ExperimentName: c.ExperimentName, + DurationSeconds: c.DurationSeconds, AcceleratorType: c.AcceleratorType, NumAccelerators: c.NumAccelerators, DashboardURL: c.DashboardURL, Experiment: c.Experiment, Duration: c.Duration, MLflowURL: c.MLflowURL, MLflowLabel: c.MLflowLabel, RunURL: c.RunURL, ExperimentURL: c.ExperimentURL, Accelerators: c.Accelerators, } @@ -61,7 +67,8 @@ func (c cachedRun) toRow() listRow { func cachedRunFromRow(r listRow, tasks []jobs.RunTask, fields filterFields, submitTimeMs int64) cachedRun { return cachedRun{ RunID: r.RunID, RunName: r.RunName, User: r.User, Status: r.Status, - StartedAt: r.StartedAt, IsSweep: r.IsSweep, Experiment: r.Experiment, + StartedAt: r.StartedAt, IsSweep: r.IsSweep, ExperimentName: r.ExperimentName, + DurationSeconds: r.DurationSeconds, AcceleratorType: r.AcceleratorType, NumAccelerators: r.NumAccelerators, DashboardURL: r.DashboardURL, Experiment: r.Experiment, Duration: r.Duration, MLflowURL: r.MLflowURL, MLflowLabel: r.MLflowLabel, RunURL: r.RunURL, ExperimentURL: r.ExperimentURL, Accelerators: r.Accelerators, Tasks: tasks, Fields: fields, SubmitTimeMs: submitTimeMs, diff --git a/cmd/air/list_cache_test.go b/cmd/air/list_cache_test.go index 8e4e9be4fd0..89f629a3643 100644 --- a/cmd/air/list_cache_test.go +++ b/cmd/air/list_cache_test.go @@ -20,7 +20,10 @@ func TestListCacheRoundTrip(t *testing.T) { _, _, _, ok := cachedRow(ctx, c, "https://host.test", 42) require.False(t, ok, "miss before write") - row := listRow{RunID: "42", Experiment: "exp", Status: "SUCCESS"} + row := listRow{ + RunID: "42", Status: "SUCCESS", ExperimentName: new("exp"), DurationSeconds: new(int64(12)), + AcceleratorType: new("GPU_1xA10"), NumAccelerators: new(1), DashboardURL: "https://host.test/jobs/runs/42?o=1", Experiment: "exp", + } fields := filterFields{Experiment: "exp", GPUType: "GPU_1xA10", GPUCount: 1} tasks := []jobs.RunTask{{RunId: 420, TaskKey: "train"}, {RunId: 421, TaskKey: "train", AttemptNumber: 1}} putRow(ctx, c, "https://host.test", 42, tasks, 1700000000000, row, fields) diff --git a/cmd/air/list_format.go b/cmd/air/list_format.go index 81c22fbbea9..cda11b49a58 100644 --- a/cmd/air/list_format.go +++ b/cmd/air/list_format.go @@ -2,7 +2,6 @@ package aircmd import ( "strconv" - "time" "github.com/databricks/databricks-sdk-go/service/jobs" ) @@ -11,41 +10,50 @@ import ( // to "-"; MLflowURL starts as "-" and setMLflowLinks fills it in for text output. // host and workspaceID are used for building dashboard URLs. func buildListRow(run *jobs.Run, host string, workspaceID int64) listRow { - experiment := "-" - if e := jobExperiment(run); e != "" { - experiment = e + experiment := jobExperiment(run) + experimentName := nilIfEmpty(experiment) + if experiment == "" { + experiment = "-" } - var startedAt *string + startedAtValue := startedAt(run) + durationSecondsValue := durationSeconds(run) duration := "-" - if start, end := jobTiming(run); start > 0 { - s := isoFormat(time.UnixMilli(start)) - startedAt = &s - if end == 0 { - // Still running: measure against the current time. - end = time.Now().UnixMilli() - } - duration = formatDuration(roundMillisToSeconds(end - start)) + if durationSecondsValue != nil { + duration = formatDuration(*durationSecondsValue) } + acceleratorType, numAccelerators := jobCompute(run) + acceleratorTypeJSON := nilIfEmpty(acceleratorType) + var numAcceleratorsJSON *int + if numAccelerators != 0 { + numAcceleratorsJSON = &numAccelerators + } accel := "-" - if a := acceleratorLabel(jobCompute(run)); a != "" { + if a := acceleratorLabel(acceleratorType, numAccelerators); a != "" { accel = a } + runURL := dashboardURL(host, run.RunId, workspaceID) + return listRow{ - RunID: strconv.FormatInt(run.RunId, 10), - RunName: run.RunName, - User: run.CreatorUserName, - Status: displayRunStatus(run), - DisplayStatus: displayRunStatus(run), - StartedAt: startedAt, - IsSweep: isSweep(run), - Experiment: experiment, - Duration: duration, - MLflowURL: "-", - MLflowLabel: "-", - RunURL: dashboardURL(host, run.RunId, workspaceID), - Accelerators: accel, + RunID: strconv.FormatInt(run.RunId, 10), + RunName: run.RunName, + User: run.CreatorUserName, + Status: displayRunStatus(run), + DisplayStatus: displayRunStatus(run), + StartedAt: startedAtValue, + IsSweep: isSweep(run), + ExperimentName: experimentName, + DurationSeconds: durationSecondsValue, + AcceleratorType: acceleratorTypeJSON, + NumAccelerators: numAcceleratorsJSON, + DashboardURL: runURL, + Experiment: experiment, + Duration: duration, + MLflowURL: "-", + MLflowLabel: "-", + RunURL: runURL, + Accelerators: accel, } } diff --git a/cmd/air/list_test.go b/cmd/air/list_test.go index 0928769393d..81bdfd27c34 100644 --- a/cmd/air/list_test.go +++ b/cmd/air/list_test.go @@ -172,7 +172,7 @@ func TestBuildListRowFromRun(t *testing.T) { assert.Equal(t, "GPU_1xA10", gpu) assert.Equal(t, 1, count) - row := buildListRow(&run, "https://example.test", 0) + row := buildListRow(&run, "https://example.test", 456) assert.Equal(t, "842552489592352", row.RunID) assert.Equal(t, "SUCCESS", row.Status) assert.Equal(t, "my-first-air-run", row.Experiment) @@ -186,7 +186,7 @@ func TestBuildListRow(t *testing.T) { run.EndTime = 1700000012000 run.State = &jobs.RunState{ResultState: jobs.RunResultStateSuccess} - row := buildListRow(&run, "https://example.test", 0) + row := buildListRow(&run, "https://example.test", 456) assert.Equal(t, "123", row.RunID) assert.Equal(t, "me@example.com", row.User) assert.Equal(t, "SUCCESS", row.Status) @@ -196,6 +196,32 @@ func TestBuildListRow(t *testing.T) { assert.Equal(t, "-", row.MLflowURL) assert.False(t, row.IsSweep) require.NotNil(t, row.StartedAt) + assert.Equal(t, "https://example.test/jobs/runs/123?o=456", row.DashboardURL) + assert.Equal(t, row.DashboardURL, row.RunURL) + + body, err := json.Marshal(row) + require.NoError(t, err) + assert.JSONEq(t, `{ + "run_id":"123","run_name":"run-123","user":"me@example.com","status":"SUCCESS", + "started_at":"2023-11-14T22:13:20+00:00","is_sweep":false, + "experiment_name":"exp","duration_seconds":12, + "accelerator_type":"GPU_8xH100","num_accelerators":8, + "dashboard_url":"https://example.test/jobs/runs/123?o=456" + }`, string(body)) +} + +func TestBuildListRowUsesLatestAttemptTiming(t *testing.T) { + run := airRun(123, "me@example.com", "GPU_1xA10", 1, "exp") + run.Tasks[0].StartTime = 1000 + run.Tasks[0].EndTime = 2000 + run.Tasks = append(run.Tasks, jobs.RunTask{StartTime: 10000, EndTime: 22000}) + + row := buildListRow(&run, "https://example.test", 456) + require.NotNil(t, row.StartedAt) + assert.Equal(t, "1970-01-01T00:00:10+00:00", *row.StartedAt) + require.NotNil(t, row.DurationSeconds) + assert.Equal(t, int64(12), *row.DurationSeconds) + assert.Equal(t, "12s", row.Duration) } func TestBuildListRowWaitingForComputeStatus(t *testing.T) { @@ -203,7 +229,7 @@ func TestBuildListRowWaitingForComputeStatus(t *testing.T) { run.State = &jobs.RunState{LifeCycleState: jobs.RunLifeCycleStateRunning} run.Tasks[0].State = &jobs.RunState{LifeCycleState: jobs.RunLifeCycleStatePending} - row := buildListRow(&run, "https://example.test", 0) + row := buildListRow(&run, "https://example.test", 456) body, err := json.Marshal(row) require.NoError(t, err) @@ -211,11 +237,13 @@ func TestBuildListRowWaitingForComputeStatus(t *testing.T) { assert.Equal(t, listRowStatus(row), row.Status) assert.JSONEq(t, `{ "run_id":"123","run_name":"run-123","user":"me@example.com","status":"PENDING", - "started_at":null,"is_sweep":false + "started_at":null,"is_sweep":false,"experiment_name":"exp","duration_seconds":null, + "accelerator_type":"GPU_8xH100","num_accelerators":8, + "dashboard_url":"https://example.test/jobs/runs/123?o=456" }`, string(body)) } -func TestBuildListRowDashFallbacks(t *testing.T) { +func TestBuildListRowMissingValues(t *testing.T) { // A run with no task, compute, or start time falls back to dashes and UNKNOWN. row := buildListRow(&jobs.Run{RunId: 7}, "https://example.test", 0) assert.Equal(t, "-", row.Experiment) @@ -224,6 +252,16 @@ func TestBuildListRowDashFallbacks(t *testing.T) { assert.Equal(t, "-", row.MLflowURL) assert.Equal(t, "UNKNOWN", row.Status) assert.Nil(t, row.StartedAt) + assert.Equal(t, "https://example.test/jobs/runs/7", row.RunURL) + assert.Equal(t, row.RunURL, row.DashboardURL) + + body, err := json.Marshal(row) + require.NoError(t, err) + assert.JSONEq(t, `{ + "run_id":"7","run_name":"","user":"","status":"UNKNOWN","started_at":null,"is_sweep":false, + "experiment_name":null,"duration_seconds":null,"accelerator_type":null,"num_accelerators":null, + "dashboard_url":"https://example.test/jobs/runs/7" + }`, string(body)) } func TestBuildListRowSweep(t *testing.T) { diff --git a/cmd/air/list_tui_test.go b/cmd/air/list_tui_test.go index 89964d14619..a9adbdd3439 100644 --- a/cmd/air/list_tui_test.go +++ b/cmd/air/list_tui_test.go @@ -194,7 +194,7 @@ func TestStaticListTable(t *testing.T) { assert.NotContains(t, out, "\x1b") assert.NotContains(t, out, "▸", "static table has no selection") - for _, want := range []string{"Run ID", "1", "qwen-train", "qwen-run-001", "Accelerators"} { + for _, want := range []string{"Run ID", "1", "qwen-train", "1m 14s", "qwen-run-001", "8x H100", "Accelerators"} { assert.Contains(t, out, want) }