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/7568.md
Original file line number Diff line number Diff line change
@@ -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))
14 changes: 12 additions & 2 deletions acceptance/air/list/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
}
]
}
Expand All @@ -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]"
}
]
}
Expand Down
24 changes: 14 additions & 10 deletions cmd/air/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this comment now sits above RunURL, which is emitted as dashboard_url. Move RunURL up with the JSON fields.

Experiment string `json:"-"`
Duration string `json:"-"`
// Progress is a best-effort estimate ("45% · ~2h 15m"), set only for a running
Expand Down
43 changes: 25 additions & 18 deletions cmd/air/list_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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"`
Expand All @@ -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,
}
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion cmd/air/list_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
62 changes: 35 additions & 27 deletions cmd/air/list_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aircmd

import (
"strconv"
"time"

"github.com/databricks/databricks-sdk-go/service/jobs"
)
Expand All @@ -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,
}
}
48 changes: 43 additions & 5 deletions cmd/air/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -196,26 +196,54 @@ 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) {
run := airRun(123, "me@example.com", "GPU_8xH100", 8, "exp")
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)

assert.Equal(t, "PENDING", row.Status)
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)
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/air/list_tui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Loading