Repository navigation
Write the deploy's error class to a result file for auto-deploy - #7856
atreyadbrx wants to merge 3 commits into
Conversation
|
Commit: Regression test reportSelected 1 changed tests (limit=20, 0 not selected) 2 tests: regression=2 unreleased=0 coverage=0 failing=0
TestAccept/bundle/deploy/result-file/DMS=: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): same output as main (c639f9d) TestAccept/bundle/deploy/result-file/DMS=true: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌main (c639f9d): latest (v1.28.0): same output as main (c639f9d) |
✅ Integration test reportCommit: 4e0055a
Top 6 slowest tests (at least 2 minutes):
|
b33418c to
7ad3f2e
Compare
There was a problem hiding this comment.
Automated review at 7ad3f2e. Each finding was verified against the code.
Not ready yet: 1 blocking issue(s), tagged [blocking].
This PR has bundle deploy and pipelines deploy write a result file with {} or an error_class of USER or SERVICE when DATABRICKS_AUTO_DEPLOY_RESULT_FILE is set. The classification now uses the first error's cause, which diag.Diagnostic and logdiag keep. The approach is small and the unit and acceptance tests cover the main cases. The file doesn't hold up on some exit paths, though: a panic writes {}, and pipelines deploy can fail after the file says success. Treating every *url.Error as SERVICE also goes against the "if unsure, USER" rule.
| if opts.Deploy { | ||
| defer func() { | ||
| // Ahead of the nil check: the result file is written on every exit. | ||
| phases.WriteDeployResult(ctx, retErr) |
There was a problem hiding this comment.
[blocking] This defer also runs while a panic unwinds. At that point retErr is still nil and logdiag usually has no error, so WriteDeployResult writes {}. Then root.execute recovers the panic and exits 1. So a nil dereference in a mutator or in phases.Deploy leaves a file that says the deploy succeeded, which contradicts "a missing file means the CLI crashed" in bundle/phases/deploy_result.go:31. Can we recover() here and re-panic, then either skip the write or write SERVICE when there was a panic?
There was a problem hiding this comment.
Fixed in ba3592d. WriteDeployResultOnExit is now its own deferred function: it calls recover(), writes SERVICE (a panic is a CLI bug, not the bundle's) and re-panics, so telemetry and root.execute's recovery still run. Covered by TestWriteDeployResultOnExitReportsPanicAsService.
| if opts.Deploy { | ||
| defer func() { | ||
| // Ahead of the nil check: the result file is written on every exit. | ||
| phases.WriteDeployResult(ctx, retErr) |
There was a problem hiding this comment.
[nice to have] The file is written when ProcessBundleRet returns, not when the command exits. After that, pipelines deploy (cmd/pipelines/deploy.go:69) runs mutator.InitializeURLs(), which calls CurrentWorkspaceID. If that call fails, the command exits 1 with root.ErrAlreadyPrinted, but the file already says {}. Should pipelines deploy write the result again after that step, or should the write move to a place that covers the whole command?
There was a problem hiding this comment.
Fixed in ba3592d. Only bundle deploy writes the file now, through ProcessOptions.WriteDeployResult. pipelines deploy and the apps commands keep working after ProcessBundle returns, and the runner only runs bundle deploy.
| } | ||
| return errorClassUser | ||
| } | ||
| if _, ok := errors.AsType[*url.Error](err); ok { |
There was a problem hiding this comment.
[nice to have] net/http wraps nearly every client-side failure in *url.Error. That includes a DNS failure for a mistyped workspace.host, TLS or proxy misconfiguration, and context.Canceled/DeadlineExceeded when the run is interrupted. All of these come out as SERVICE, so the runner hides a message the customer needs. That's the opposite of the stated "when unsure, USER" fallback, and libs/retry/retry.go:84-90 explains why the repo doesn't treat every *url.Error as the platform's fault. Can this reuse or align with retry.IsTransient/IsTransientRead, or at least return USER for context cancellation and DNS/x509 errors, with a unit case for each?
There was a problem hiding this comment.
Agreed, fixed in ba3592d. Only an API error with status 5xx, 429 or 408 is SERVICE; network errors are USER. retry.IsTransient doesn't fit here, because it leaves out errors the SDK already retried, such as a 429. The unit table now has a network error as USER.
|
|
||
| data, err := json.Marshal(result) | ||
| if err == nil { | ||
| err = os.WriteFile(path, data, 0o644) |
There was a problem hiding this comment.
[nice to have] The file is written only from the defer in ProcessBundleRet. A flag-parsing error or a PersistentPreRunE failure (cmd/root/root.go:57-72) never gets there, so no file is written, and the runner reads that as a crash. Nothing removes an old file either, so if the runner reuses the path it reads the previous run's {} (the acceptance script has to rm result.json by hand). Should the runner contract require deleting the file before each run, or should the CLI remove it early, with the doc comment on WriteDeployResult updated to match?
There was a problem hiding this comment.
The runner passes fixed flags and gives each run a fresh temporary directory, so the path never exists when the CLI starts. A failure before ProcessBundleRet (output or logger setup) leaves no file, and the runner then keeps its current behavior. The doc comment now says a missing file means the deploy never got far enough to write it (ba3592d).
When DATABRICKS_AUTO_DEPLOY_RESULT_FILE is set, bundle deploy writes a
JSON file on every exit: {} on success, otherwise
{"error_class": "SERVICE"} or {"error_class": "USER"}. SERVICE means the
first error logged is an API error with status 5xx, 429 or 408, or a
request that got no response. Everything else is USER. Without the
variable nothing changes.
diag.FromErr now keeps the error a diagnostic was made from as
Diagnostic.Cause, and logdiag remembers the first error's cause, so the
class can be read after the error is rendered.
Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
load_dbalert_files.go lists every diag.Diagnostic field, so it needs the new Cause field: the error for the read and parse failures, nil for the others. Signed-off-by: atreyadbrx <atreya.misra@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
- A panic wrote {}, as if the deploy had succeeded. WriteDeployResultOnExit
is now its own deferred function: it reports a panic as SERVICE, because
a panic is a CLI bug, and re-panics.
- Only bundle deploy writes the file (ProcessOptions.WriteDeployResult).
pipelines deploy and the apps commands keep working after ProcessBundle
returns, so a file written there could say {} for a command that then
fails.
- Network errors are USER: a wrong host, proxy or certificate causes them
too, and USER is the default when the CLI can't tell.
Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
ba3592d to
4e0055a
Compare
Changes
When
DATABRICKS_AUTO_DEPLOY_RESULT_FILEis set,bundle deploywrites a JSON file on every exit:{}on success;{"error_class": "SERVICE"}when the first error logged is an API error with status 5xx, 429 or 408, or the CLI panicked;{"error_class": "USER"}for any other failure, network errors included.A deferred function in
ProcessBundleRetwrites it; onlybundle deployturns it on (ProcessOptions.WriteDeployResult), because other deploying commands keep working afterProcessBundlereturns. On a panic it writesSERVICEand re-panics. To classify an error after it's rendered,diag.FromErrnow keeps it asDiagnostic.Cause, andlogdiagremembers the first error's cause next to its summary. A failed write logs a warning and doesn't change the exit code. Without the variable nothing changes.Why
The DABs auto-deploy runner runs
bundle deployand reports failures to the customer. Today it treats every CLI failure as the customer's, so platform failures are blamed on customers and don't reach our alerts. The runner sets this variable and will useerror_classto tell the two apart. When the CLI can't tell, it reportsUSER, so the customer still sees the error.A file rather than
-o jsonleaves deploy's output unchanged and covers every exit path. There's no changelog entry: the variable is an interface for the runner, not for users.Tests
SERVICE, andlogdiagkeeping the first error's cause.bundle/deploy/result-file: a deploy that succeeds ({}), a job create that keeps returning 500 (SERVICE), a reference to an undefined variable (USER), andbundle validate(no file).cmd/roottests compared whole diagnostics; they now check severity and summary.load_dbalert_files.golists everyDiagnosticfield forexhaustruct, so it setsCausetoo.This pull request and its description were written by Isaac.