Fix CLI token source --profile fallback with version detection#751
Fix CLI token source --profile fallback with version detection#751mihaimitrea-db wants to merge 1 commit intomainfrom
Conversation
048a903 to
5e8f476
Compare
Range-diff: main (048a903 -> 5e8f476)
Reproduce locally: |
5e8f476 to
6b8a57f
Compare
Range-diff: main (5e8f476 -> 6b8a57f)
Reproduce locally: |
6b8a57f to
61686da
Compare
Range-diff: main (6b8a57f -> 61686da)
Reproduce locally: |
61686da to
1c68e85
Compare
Range-diff: main (61686da -> 1c68e85)
Reproduce locally: |
1c68e85 to
0de2614
Compare
0de2614 to
6d775fc
Compare
6d775fc to
c4e12c1
Compare
simonfaltum
left a comment
There was a problem hiding this comment.
Review Swarm (Isaac + Cursor, 2 rounds, deep review)
Verdict: Not ready yet
0 Critical | 2 Major | 1 Gap (Minor) | 8 Nit | 6 Suggestion
Both reviewers independently proposed the same architecture the PR already uses (probe + cache + typed semver + UNKNOWN sentinel). The two Major findings are about subprocess and JSON-parsing robustness, not the design. Everything else is polish.
See inline comments for specific findings, and a follow-up general PR comment for findings that reference lines outside the diff hunks.
Verifications (both reviewers agreed, no issues)
CliTokenSourcecarries@InternalApi; removing the 6-arg constructor is not a breaking change.AzureCliCredentialsProvideris untouched (still uses the 5-arg constructor).atLeast/compareToordering is correct across patch/minor/major;UNKNOWN(-1,-1,-1)sorts below all real versions including(0,0,0).- Account-host vs workspace-host behavior is preserved (
buildHostArgsstill appends--account-idonly whenClientType.ACCOUNT). - The core bug is fixed:
cfg.profileset with CLI < v0.207.1 now correctly falls back to--host.
Automated review swarm. Classifications are advisory; final judgement is yours.
|
|
||
| // Successful version probes keyed by cliPath. Failures are deliberately not cached, so a | ||
| // transient error (timeout, AV scan) does not pin every later token source to the conservative | ||
| // fallback for the rest of the process lifetime. | ||
| private static final Map<String, DatabricksCliVersion> VERSION_CACHE = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
[Suggestion] Negative-result caching trade-off could bite SDK consumers that build many WorkspaceClients
Found by: Cursor, confirmed by Isaac
Failing-fast is fine when the CLI is truly unavailable (fast exception). But a CLI that genuinely hangs (corporate AV scan on first launch, blocked exec) incurs 5s on every configure(...) call for the JVM lifetime. For SDK consumers that build many WorkspaceClients this is death by a thousand cuts. Worth confirming parity with the Go/Python siblings.
Suggestion: Either (a) document the trade-off explicitly in the cache comment ("we accept up to N×5s startup latency under sustained CLI failure"), or (b) cache UNKNOWN with a small TTL (e.g. 60s) to bound the damage. Not a blocker.
Review Swarm: Additional findingsThe findings below reference code locations outside the PR's diff hunks (pre-existing lines that weren't touched, or test-coverage gaps that don't have a single pin-point) so they're posted here rather than as inline comments. [Nit] Dead
|
|
Process resource leak in
Duplicate WARN log emitted when CLI binary is missing
🔍 Reviewed by nitpicker |
c4e12c1 to
228ea4d
Compare
228ea4d to
5525326
Compare
5525326 to
6a66c24
Compare
6a66c24 to
c968abd
Compare
`--profile` on `databricks auth token` is a global Cobra flag, so old CLIs (< v0.207.1) silently accept it and fail later with `cannot fetch credentials` instead of `unknown flag: --profile`. The previous error-based fallback never matched, leaving the `--host` fallback as dead code. This commit replaces the runtime fallback chain with version-based capability detection: * `CliVersion` carries a (major, minor, patch) triple plus an `UNKNOWN` sentinel and a default-dev-build (0,0,0) check. * `DatabricksCliCredentialsProvider` runs `databricks version --output json` once per CLI path (cached on success only, with a 5s timeout) and gates `--profile` on >= v0.207.1; everything else falls back to `--host` with a precise warning. * `CliTokenSource` is simplified to a single `cmd`; the `fallbackCmd` parameter and the runtime "unknown flag" retry loop are removed. Mirrors the equivalent refactors in the Go and Python SDKs: * databricks/databricks-sdk-go#1605 * databricks/databricks-sdk-py#1377 Co-authored-by: Isaac
c968abd to
fdd7383
Compare
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
🥞 Stacked PR
Use this link to review incremental changes.
Summary
Replace the broken error-based
--profilefallback inCliTokenSourcewith version-based CLI detection at init time. Mirrors databricks/databricks-sdk-go#1605 and databricks/databricks-sdk-py#1377.Why
--profileondatabricks auth tokenis a global flag, so old CLIs (< v0.207.1) silently accept it and then fail with"cannot fetch credentials"instead of"unknown flag: --profile". The existing retry check was matching on the latter and never fired — the--hostfallback it gated was effectively dead code. Switching todatabricks version+ a minimum-version constant makes the fallback reliable and sets up future capability-gated flags (e.g.--force-refreshin #752) without additional subprocess calls.What changed
Interface changes
None.
CliTokenSourceis not part of the public API surface.Behavioral changes
cfg.profile+ CLI < v0.207.1 now correctly falls back to--host(previously broken).databricks versionfailures log aWARNINGand fall back to the most conservative command. Successful detections are cached per CLI path; failures are not cached and will be retried on the next call.v0.0.0-dev) logs anINFOexplaining why feature gates are conservative.AzureCliCredentialsProvideris untouched.Internal changes
DatabricksCliVersionclass with a(major, minor, patch)triple, anUNKNOWNsentinel, anatLeast()comparator, and anisDefaultDevBuild()helper.CliTokenSourcesimplified to a singlecmd; thefallbackCmdparameter and its retry logic are removed.DatabricksCliCredentialsProvidergainsgetCliVersion,probeCliVersion,parseCliVersion,resolveCliCommand, andbuildCliCommandhelpers.How is this tested?
Unit tests in
DatabricksCliVersionTestcover version comparison (across patch/minor/major), theUNKNOWNsentinel, dev-build detection, andtoStringformatting.Unit tests in
DatabricksCliCredentialsProviderTestcover JSON parsing ofdatabricks version --output json(standard, dev build, missing fields, malformed JSON, empty string) and command assembly for every profile/host/version combination (host-only, account host, profile + new CLI, profile + old CLI, unknown version, dev build).CliTokenSourceTestretains its parsing and timezone tests; the obsolete fallback tests are dropped.