Repository navigation
air: stop polling a finished run once its execution summary has settled - #8159
Open
qianhao-zhang-databricks wants to merge 2 commits into
Open
qianhao-zhang-databricks wants to merge 2 commits into
qianhao-zhang-databricks wants to merge 2 commits into
Conversation
After a watched run turns terminal, the Bricklens stream waits for three consecutive empty polls, one second apart, so records indexed late are not lost. When the stream already ended with the entry script's execution summary (its last output on every attempt), the summary ended it at least 5 seconds before the terminal poll, and at least three polls since then found nothing new, those polls repeat evidence the stream already has. In that case exit on the first terminal poll. The decision is one function, tailComplete, that checks its evidence strongest first and otherwise keeps today's three empty polls. The summary lines only shorten the wait for late records. The exit code, the final status and the closing -o json event still come from the Jobs run state, because user code can print the same lines. Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
databricks air run --watchanddatabricks air logs --followexit about 2 s sooner after a run ends. Today, once the run is terminal, the log stream waits for three consecutive empty polls, one second apart, so that late-indexed records are not lost. It now exits on the first terminal poll when all of these hold:Time in container: ..., thenCompleted at ...orERROR: Script failed with exit code ..., then the closing rule), printed during the run's latest attempt;In every other case nothing changes. The rule is in one method,
tailComplete(cmd/air/logstream.go); the summary matcher issummaryTracker(cmd/air/logstream_support.go).Why
The entry script prints the summary as its last output on every attempt. Once it has been printed, three polls after it found nothing, and 5 s have passed, the three terminal polls repeat checks the stream has already made.
The summary never decides the outcome: the exit code, the final status and the closing
-o jsonevent still come from the Jobs run state, because user code can print the same lines. A summary from an earlier retry attempt, or any output after it, keeps the three terminal polls.What this trades: the last look for late log records comes about 2 s earlier than today, at the first terminal poll instead of after three more. The 5 s floor keeps that look at least 5 s after the summary. In our test runs no log record became readable after the run was terminal on any run where the rule applied, and the slowest record took about 3 s from write to readable.
Known limitation, deliberate: when a run turns terminal less than 5 s after its summary, the rule does not apply and the CLI waits for today's three polls. So the saving shrinks as the server reports the end of a run faster. On test runs with a faster, not yet released server path, the summary came 2.7 to 4.1 s before the terminal poll on 6 of 8 runs, and the saving fell to 0.73 s median (n=8). The floor could be revisited (shortened or dropped) once there is more data on how late records arrive.
Tests
cmd/air/logstream_test.go:TestStreamBricklensExitsOnFirstTerminalPollAfterSettledSummaryfails without the change (7 log requests instead of 5).TestStreamBricklensKeepsTerminalPollsWhenSummaryIsYoungerThanTheFloorfails without the 5 s floor (5 instead of 7).TestStreamBricklensKeepsTerminalPollsWhenSummaryIsFromEarlierAttemptfails without the latest-attempt check (5 instead of 7).TestStreamBricklensReturnsFailureOnFirstTerminalPollAfterSettledFailureSummary: a failed run whose summary has settled exits on the first terminal poll and still returns failure. It fails if the result is not taken from the Jobs run state, and without the change (7 log requests instead of 5).summaryTrackercases.go test ./cmd/air/...andgo test ./acceptance -run TestAccept/air/pass.golangci-lint run ./...,golangci-lint fmt --diff,go vet ./cmd/air/...,go mod tidy(no diff), the dead-code check andtools/validate_nextchanges.pyare clean.main. Since then the only upstream change tocmd/air/logstream*.gois the waiting-status text (#7899), which does not touch the poll loop or the exit decision, and this patch rebased onto it without a conflict. A secondair run --watchwith the same--idempotency-keyattaches to the existing run, so the released CLI (v1.27.0) and this branch watched the same run:-o jsonpair). Against an unpatched build of the same base commit, the saving was 1.89 s median (n=17).-o jsoncompared without timestamps; one watcher on two runs had an extraWAITINGevent because it attached earlier). Exit codes and the closing JSON event matched the Jobs result.This pull request and its description were written by Isaac.