Skip to content
Closed
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/logs-non-tty-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `air logs` and `air run --watch` now print the waiting status (for example `Waiting for accelerator compute capacity...`) as a line on stderr when stderr is not a terminal, instead of printing nothing until the run produces logs. ([#7651](https://github.com/databricks/cli/pull/7651))
3 changes: 2 additions & 1 deletion cmd/air/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ func TestLogsCommandRepeatsRunLinkAfterStreaming(t *testing.T) {
assert.Contains(t, buf.String(), `"line":"step 2"`)
assert.NotContains(t, buf.String(), "View job run at:")
} else {
assert.Equal(t, "step 1\nstep 2\n\nView job run at: "+srv.URL+"/jobs/runs/777\n", buf.String())
// stderr shares buf and is not a TTY, so the waiting status prints as a line.
assert.Equal(t, "Waiting for run to start (node 0)...\nstep 1\nstep 2\n\nView job run at: "+srv.URL+"/jobs/runs/777\n", buf.String())
}
})
}
Expand Down
12 changes: 12 additions & 0 deletions cmd/air/logstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ func (st *bricklensStreamer) serverStatusMessage() string {
return normalizeStatusMessage(out.AiRuntimeTaskOutput.StatusMessage)
}

// logWaitingStatus prints a waiting status as a plain stderr line, for terminals
// that can't show the spinner.
func (st *bricklensStreamer) logWaitingStatus(msg string) {
cmdio.LogProgress(st.ctx, msg)
}

// reportStatusChange fires onStatusChange when the run's display state differs
// from the last reported one.
func (st *bricklensStreamer) reportStatusChange() {
Expand Down Expand Up @@ -427,6 +433,12 @@ func (st *bricklensStreamer) run() (bool, error) {
defer sp.Close()
st.onFirstLog = sp.Close
st.updateSpinner = sp.Update
// A non-interactive stderr (agents, CI, pipes) gets no spinner, which made
// a provisioning run look hung. Print each new waiting status as one line
// instead; the caller only calls updateSpinner when the text changes.
if cmdio.GetInteractiveMode(st.ctx) == cmdio.InteractiveModeNone {
st.updateSpinner = st.logWaitingStatus
}
}

firstIteration := true
Expand Down
41 changes: 41 additions & 0 deletions cmd/air/logstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,47 @@ func TestWaitingSpinnerText(t *testing.T) {
newStreamer(t, "", "TERMINATED", "PENDING").waitingSpinnerText())
}

func TestStreamBricklensPrintsWaitingStatusWithoutTTY(t *testing.T) {
original := bricklensPollInterval
bricklensPollInterval = time.Millisecond
t.Cleanup(func() { bricklensPollInterval = original })

var runGets int
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch {
case strings.HasSuffix(r.URL.Path, "/logs"):
if runGets < 4 {
_, _ = w.Write([]byte(`{"log_records":[]}`))
return
}
_, _ = w.Write([]byte(`{"log_records":[{"record_id":"a","time_unix_nano":20000000000,"body":"training"}]}`))
case r.URL.Path == "/api/2.2/jobs/runs/get":
runGets++
if runGets < 4 {
_, _ = w.Write([]byte(`{"run_id":1,"state":{"life_cycle_state":"PENDING"},"tasks":[{"run_id":2,"attempt_number":0}]}`))
return
}
_, _ = w.Write([]byte(`{"run_id":1,"start_time":10000,"state":{"life_cycle_state":"TERMINATED","result_state":"SUCCESS"},"tasks":[{"run_id":2,"attempt_number":0}]}`))
case r.URL.Path == "/api/2.2/jobs/runs/get-output":
_, _ = w.Write([]byte(`{"ai_runtime_task_output":{"status_message":"STATUS: Waiting for GPU capacity"}}`))
default:
_, _ = w.Write([]byte(`{}`))
}
}))
t.Cleanup(srv.Close)

// Buffers are not TTYs, so this is the agent/CI case where no spinner renders.
var stdout, stderr bytes.Buffer
ctx := cmdio.InContext(t.Context(), cmdio.NewIO(t.Context(), flags.OutputText, nil, &stdout, &stderr, "", ""))
ok, err := streamBricklensLogs(ctx, newTestWorkspaceClient(t, srv.URL), &stdout,
logRequest{runID: 1, attempt: -1, tailLines: -1},
logRunStatus{lifeCycleState: "PENDING", startTimeMs: 10_000})
require.NoError(t, err)
assert.True(t, ok)
assert.Equal(t, "Waiting for GPU capacity...\n", stderr.String())
assert.Contains(t, stdout.String(), "training")
}

func TestEmitLogLineJSON(t *testing.T) {
var buf bytes.Buffer
emitLogLine(&buf, logRequest{node: 2, jsonOutput: true}, "hello")
Expand Down
Loading