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-no-follow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `databricks air logs --no-follow` prints the logs so far from an active run and exits, instead of following the run until it finishes. ([#7654](https://github.com/databricks/cli/pull/7654))
5 changes: 4 additions & 1 deletion acceptance/air/help/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,23 @@ Global Flags:
Stream logs from an active run until it completes, or fetch logs from a
completed run.

JOB_RUN_ID is the job run ID returned by "databricks air run".
JOB_RUN_ID is the job run ID returned by "databricks air run". Use --no-follow
to print the logs so far from an active run and exit.

Usage:
databricks air logs JOB_RUN_ID [flags]

Examples:
databricks air logs 123456789
databricks air logs 123456789 --node 1 --retry 0
databricks air logs 123456789 --no-follow --tail 50
databricks air logs 123456789 --download-to ./logs

Flags:
--download-to string Download all logs to this directory instead of printing
-h, --help help for logs
--minutes int Fetch only logs from the last N minutes
--no-follow Print the logs so far and exit instead of following an active run
--node int Fetch logs from this node
--retry int View logs from a specific retry attempt; -1 means latest (default -1)
--tail int Print the last N existing lines before following, or from a completed run (default 10000)
Expand Down
7 changes: 6 additions & 1 deletion cmd/air/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func newLogsCommand() *cobra.Command {
retry int
downloadTo string
review bool
noFollow bool
)

cmd := &cobra.Command{
Expand All @@ -35,16 +36,19 @@ func newLogsCommand() *cobra.Command {
Long: `Stream logs from an active run until it completes, or fetch logs from a
completed run.

JOB_RUN_ID is the job run ID returned by "databricks air run".`,
JOB_RUN_ID is the job run ID returned by "databricks air run". Use --no-follow
to print the logs so far from an active run and exit.`,
Example: ` databricks air logs 123456789
databricks air logs 123456789 --node 1 --retry 0
databricks air logs 123456789 --no-follow --tail 50
databricks air logs 123456789 --download-to ./logs`,
}

cmd.Flags().IntVar(&node, "node", 0, "Fetch logs from this node")
cmd.Flags().IntVar(&tail, "tail", 0, "Print the last N existing lines before following, or from a completed run (default 10000)")
cmd.Flags().IntVar(&minutes, "minutes", 0, "Fetch only logs from the last N minutes")
cmd.Flags().IntVar(&retry, "retry", -1, "View logs from a specific retry attempt; -1 means latest")
cmd.Flags().BoolVar(&noFollow, "no-follow", false, "Print the logs so far and exit instead of following an active run")
cmd.Flags().StringVar(&downloadTo, "download-to", "", "Download all logs to this directory instead of printing")
cmd.Flags().BoolVar(&review, "review", false, "Download logs from all nodes and filter for error signatures")
cmd.Flags().MarkHidden("review")
Expand Down Expand Up @@ -130,6 +134,7 @@ JOB_RUN_ID is the job run ID returned by "databricks air run".`,
boundInitialLogs: minutes == 0,
downloadTo: downloadTo,
jsonOutput: root.OutputType(cmd) == flags.OutputJSON,
staticView: noFollow,
})
if downloadTo != "" || root.OutputType(cmd) == flags.OutputJSON {
return err
Expand Down
19 changes: 19 additions & 0 deletions cmd/air/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,22 @@ func TestRunLogsPreservesSubmittedRunURL(t *testing.T) {
require.NoError(t, err)
assert.True(t, strings.HasSuffix(buf.String(), "\n\nView job run at: "+runURL+"\n"), buf.String())
}

func TestLogsNoFollowPrintsActiveRunOnce(t *testing.T) {
var getRunHits int
srv := activeRunPastRetryServer(t, &getRunHits)
var buf bytes.Buffer
// The run never finishes, so following it would block until the deadline.
ctx, cancel := context.WithTimeout(t.Context(), 10*time.Second)
defer cancel()
ctx = cmdio.InContext(ctx, cmdio.NewIO(ctx, flags.OutputText, nil, &buf, &buf, "", ""))
ctx = cmdctx.SetWorkspaceClient(ctx, newTestWorkspaceClient(t, srv.URL))
cmd := withOutput(newLogsCommand(), flags.OutputText)
cmd.SetContext(ctx)
cmd.SetOut(&buf)
require.NoError(t, cmd.Flags().Set("no-follow", "true"))

require.NoError(t, cmd.RunE(cmd, []string{"9"}))
assert.Equal(t, "retry 0 log\n", buf.String())
assert.Equal(t, 1, getRunHits)
}
Loading