From 5d2241542ddb2f4f0e3242feb04e512a8d8e8cf8 Mon Sep 17 00:00:00 2001 From: Ilya Kuznetsov Date: Mon, 16 Nov 2026 17:30:49 +0000 Subject: [PATCH 01/14] Record the real error in config-remote-sync telemetry Co-authored-by: Isaac --- .../databricks.yml | 13 ++++++++++++ .../out.test.toml | 3 +++ .../output.txt | 20 +++++++++++++++++++ .../config-remote-sync-error-message/script | 13 ++++++++++++ .../test.toml | 2 ++ bundle/configsync/output.go | 4 +++- cmd/bundle/config_remote_sync.go | 14 +++++++++++++ 7 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml create mode 100644 acceptance/bundle/telemetry/config-remote-sync-error-message/out.test.toml create mode 100644 acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt create mode 100644 acceptance/bundle/telemetry/config-remote-sync-error-message/script create mode 100644 acceptance/bundle/telemetry/config-remote-sync-error-message/test.toml diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml b/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml new file mode 100644 index 00000000000..31bf36ca47a --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml @@ -0,0 +1,13 @@ +bundle: + name: config-remote-sync-telemetry-error-message + +variables: + myvar: + description: a required variable + +targets: + dev: + default: true + bad: + variables: + undefined_var: value diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/out.test.toml b/acceptance/bundle/telemetry/config-remote-sync-error-message/out.test.toml new file mode 100644 index 00000000000..aadf9e4a151 --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/out.test.toml @@ -0,0 +1,3 @@ +Cloud = false +GOOS.windows = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt new file mode 100644 index 00000000000..bbeaae7e2a0 --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -0,0 +1,20 @@ + +>>> musterr [CLI] bundle config-remote-sync +Error: no value assigned to required variable myvar. Variables are usually assigned in databricks.yml, and they can be overridden using "--var", the BUNDLE_VAR_myvar environment variable, or .databricks/bundle//variable-overrides.json + + +>>> cat [OUTPUT_DIR]/out.requests.txt +{ + "error_message": "no value assigned to required variable myvar. Variables are usually assigned in databricks.yml, and they can be overridden using \"--var\", the BUNDLE_VAR_myvar environment variable, or [REDACTED_REL_PATH](json)", + "error_category": "BUNDLE_LOAD_FAILED" +} + +>>> musterr [CLI] bundle config-remote-sync -t bad +Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value + + +>>> cat [OUTPUT_DIR]/out.requests.txt +{ + "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", + "error_category": "BUNDLE_LOAD_FAILED" +} diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script new file mode 100644 index 00000000000..e79ec8a2a2d --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -0,0 +1,13 @@ +# The diagnostic is already printed, so telemetry records it instead of the AlreadyPrinted sentinel. +trace musterr $CLI bundle config-remote-sync + +trace cat "$OUT_REQUESTS" | jq 'select(has("path") and .path == "/telemetry-ext") | .body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | select(. != null) | {error_message, error_category}' + +rm "$OUT_REQUESTS" + +# Selecting the target fails before the auth config is set; the failure is still reported. +trace musterr $CLI bundle config-remote-sync -t bad + +trace cat "$OUT_REQUESTS" | jq 'select(has("path") and .path == "/telemetry-ext") | .body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | select(. != null) | {error_message, error_category}' + +rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/test.toml b/acceptance/bundle/telemetry/config-remote-sync-error-message/test.toml new file mode 100644 index 00000000000..97b2a8e4d49 --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/test.toml @@ -0,0 +1,2 @@ +# config-remote-sync is not supported on Windows. +GOOS.windows = false diff --git a/bundle/configsync/output.go b/bundle/configsync/output.go index 2e61e618b4e..35459aadc77 100644 --- a/bundle/configsync/output.go +++ b/bundle/configsync/output.go @@ -91,7 +91,9 @@ func WriteResult(out io.Writer, jsonOutput bool, stats *Stats, files []FileChang if stats.ErrorCategory == "" { stats.ErrorCategory = protos.BundleConfigRemoteSyncErrorCategoryBundleLoadFailed } - stats.ErrorMessage = telemetry.ScrubErrorMessage(err.Error()) + if stats.ErrorMessage == "" { + stats.ErrorMessage = telemetry.ScrubErrorMessage(err.Error()) + } // A selector that matched nothing: nothing to sync, not a failure. if errors.Is(err, ErrNoMatchingSelector) { status = StatusSkipped diff --git a/cmd/bundle/config_remote_sync.go b/cmd/bundle/config_remote_sync.go index 972810d6f0f..deb2a07dc30 100644 --- a/cmd/bundle/config_remote_sync.go +++ b/cmd/bundle/config_remote_sync.go @@ -18,6 +18,8 @@ import ( "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/log" + "github.com/databricks/cli/libs/logdiag" + "github.com/databricks/cli/libs/telemetry" "github.com/databricks/cli/libs/telemetry/protos" "github.com/spf13/cobra" ) @@ -179,6 +181,18 @@ Examples: }) if b != nil { stats.InGitRepo = b.InGitRepo + // Failing to load or select the target returns before the auth config is + // set; resolve it here so those failures are still reported. + if !cmdctx.HasConfigUsed(cmd.Context()) { + if client, clientErr := b.WorkspaceClientE(cmd.Context()); clientErr == nil { + cmd.SetContext(cmdctx.SetConfigUsed(cmd.Context(), client.Config)) + } + } + } + + // The diagnostics are already on stderr; record the first one instead of the sentinel. + if errors.Is(err, root.ErrAlreadyPrinted) { + stats.ErrorMessage = telemetry.ScrubErrorMessage(logdiag.GetFirstErrorSummary(cmd.Context())) } return configsync.WriteResult(cmd.OutOrStdout(), root.OutputType(cmd) == flags.OutputJSON, &stats, files, changes, skippedChanges, err) From 965f9d357ce0caf6d79bf8bfd07cb13a52e23a44 Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Mon, 16 Nov 2026 17:38:28 +0000 Subject: [PATCH 02/14] Apply the profile flag before resolving auth after a target failure Co-authored-by: Isaac --- .../output.txt | 4 +- .../config-remote-sync-error-message/script | 8 +--- cmd/bundle/config_remote_sync.go | 10 ++--- cmd/root/bundle.go | 15 ++++++++ cmd/root/bundle_test.go | 37 +++++++++++++++++++ 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index bbeaae7e2a0..d3eb572e97f 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -3,7 +3,7 @@ Error: no value assigned to required variable myvar. Variables are usually assigned in databricks.yml, and they can be overridden using "--var", the BUNDLE_VAR_myvar environment variable, or .databricks/bundle//variable-overrides.json ->>> cat [OUTPUT_DIR]/out.requests.txt +>>> print_requests.py //telemetry-ext { "error_message": "no value assigned to required variable myvar. Variables are usually assigned in databricks.yml, and they can be overridden using \"--var\", the BUNDLE_VAR_myvar environment variable, or [REDACTED_REL_PATH](json)", "error_category": "BUNDLE_LOAD_FAILED" @@ -13,7 +13,7 @@ Error: no value assigned to required variable myvar. Variables are usually assig Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value ->>> cat [OUTPUT_DIR]/out.requests.txt +>>> print_requests.py //telemetry-ext { "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", "error_category": "BUNDLE_LOAD_FAILED" diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index e79ec8a2a2d..ad0a7a0a26d 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -1,13 +1,9 @@ # The diagnostic is already printed, so telemetry records it instead of the AlreadyPrinted sentinel. trace musterr $CLI bundle config-remote-sync -trace cat "$OUT_REQUESTS" | jq 'select(has("path") and .path == "/telemetry-ext") | .body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | select(. != null) | {error_message, error_category}' - -rm "$OUT_REQUESTS" +trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' # Selecting the target fails before the auth config is set; the failure is still reported. trace musterr $CLI bundle config-remote-sync -t bad -trace cat "$OUT_REQUESTS" | jq 'select(has("path") and .path == "/telemetry-ext") | .body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | select(. != null) | {error_message, error_category}' - -rm "$OUT_REQUESTS" +trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' diff --git a/cmd/bundle/config_remote_sync.go b/cmd/bundle/config_remote_sync.go index deb2a07dc30..c70ef81434e 100644 --- a/cmd/bundle/config_remote_sync.go +++ b/cmd/bundle/config_remote_sync.go @@ -181,13 +181,9 @@ Examples: }) if b != nil { stats.InGitRepo = b.InGitRepo - // Failing to load or select the target returns before the auth config is - // set; resolve it here so those failures are still reported. - if !cmdctx.HasConfigUsed(cmd.Context()) { - if client, clientErr := b.WorkspaceClientE(cmd.Context()); clientErr == nil { - cmd.SetContext(cmdctx.SetConfigUsed(cmd.Context(), client.Config)) - } - } + // Failing to select the target returns before the auth config is set; + // resolve it here so those failures are still reported. + root.ConfigureBundleAuth(cmd, b) } // The diagnostics are already on stderr; record the first one instead of the sentinel. diff --git a/cmd/root/bundle.go b/cmd/root/bundle.go index a17d88f5fcf..7c0c363df1f 100644 --- a/cmd/root/bundle.go +++ b/cmd/root/bundle.go @@ -217,6 +217,21 @@ func MustConfigureBundle(cmd *cobra.Command) *bundle.Bundle { return b } +// ConfigureBundleAuth sets the auth configuration in the command context when +// configuring the bundle stopped before it did, for example because selecting +// the target failed. It does nothing if the configuration cannot be resolved. +func ConfigureBundleAuth(cmd *cobra.Command, b *bundle.Bundle) { + if cmdctx.HasConfigUsed(cmd.Context()) { + return + } + configureProfile(cmd, b) + client, err := b.WorkspaceClientE(cmd.Context()) + if err != nil { + return + } + cmd.SetContext(cmdctx.SetConfigUsed(cmd.Context(), client.Config)) +} + // TryConfigureBundle configures a bundle on the command context // if there is one, but doesn't fail if there isn't one. func TryConfigureBundle(cmd *cobra.Command) *bundle.Bundle { diff --git a/cmd/root/bundle_test.go b/cmd/root/bundle_test.go index 6116003ea70..78d67b15bac 100644 --- a/cmd/root/bundle_test.go +++ b/cmd/root/bundle_test.go @@ -220,6 +220,43 @@ func TestBundleConfigureProfileFlag(t *testing.T) { assert.Equal(t, "PROFILE-2", cmdctx.ConfigUsed(cmd.Context()).Profile) } +func TestConfigureBundleAuthAfterTargetFailure(t *testing.T) { + testutil.CleanupEnvironment(t) + setupDatabricksCfg(t) + + cmd := emptyCommand(t) + err := cmd.Flag("profile").Value.Set("PROFILE-2") + require.NoError(t, err) + + rootPath := t.TempDir() + t.Chdir(rootPath) + contents := ` +workspace: + profile: PROFILE-1 +targets: + bad: + default: true + variables: + undefined_var: value +` + err = os.WriteFile(filepath.Join(rootPath, "databricks.yml"), []byte(contents), 0o644) + require.NoError(t, err) + + ctx := logdiag.InitContext(cmd.Context()) + logdiag.SetCollect(ctx, true) + cmd.SetContext(ctx) + b := MustConfigureBundle(cmd) + diags := logdiag.FlushCollected(ctx) + require.Len(t, diags, 1) + assert.Contains(t, diags[0].Summary, "variable undefined_var is not defined") + require.False(t, cmdctx.HasConfigUsed(cmd.Context())) + + ConfigureBundleAuth(cmd, b) + assert.Equal(t, "https://a.test", cmdctx.ConfigUsed(cmd.Context()).Host) + assert.Equal(t, "b", cmdctx.ConfigUsed(cmd.Context()).Token) + assert.Equal(t, "PROFILE-2", cmdctx.ConfigUsed(cmd.Context()).Profile) +} + func TestBundleConfigureProfileEnvVariable(t *testing.T) { testutil.CleanupEnvironment(t) From e1c78e01bbe9f2d4fe421ba77a03ca4086a7815a Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Mon, 16 Nov 2026 17:44:50 +0000 Subject: [PATCH 03/14] Skip the auth fallback when a target sets its own workspace Co-authored-by: Isaac --- cmd/root/bundle.go | 14 ++++++++++ cmd/root/bundle_test.go | 62 ++++++++++++++++++++++++++++++----------- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/cmd/root/bundle.go b/cmd/root/bundle.go index 7c0c363df1f..76679391adb 100644 --- a/cmd/root/bundle.go +++ b/cmd/root/bundle.go @@ -224,6 +224,11 @@ func ConfigureBundleAuth(cmd *cobra.Command, b *bundle.Bundle) { if cmdctx.HasConfigUsed(cmd.Context()) { return } + // The target's workspace was never merged. Without an explicit profile, a + // target that sets its own host or profile could point elsewhere, so don't guess. + if getProfile(cmd) == "" && targetsSetWorkspace(b) { + return + } configureProfile(cmd, b) client, err := b.WorkspaceClientE(cmd.Context()) if err != nil { @@ -232,6 +237,15 @@ func ConfigureBundleAuth(cmd *cobra.Command, b *bundle.Bundle) { cmd.SetContext(cmdctx.SetConfigUsed(cmd.Context(), client.Config)) } +func targetsSetWorkspace(b *bundle.Bundle) bool { + for _, t := range b.Config.Targets { + if t != nil && t.Workspace != nil && (t.Workspace.Host != "" || t.Workspace.Profile != "") { + return true + } + } + return false +} + // TryConfigureBundle configures a bundle on the command context // if there is one, but doesn't fail if there isn't one. func TryConfigureBundle(cmd *cobra.Command) *bundle.Bundle { diff --git a/cmd/root/bundle_test.go b/cmd/root/bundle_test.go index 78d67b15bac..5b8311df288 100644 --- a/cmd/root/bundle_test.go +++ b/cmd/root/bundle_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + "github.com/databricks/cli/bundle" "github.com/databricks/cli/internal/testutil" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" @@ -220,26 +221,14 @@ func TestBundleConfigureProfileFlag(t *testing.T) { assert.Equal(t, "PROFILE-2", cmdctx.ConfigUsed(cmd.Context()).Profile) } -func TestConfigureBundleAuthAfterTargetFailure(t *testing.T) { - testutil.CleanupEnvironment(t) +// setupTargetFailure loads a bundle whose default target assigns an undefined +// variable, so configureBundle stops before setting the auth configuration. +func setupTargetFailure(t *testing.T, cmd *cobra.Command, contents string) *bundle.Bundle { setupDatabricksCfg(t) - cmd := emptyCommand(t) - err := cmd.Flag("profile").Value.Set("PROFILE-2") - require.NoError(t, err) - rootPath := t.TempDir() t.Chdir(rootPath) - contents := ` -workspace: - profile: PROFILE-1 -targets: - bad: - default: true - variables: - undefined_var: value -` - err = os.WriteFile(filepath.Join(rootPath, "databricks.yml"), []byte(contents), 0o644) + err := os.WriteFile(filepath.Join(rootPath, "databricks.yml"), []byte(contents), 0o644) require.NoError(t, err) ctx := logdiag.InitContext(cmd.Context()) @@ -250,6 +239,27 @@ targets: require.Len(t, diags, 1) assert.Contains(t, diags[0].Summary, "variable undefined_var is not defined") require.False(t, cmdctx.HasConfigUsed(cmd.Context())) + return b +} + +func TestConfigureBundleAuthAfterTargetFailure(t *testing.T) { + testutil.CleanupEnvironment(t) + + cmd := emptyCommand(t) + err := cmd.Flag("profile").Value.Set("PROFILE-2") + require.NoError(t, err) + + b := setupTargetFailure(t, cmd, ` +workspace: + profile: PROFILE-1 +targets: + bad: + default: true + workspace: + profile: PROFILE-1 + variables: + undefined_var: value +`) ConfigureBundleAuth(cmd, b) assert.Equal(t, "https://a.test", cmdctx.ConfigUsed(cmd.Context()).Host) @@ -257,6 +267,26 @@ targets: assert.Equal(t, "PROFILE-2", cmdctx.ConfigUsed(cmd.Context()).Profile) } +func TestConfigureBundleAuthAfterTargetFailureSkipsTargetWorkspace(t *testing.T) { + testutil.CleanupEnvironment(t) + + cmd := emptyCommand(t) + b := setupTargetFailure(t, cmd, ` +workspace: + host: https://x.test +targets: + bad: + default: true + workspace: + profile: PROFILE-2 + variables: + undefined_var: value +`) + + ConfigureBundleAuth(cmd, b) + assert.False(t, cmdctx.HasConfigUsed(cmd.Context())) +} + func TestBundleConfigureProfileEnvVariable(t *testing.T) { testutil.CleanupEnvironment(t) From d22d823a0c59fd5e435944434b7177a4f8562899 Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Tue, 17 Nov 2026 09:47:02 +0000 Subject: [PATCH 04/14] Report target-load failures only with an explicit profile Co-authored-by: Isaac --- .../output.txt | 15 ++++- .../config-remote-sync-error-message/script | 17 ++++- .../test.toml | 3 + bundle/configsync/telemetry.go | 25 +++++++ cmd/bundle/config_remote_sync.go | 5 +- cmd/root/bundle.go | 29 -------- cmd/root/bundle_test.go | 67 ------------------- 7 files changed, 59 insertions(+), 102 deletions(-) diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index d3eb572e97f..575e821452f 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -9,7 +9,7 @@ Error: no value assigned to required variable myvar. Variables are usually assig "error_category": "BUNDLE_LOAD_FAILED" } ->>> musterr [CLI] bundle config-remote-sync -t bad +>>> musterr [CLI] bundle config-remote-sync -t bad -p myprofile Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value @@ -18,3 +18,16 @@ Error: failed to perform target override for target=bad: variable undefined_var "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", "error_category": "BUNDLE_LOAD_FAILED" } + +>>> musterr [CLI] bundle config-remote-sync -t bad +Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value + + +>>> musterr [CLI] bundle config-remote-sync -t bad -p missing +Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value + + +>>> errcode print_requests.py //telemetry-ext +File [OUTPUT_DIR]/out.requests.txt not found + +Exit code: 1 diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index ad0a7a0a26d..d9dfe0589a9 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -3,7 +3,20 @@ trace musterr $CLI bundle config-remote-sync trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' -# Selecting the target fails before the auth config is set; the failure is still reported. -trace musterr $CLI bundle config-remote-sync -t bad +cat > .databrickscfg < Date: Tue, 17 Nov 2026 10:12:25 +0000 Subject: [PATCH 05/14] Report a missing bundle with an explicit profile too Co-authored-by: Isaac --- .../config-remote-sync-error-message/output.txt | 12 ++++++++++++ .../config-remote-sync-error-message/script | 5 +++++ bundle/configsync/telemetry.go | 11 +++++------ cmd/bundle/config_remote_sync.go | 3 +-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index 575e821452f..b98ebf6e66f 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -19,6 +19,18 @@ Error: failed to perform target override for target=bad: variable undefined_var "error_category": "BUNDLE_LOAD_FAILED" } +>>> musterr [CLI] bundle config-remote-sync -p myprofile +Error: Invalid bundle root DATABRICKS_BUNDLE_ROOT="missing": stat missing: no such file or directory + +The DATABRICKS_BUNDLE_ROOT environment variable must point to an existing directory that contains a bundle configuration file. + + +>>> print_requests.py //telemetry-ext +{ + "error_message": "Invalid bundle root DATABRICKS_BUNDLE_ROOT=\"missing\": stat missing: no such file or directory", + "error_category": "BUNDLE_LOAD_FAILED" +} + >>> musterr [CLI] bundle config-remote-sync -t bad Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index d9dfe0589a9..bf2d02e5ca4 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -15,6 +15,11 @@ trace musterr $CLI bundle config-remote-sync -t bad -p myprofile trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' +# So is a bundle that is not found at all. +DATABRICKS_BUNDLE_ROOT=missing trace musterr $CLI bundle config-remote-sync -p myprofile + +trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' + # Without a profile, or with one that does not resolve, nothing is sent. trace musterr $CLI bundle config-remote-sync -t bad trace musterr $CLI bundle config-remote-sync -t bad -p missing diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index 64c0c8ff26e..a0f2898259a 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -1,6 +1,7 @@ package configsync import ( + "cmp" "context" "slices" "strings" @@ -287,16 +288,14 @@ func (s *Stats) CollectStateIDs(typeAndIDs []string) { } // WithProfileAuth sets the auth config from an explicitly selected profile when -// loading the target failed before the bundle set its own, so the failure can -// still be reported. Without the target its workspace is unknown, so nothing is -// set without a profile or when the profile does not resolve. +// loading the bundle or its target failed before the bundle set its own, so the +// failure can still be reported. Without the target its workspace is unknown, so +// nothing is set without a profile or when the profile does not resolve. func WithProfileAuth(ctx context.Context, profile string) context.Context { if cmdctx.HasConfigUsed(ctx) { return ctx } - if profile == "" { - profile = env.Get(ctx, "DATABRICKS_CONFIG_PROFILE") - } + profile = cmp.Or(profile, env.Get(ctx, "DATABRICKS_CONFIG_PROFILE")) if profile == "" { return ctx } diff --git a/cmd/bundle/config_remote_sync.go b/cmd/bundle/config_remote_sync.go index 2d363b274c1..d3136e7f8bc 100644 --- a/cmd/bundle/config_remote_sync.go +++ b/cmd/bundle/config_remote_sync.go @@ -181,9 +181,8 @@ Examples: }) if b != nil { stats.InGitRepo = b.InGitRepo - // Failing to select the target returns before the auth config is set. - cmd.SetContext(configsync.WithProfileAuth(cmd.Context(), cmd.Flag("profile").Value.String())) } + cmd.SetContext(configsync.WithProfileAuth(cmd.Context(), cmd.Flag("profile").Value.String())) // The diagnostics are already on stderr; record the first one instead of the sentinel. if errors.Is(err, root.ErrAlreadyPrinted) { From 98ad3751b84609c1ba3b40c5e0c2d37160dfeded Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Tue, 17 Nov 2026 10:18:31 +0000 Subject: [PATCH 06/14] Skip the profile fallback when the profile conflicts with the bundle host Co-authored-by: Isaac --- .../conflict/databricks.yml | 10 ++++++++++ .../config-remote-sync-error-message/output.txt | 5 +++++ .../telemetry/config-remote-sync-error-message/script | 5 ++++- bundle/configsync/telemetry.go | 10 ++++++++-- cmd/bundle/config_remote_sync.go | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 acceptance/bundle/telemetry/config-remote-sync-error-message/conflict/databricks.yml diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/conflict/databricks.yml b/acceptance/bundle/telemetry/config-remote-sync-error-message/conflict/databricks.yml new file mode 100644 index 00000000000..30701b900be --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/conflict/databricks.yml @@ -0,0 +1,10 @@ +bundle: + name: config-remote-sync-telemetry-host-conflict + +workspace: + host: https://other.test + +targets: + bad: + variables: + undefined_var: value diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index b98ebf6e66f..28959aecec3 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -39,6 +39,11 @@ Error: failed to perform target override for target=bad: variable undefined_var Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value +>>> musterr [CLI] bundle config-remote-sync -t bad -p myprofile +Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value + +Warn: [hostmetadata] failed to fetch host metadata for https://other.test, will skip for 1m0s + >>> errcode print_requests.py //telemetry-ext File [OUTPUT_DIR]/out.requests.txt not found diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index bf2d02e5ca4..90c2ccfd9b0 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -20,8 +20,11 @@ DATABRICKS_BUNDLE_ROOT=missing trace musterr $CLI bundle config-remote-sync -p m trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' -# Without a profile, or with one that does not resolve, nothing is sent. +# Without a profile, with one that does not resolve, or with one for another host than the bundle's, nothing is sent. trace musterr $CLI bundle config-remote-sync -t bad trace musterr $CLI bundle config-remote-sync -t bad -p missing +cd conflict +trace musterr $CLI bundle config-remote-sync -t bad -p myprofile +cd .. trace errcode print_requests.py //telemetry-ext diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index a0f2898259a..1fa7ed8cb07 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -6,6 +6,7 @@ import ( "slices" "strings" + "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config/engine" "github.com/databricks/cli/bundle/direct/dresources" @@ -291,7 +292,7 @@ func (s *Stats) CollectStateIDs(typeAndIDs []string) { // loading the bundle or its target failed before the bundle set its own, so the // failure can still be reported. Without the target its workspace is unknown, so // nothing is set without a profile or when the profile does not resolve. -func WithProfileAuth(ctx context.Context, profile string) context.Context { +func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile string) context.Context { if cmdctx.HasConfigUsed(ctx) { return ctx } @@ -299,7 +300,12 @@ func WithProfileAuth(ctx context.Context, profile string) context.Context { if profile == "" { return ctx } - w := config.Workspace{Profile: profile} + var w config.Workspace + if b != nil { + // As in bundle auth, a profile for another host than the bundle's is rejected. + w = b.Config.Workspace + } + w.Profile = profile client, err := w.Client(ctx) if err != nil { return ctx diff --git a/cmd/bundle/config_remote_sync.go b/cmd/bundle/config_remote_sync.go index d3136e7f8bc..0b65399fa37 100644 --- a/cmd/bundle/config_remote_sync.go +++ b/cmd/bundle/config_remote_sync.go @@ -182,7 +182,7 @@ Examples: if b != nil { stats.InGitRepo = b.InGitRepo } - cmd.SetContext(configsync.WithProfileAuth(cmd.Context(), cmd.Flag("profile").Value.String())) + cmd.SetContext(configsync.WithProfileAuth(cmd.Context(), b, cmd.Flag("profile").Value.String())) // The diagnostics are already on stderr; record the first one instead of the sentinel. if errors.Is(err, root.ErrAlreadyPrinted) { From b2b792e5a0d3185181f1889f6824be77f4307085 Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Tue, 17 Nov 2026 11:21:51 +0000 Subject: [PATCH 07/14] Resolve the telemetry auth fallback from the profile alone Co-authored-by: Isaac --- .../config-remote-sync-error-message/output.txt | 4 ---- bundle/configsync/telemetry.go | 17 +++++++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index 28959aecec3..285877fbb71 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -42,9 +42,5 @@ Error: failed to perform target override for target=bad: variable undefined_var >>> musterr [CLI] bundle config-remote-sync -t bad -p myprofile Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value -Warn: [hostmetadata] failed to fetch host metadata for https://other.test, will skip for 1m0s >>> errcode print_requests.py //telemetry-ext -File [OUTPUT_DIR]/out.requests.txt not found - -Exit code: 1 diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index 1fa7ed8cb07..9341cc62d16 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -17,6 +17,7 @@ import ( "github.com/databricks/cli/libs/structs/structpath" "github.com/databricks/cli/libs/telemetry" "github.com/databricks/cli/libs/telemetry/protos" + sdkconfig "github.com/databricks/databricks-sdk-go/config" ) // recoverTelemetry swallows any panic raised while collecting or emitting @@ -292,6 +293,8 @@ func (s *Stats) CollectStateIDs(typeAndIDs []string) { // loading the bundle or its target failed before the bundle set its own, so the // failure can still be reported. Without the target its workspace is unknown, so // nothing is set without a profile or when the profile does not resolve. +// Only the profile is used: the bundle config can name other hosts, and +// telemetry must not be sent there. func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile string) context.Context { if cmdctx.HasConfigUsed(ctx) { return ctx @@ -300,16 +303,18 @@ func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile string) cont if profile == "" { return ctx } - var w config.Workspace - if b != nil { - // As in bundle auth, a profile for another host than the bundle's is rejected. - w = b.Config.Workspace - } - w.Profile = profile + w := config.Workspace{Profile: profile} client, err := w.Client(ctx) if err != nil { return ctx } + // As in bundle auth, a profile for another host than the bundle's is rejected. + if b != nil && b.Config.Workspace.Host != "" { + bundleHost := (&sdkconfig.Config{Host: b.Config.Workspace.Host}).CanonicalHostName() + if bundleHost != client.Config.CanonicalHostName() { + return ctx + } + } return cmdctx.SetConfigUsed(ctx, client.Config) } From a153117a904667afe9c079c989aea35e192f7c81 Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Tue, 17 Nov 2026 11:28:42 +0000 Subject: [PATCH 08/14] Use withdir for the host conflict case Co-authored-by: Isaac --- .../bundle/telemetry/config-remote-sync-error-message/script | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index 90c2ccfd9b0..5a036946824 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -23,8 +23,6 @@ trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .en # Without a profile, with one that does not resolve, or with one for another host than the bundle's, nothing is sent. trace musterr $CLI bundle config-remote-sync -t bad trace musterr $CLI bundle config-remote-sync -t bad -p missing -cd conflict -trace musterr $CLI bundle config-remote-sync -t bad -p myprofile -cd .. +withdir conflict trace musterr $CLI bundle config-remote-sync -t bad -p myprofile trace errcode print_requests.py //telemetry-ext From 659809856785627d921dd76a67ba56f9182fc536 Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Fri, 20 Nov 2026 11:53:49 +0000 Subject: [PATCH 09/14] Bound the profile fallback, skip it when telemetry is disabled, and check the target's host Co-authored-by: Isaac --- .../databricks.yml | 5 ++ .../output.txt | 22 +++++++ .../same-host/databricks.yml | 10 +++ .../config-remote-sync-error-message/script | 10 ++- bundle/configsync/telemetry.go | 66 ++++++++++++++++--- cmd/bundle/config_remote_sync.go | 2 +- 6 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 acceptance/bundle/telemetry/config-remote-sync-error-message/same-host/databricks.yml diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml b/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml index 31bf36ca47a..f01549a3b25 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml @@ -11,3 +11,8 @@ targets: bad: variables: undefined_var: value + other: + workspace: + host: https://other.test + variables: + undefined_var: value diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index 285877fbb71..831f68b0b67 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -19,6 +19,24 @@ Error: failed to perform target override for target=bad: variable undefined_var "error_category": "BUNDLE_LOAD_FAILED" } +>>> musterr [CLI] bundle config-remote-sync -t bad +Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value + + +>>> musterr [CLI] bundle config-remote-sync -t bad -p myprofile +Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value + + +>>> print_requests.py //telemetry-ext +{ + "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", + "error_category": "BUNDLE_LOAD_FAILED" +} +{ + "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", + "error_category": "BUNDLE_LOAD_FAILED" +} + >>> musterr [CLI] bundle config-remote-sync -p myprofile Error: Invalid bundle root DATABRICKS_BUNDLE_ROOT="missing": stat missing: no such file or directory @@ -43,4 +61,8 @@ Error: failed to perform target override for target=bad: variable undefined_var Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value +>>> musterr [CLI] bundle config-remote-sync -t other -p myprofile +Error: failed to perform target override for target=other: variable undefined_var is not defined but is assigned a value + + >>> errcode print_requests.py //telemetry-ext diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/same-host/databricks.yml b/acceptance/bundle/telemetry/config-remote-sync-error-message/same-host/databricks.yml new file mode 100644 index 00000000000..a34914c9fa7 --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/same-host/databricks.yml @@ -0,0 +1,10 @@ +bundle: + name: config-remote-sync-telemetry-same-host + +workspace: + host: $DATABRICKS_HOST + +targets: + bad: + variables: + undefined_var: value diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index 5a036946824..a8a40b7119d 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -15,14 +15,22 @@ trace musterr $CLI bundle config-remote-sync -t bad -p myprofile trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' +# So is one with the profile from DATABRICKS_CONFIG_PROFILE, and one where the bundle's host is the profile's. +DATABRICKS_CONFIG_PROFILE=myprofile trace musterr $CLI bundle config-remote-sync -t bad +envsubst < same-host/databricks.yml > out && mv out same-host/databricks.yml +withdir same-host trace musterr $CLI bundle config-remote-sync -t bad -p myprofile + +trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' + # So is a bundle that is not found at all. DATABRICKS_BUNDLE_ROOT=missing trace musterr $CLI bundle config-remote-sync -p myprofile trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' -# Without a profile, with one that does not resolve, or with one for another host than the bundle's, nothing is sent. +# Without a profile, with one that does not resolve, or with one for another host than the bundle's or the target's, nothing is sent. trace musterr $CLI bundle config-remote-sync -t bad trace musterr $CLI bundle config-remote-sync -t bad -p missing withdir conflict trace musterr $CLI bundle config-remote-sync -t bad -p myprofile +trace musterr $CLI bundle config-remote-sync -t other -p myprofile trace errcode print_requests.py //telemetry-ext diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index 9341cc62d16..5fabf65e312 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -3,13 +3,16 @@ package configsync import ( "cmp" "context" + "fmt" "slices" "strings" + "time" "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config/engine" "github.com/databricks/cli/bundle/direct/dresources" + bundleenv "github.com/databricks/cli/bundle/env" "github.com/databricks/cli/bundle/statemgmt" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/env" @@ -289,33 +292,78 @@ func (s *Stats) CollectStateIDs(typeAndIDs []string) { s.StateResourceIDs = collectResourceIDs(typeAndIDs) } +// profileAuthBudget bounds how long WithProfileAuth waits for the profile to +// resolve, which fetches host metadata from the profile's host. Matches the +// telemetry upload's own default timeout. +const profileAuthBudget = 3 * time.Second + // WithProfileAuth sets the auth config from an explicitly selected profile when // loading the bundle or its target failed before the bundle set its own, so the // failure can still be reported. Without the target its workspace is unknown, so // nothing is set without a profile or when the profile does not resolve. // Only the profile is used: the bundle config can name other hosts, and // telemetry must not be sent there. -func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile string) context.Context { - if cmdctx.HasConfigUsed(ctx) { +func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile, target string) context.Context { + if cmdctx.HasConfigUsed(ctx) || telemetry.Disabled(ctx) { return ctx } profile = cmp.Or(profile, env.Get(ctx, "DATABRICKS_CONFIG_PROFILE")) if profile == "" { return ctx } - w := config.Workspace{Profile: profile} - client, err := w.Client(ctx) + cfg, err := resolveProfile(ctx, profile) if err != nil { + log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s: %v", profile, err) return ctx } // As in bundle auth, a profile for another host than the bundle's is rejected. - if b != nil && b.Config.Workspace.Host != "" { - bundleHost := (&sdkconfig.Config{Host: b.Config.Workspace.Host}).CanonicalHostName() - if bundleHost != client.Config.CanonicalHostName() { - return ctx + if b != nil { + if target == "" { + target, _ = bundleenv.Target(ctx) + } + hosts := []string{b.Config.Workspace.Host} + // Targets are only left when merging the target failed, so its host is not + // in the root config yet. Without a named target, the default can be any. + for name, t := range b.Config.Targets { + if (target == "" || name == target) && t != nil && t.Workspace != nil { + hosts = append(hosts, t.Workspace.Host) + } + } + for _, host := range hosts { + if host != "" && (&sdkconfig.Config{Host: host}).CanonicalHostName() != cfg.CanonicalHostName() { + log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s is for another host than the bundle's %s", profile, host) + return ctx + } + } + } + return cmdctx.SetConfigUsed(ctx, cfg) +} + +// resolveProfile resolves the profile within profileAuthBudget. The SDK fetches +// host metadata without a context, so a resolution past the budget is left to +// finish in the background. +func resolveProfile(ctx context.Context, profile string) (*sdkconfig.Config, error) { + type result struct { + cfg *sdkconfig.Config + err error + } + done := make(chan result, 1) + go func() { + defer recoverTelemetry(ctx) + w := config.Workspace{Profile: profile} + client, err := w.Client(ctx) + if err != nil { + done <- result{err: err} + return } + done <- result{cfg: client.Config} + }() + select { + case r := <-done: + return r.cfg, r.err + case <-time.After(profileAuthBudget): + return nil, fmt.Errorf("not resolved within %s", profileAuthBudget) } - return cmdctx.SetConfigUsed(ctx, client.Config) } // LogTelemetry emits the BundleConfigRemoteSyncEvent for this run. diff --git a/cmd/bundle/config_remote_sync.go b/cmd/bundle/config_remote_sync.go index 0b65399fa37..921f4a60f04 100644 --- a/cmd/bundle/config_remote_sync.go +++ b/cmd/bundle/config_remote_sync.go @@ -182,7 +182,7 @@ Examples: if b != nil { stats.InGitRepo = b.InGitRepo } - cmd.SetContext(configsync.WithProfileAuth(cmd.Context(), b, cmd.Flag("profile").Value.String())) + cmd.SetContext(configsync.WithProfileAuth(cmd.Context(), b, cmd.Flag("profile").Value.String(), cmd.Flag("target").Value.String())) // The diagnostics are already on stderr; record the first one instead of the sentinel. if errors.Is(err, root.ErrAlreadyPrinted) { From 8c318103f37b82ff20a191c46bd3ecbf55a13e06 Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Fri, 20 Nov 2026 12:08:52 +0000 Subject: [PATCH 10/14] Skip the fallback on bundle auth errors, use the selected target's host, and never refresh tokens for it Co-authored-by: Isaac --- .../conflict/databricks.yml | 5 ++ .../databricks.yml | 3 + .../default-target/databricks.yml | 11 ++++ .../output.txt | 20 +++++++ .../config-remote-sync-error-message/script | 10 +++- bundle/configsync/telemetry.go | 59 +++++++++++++------ cmd/bundle/config_remote_sync.go | 4 +- 7 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 acceptance/bundle/telemetry/config-remote-sync-error-message/default-target/databricks.yml diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/conflict/databricks.yml b/acceptance/bundle/telemetry/config-remote-sync-error-message/conflict/databricks.yml index 30701b900be..3584241403e 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/conflict/databricks.yml +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/conflict/databricks.yml @@ -8,3 +8,8 @@ targets: bad: variables: undefined_var: value + own-host: + workspace: + host: $DATABRICKS_HOST + variables: + undefined_var: value diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml b/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml index f01549a3b25..ced813ab3a0 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/databricks.yml @@ -16,3 +16,6 @@ targets: host: https://other.test variables: undefined_var: value + auth-error: + workspace: + client_id: x diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/default-target/databricks.yml b/acceptance/bundle/telemetry/config-remote-sync-error-message/default-target/databricks.yml new file mode 100644 index 00000000000..ea55df91dbb --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/default-target/databricks.yml @@ -0,0 +1,11 @@ +bundle: + name: config-remote-sync-telemetry-default-target + +targets: + bad: + default: true + variables: + undefined_var: value + other: + workspace: + host: https://other.test diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index 831f68b0b67..c35196646d6 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -27,6 +27,14 @@ Error: failed to perform target override for target=bad: variable undefined_var Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value +>>> musterr [CLI] bundle config-remote-sync -t own-host -p myprofile +Error: failed to perform target override for target=own-host: variable undefined_var is not defined but is assigned a value + + +>>> musterr [CLI] bundle config-remote-sync -p myprofile +Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value + + >>> print_requests.py //telemetry-ext { "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", @@ -36,6 +44,14 @@ Error: failed to perform target override for target=bad: variable undefined_var "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", "error_category": "BUNDLE_LOAD_FAILED" } +{ + "error_message": "failed to perform target override for target=own-host: variable undefined_var is not defined but is assigned a value", + "error_category": "BUNDLE_LOAD_FAILED" +} +{ + "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", + "error_category": "BUNDLE_LOAD_FAILED" +} >>> musterr [CLI] bundle config-remote-sync -p myprofile Error: Invalid bundle root DATABRICKS_BUNDLE_ROOT="missing": stat missing: no such file or directory @@ -65,4 +81,8 @@ Error: failed to perform target override for target=bad: variable undefined_var Error: failed to perform target override for target=other: variable undefined_var is not defined but is assigned a value +>>> musterr [CLI] bundle config-remote-sync -t auth-error -p myprofile +Error: cannot resolve bundle auth configuration: validate: more than one authorization method configured: oauth and pat. Config: host=[DATABRICKS_URL], token=***, profile=myprofile, config_file=[TEST_TMP_DIR]/.databrickscfg, client_id=x, databricks_cli_path=[CLI]. Env: DATABRICKS_HOST, DATABRICKS_TOKEN, DATABRICKS_CONFIG_FILE, DATABRICKS_CLI_PATH + + >>> errcode print_requests.py //telemetry-ext diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index a8a40b7119d..c70b6b36670 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -15,10 +15,14 @@ trace musterr $CLI bundle config-remote-sync -t bad -p myprofile trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' -# So is one with the profile from DATABRICKS_CONFIG_PROFILE, and one where the bundle's host is the profile's. +# So is one with the profile from DATABRICKS_CONFIG_PROFILE, one where the bundle's or the target's host is the +# profile's, and a default target next to a target on another host. DATABRICKS_CONFIG_PROFILE=myprofile trace musterr $CLI bundle config-remote-sync -t bad envsubst < same-host/databricks.yml > out && mv out same-host/databricks.yml withdir same-host trace musterr $CLI bundle config-remote-sync -t bad -p myprofile +envsubst < conflict/databricks.yml > out && mv out conflict/databricks.yml +withdir conflict trace musterr $CLI bundle config-remote-sync -t own-host -p myprofile +withdir default-target trace musterr $CLI bundle config-remote-sync -p myprofile trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' @@ -27,10 +31,12 @@ DATABRICKS_BUNDLE_ROOT=missing trace musterr $CLI bundle config-remote-sync -p m trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' -# Without a profile, with one that does not resolve, or with one for another host than the bundle's or the target's, nothing is sent. +# Without a profile, with one that does not resolve, with one for another host than the bundle's or the target's, +# or when the bundle's own auth fails, nothing is sent. trace musterr $CLI bundle config-remote-sync -t bad trace musterr $CLI bundle config-remote-sync -t bad -p missing withdir conflict trace musterr $CLI bundle config-remote-sync -t bad -p myprofile trace musterr $CLI bundle config-remote-sync -t other -p myprofile +trace musterr $CLI bundle config-remote-sync -t auth-error -p myprofile trace errcode print_requests.py //telemetry-ext diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index 5fabf65e312..93d4e798c8f 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -14,6 +14,7 @@ import ( "github.com/databricks/cli/bundle/direct/dresources" bundleenv "github.com/databricks/cli/bundle/env" "github.com/databricks/cli/bundle/statemgmt" + "github.com/databricks/cli/libs/auth" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/env" "github.com/databricks/cli/libs/log" @@ -307,6 +308,11 @@ func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile, target stri if cmdctx.HasConfigUsed(ctx) || telemetry.Disabled(ctx) { return ctx } + // With the target selected, only the bundle's own auth can have failed, and + // auth errors are not reported. + if b != nil && b.Config.Bundle.Target != "" { + return ctx + } profile = cmp.Or(profile, env.Get(ctx, "DATABRICKS_CONFIG_PROFILE")) if profile == "" { return ctx @@ -318,30 +324,44 @@ func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile, target stri } // As in bundle auth, a profile for another host than the bundle's is rejected. if b != nil { - if target == "" { - target, _ = bundleenv.Target(ctx) + host := b.Config.Workspace.Host + // The target was not merged, so its own host is not in the root config yet. + if t := b.Config.Targets[selectedTarget(ctx, b, target)]; t != nil && t.Workspace != nil && t.Workspace.Host != "" { + host = t.Workspace.Host } - hosts := []string{b.Config.Workspace.Host} - // Targets are only left when merging the target failed, so its host is not - // in the root config yet. Without a named target, the default can be any. - for name, t := range b.Config.Targets { - if (target == "" || name == target) && t != nil && t.Workspace != nil { - hosts = append(hosts, t.Workspace.Host) - } - } - for _, host := range hosts { - if host != "" && (&sdkconfig.Config{Host: host}).CanonicalHostName() != cfg.CanonicalHostName() { - log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s is for another host than the bundle's %s", profile, host) - return ctx - } + if host != "" && (&sdkconfig.Config{Host: host}).CanonicalHostName() != cfg.CanonicalHostName() { + log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s is for another host than the bundle's %s", profile, host) + return ctx } } return cmdctx.SetConfigUsed(ctx, cfg) } +// selectedTarget returns the target loading the bundle selects: the named one, +// else DATABRICKS_BUNDLE_TARGET, else the only target or the one marked default. +func selectedTarget(ctx context.Context, b *bundle.Bundle, name string) string { + if name == "" { + name, _ = bundleenv.Target(ctx) + } + if name != "" { + return name + } + var defaults []string + for n, t := range b.Config.Targets { + if len(b.Config.Targets) == 1 || (t != nil && config.IsExplicitlyEnabled(t.Default)) { + defaults = append(defaults, n) + } + } + if len(defaults) != 1 { + return "" + } + return defaults[0] +} + // resolveProfile resolves the profile within profileAuthBudget. The SDK fetches // host metadata without a context, so a resolution past the budget is left to -// finish in the background. +// finish in the background. The upload may be cut off at exit, so its auth never +// refreshes an OAuth token. func resolveProfile(ctx context.Context, profile string) (*sdkconfig.Config, error) { type result struct { cfg *sdkconfig.Config @@ -349,13 +369,18 @@ func resolveProfile(ctx context.Context, profile string) (*sdkconfig.Config, err } done := make(chan result, 1) go func() { - defer recoverTelemetry(ctx) + defer func() { + if r := recover(); r != nil { + done <- result{err: fmt.Errorf("panic: %v", r)} + } + }() w := config.Workspace{Profile: profile} client, err := w.Client(ctx) if err != nil { done <- result{err: err} return } + client.Config.Credentials = auth.CredentialsWithoutRefresh() done <- result{cfg: client.Config} }() select { diff --git a/cmd/bundle/config_remote_sync.go b/cmd/bundle/config_remote_sync.go index 921f4a60f04..8813cc234d3 100644 --- a/cmd/bundle/config_remote_sync.go +++ b/cmd/bundle/config_remote_sync.go @@ -1,6 +1,7 @@ package bundle import ( + "cmp" "context" "errors" "fmt" @@ -182,7 +183,8 @@ Examples: if b != nil { stats.InGitRepo = b.InGitRepo } - cmd.SetContext(configsync.WithProfileAuth(cmd.Context(), b, cmd.Flag("profile").Value.String(), cmd.Flag("target").Value.String())) + target := cmp.Or(cmd.Flag("target").Value.String(), cmd.Flag("environment").Value.String()) + cmd.SetContext(configsync.WithProfileAuth(cmd.Context(), b, cmd.Flag("profile").Value.String(), target)) // The diagnostics are already on stderr; record the first one instead of the sentinel. if errors.Is(err, root.ErrAlreadyPrinted) { From 1d903da4e7a6fff9948e30d4f1e1b2d9caacdd7a Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Fri, 20 Nov 2026 12:21:28 +0000 Subject: [PATCH 11/14] Log the remaining fallback skips and cover DATABRICKS_BUNDLE_TARGET Co-authored-by: Isaac --- .../telemetry/config-remote-sync-error-message/output.txt | 4 ++++ .../bundle/telemetry/config-remote-sync-error-message/script | 1 + bundle/configsync/telemetry.go | 2 ++ 3 files changed, 7 insertions(+) diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index c35196646d6..9a893fb1976 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -81,6 +81,10 @@ Error: failed to perform target override for target=bad: variable undefined_var Error: failed to perform target override for target=other: variable undefined_var is not defined but is assigned a value +>>> musterr [CLI] bundle config-remote-sync -p myprofile +Error: failed to perform target override for target=other: variable undefined_var is not defined but is assigned a value + + >>> musterr [CLI] bundle config-remote-sync -t auth-error -p myprofile Error: cannot resolve bundle auth configuration: validate: more than one authorization method configured: oauth and pat. Config: host=[DATABRICKS_URL], token=***, profile=myprofile, config_file=[TEST_TMP_DIR]/.databrickscfg, client_id=x, databricks_cli_path=[CLI]. Env: DATABRICKS_HOST, DATABRICKS_TOKEN, DATABRICKS_CONFIG_FILE, DATABRICKS_CLI_PATH diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index c70b6b36670..2adea7d5c05 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -37,6 +37,7 @@ trace musterr $CLI bundle config-remote-sync -t bad trace musterr $CLI bundle config-remote-sync -t bad -p missing withdir conflict trace musterr $CLI bundle config-remote-sync -t bad -p myprofile trace musterr $CLI bundle config-remote-sync -t other -p myprofile +DATABRICKS_BUNDLE_TARGET=other trace musterr $CLI bundle config-remote-sync -p myprofile trace musterr $CLI bundle config-remote-sync -t auth-error -p myprofile trace errcode print_requests.py //telemetry-ext diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index 93d4e798c8f..c7e72eead37 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -311,10 +311,12 @@ func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile, target stri // With the target selected, only the bundle's own auth can have failed, and // auth errors are not reported. if b != nil && b.Config.Bundle.Target != "" { + log.Debugf(ctx, "config-remote-sync telemetry skipped: bundle auth failed") return ctx } profile = cmp.Or(profile, env.Get(ctx, "DATABRICKS_CONFIG_PROFILE")) if profile == "" { + log.Debugf(ctx, "config-remote-sync telemetry skipped: no profile selected") return ctx } cfg, err := resolveProfile(ctx, profile) From 6277854681ebecfd7fd14099e0ca1fa5d294c642 Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Fri, 20 Nov 2026 14:52:49 +0000 Subject: [PATCH 12/14] Let the telemetry upload resolve the profile fallback and read the profile's host from the config file Co-authored-by: Isaac --- .../output.txt | 3 + bundle/configsync/telemetry.go | 73 ++++++------------- 2 files changed, 26 insertions(+), 50 deletions(-) diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index 9a893fb1976..57620ed0ef5 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -90,3 +90,6 @@ Error: cannot resolve bundle auth configuration: validate: more than one authori >>> errcode print_requests.py //telemetry-ext +File [OUTPUT_DIR]/out.requests.txt not found + +Exit code: 1 diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index c7e72eead37..63b8187b940 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -3,10 +3,8 @@ package configsync import ( "cmp" "context" - "fmt" "slices" "strings" - "time" "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" @@ -16,6 +14,7 @@ import ( "github.com/databricks/cli/bundle/statemgmt" "github.com/databricks/cli/libs/auth" "github.com/databricks/cli/libs/cmdctx" + "github.com/databricks/cli/libs/databrickscfg/profile" "github.com/databricks/cli/libs/env" "github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/structs/structpath" @@ -293,18 +292,17 @@ func (s *Stats) CollectStateIDs(typeAndIDs []string) { s.StateResourceIDs = collectResourceIDs(typeAndIDs) } -// profileAuthBudget bounds how long WithProfileAuth waits for the profile to -// resolve, which fetches host metadata from the profile's host. Matches the -// telemetry upload's own default timeout. -const profileAuthBudget = 3 * time.Second - // WithProfileAuth sets the auth config from an explicitly selected profile when // loading the bundle or its target failed before the bundle set its own, so the // failure can still be reported. Without the target its workspace is unknown, so -// nothing is set without a profile or when the profile does not resolve. +// nothing is set without a profile or when the profile is not found. // Only the profile is used: the bundle config can name other hosts, and -// telemetry must not be sent there. -func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile, target string) context.Context { +// telemetry must not be sent there. The config is left for the upload to +// resolve within its own timeout, and as the upload may be cut off at exit, its +// auth never refreshes an OAuth token. +func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profileName, target string) (out context.Context) { + out = ctx + defer recoverTelemetry(ctx) if cmdctx.HasConfigUsed(ctx) || telemetry.Disabled(ctx) { return ctx } @@ -314,14 +312,14 @@ func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile, target stri log.Debugf(ctx, "config-remote-sync telemetry skipped: bundle auth failed") return ctx } - profile = cmp.Or(profile, env.Get(ctx, "DATABRICKS_CONFIG_PROFILE")) - if profile == "" { + profileName = cmp.Or(profileName, env.Get(ctx, "DATABRICKS_CONFIG_PROFILE")) + if profileName == "" { log.Debugf(ctx, "config-remote-sync telemetry skipped: no profile selected") return ctx } - cfg, err := resolveProfile(ctx, profile) - if err != nil { - log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s: %v", profile, err) + profiles, err := profile.GetProfiler(ctx).LoadProfiles(ctx, profile.WithName(profileName)) + if err != nil || len(profiles) == 0 { + log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s not found", profileName) return ctx } // As in bundle auth, a profile for another host than the bundle's is rejected. @@ -331,14 +329,22 @@ func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profile, target stri if t := b.Config.Targets[selectedTarget(ctx, b, target)]; t != nil && t.Workspace != nil && t.Workspace.Host != "" { host = t.Workspace.Host } - if host != "" && (&sdkconfig.Config{Host: host}).CanonicalHostName() != cfg.CanonicalHostName() { - log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s is for another host than the bundle's %s", profile, host) + // DATABRICKS_HOST takes precedence over the profile's host when the config resolves. + profileHost := cmp.Or(env.Get(ctx, "DATABRICKS_HOST"), profiles[0].Host) + if host != "" && canonicalHost(host) != canonicalHost(profileHost) { + log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s is for another host than the bundle's %s", profileName, host) return ctx } } + cfg := (&config.Workspace{Profile: profileName}).Config(ctx) + cfg.Credentials = auth.CredentialsWithoutRefresh() return cmdctx.SetConfigUsed(ctx, cfg) } +func canonicalHost(host string) string { + return (&sdkconfig.Config{Host: host}).CanonicalHostName() +} + // selectedTarget returns the target loading the bundle selects: the named one, // else DATABRICKS_BUNDLE_TARGET, else the only target or the one marked default. func selectedTarget(ctx context.Context, b *bundle.Bundle, name string) string { @@ -360,39 +366,6 @@ func selectedTarget(ctx context.Context, b *bundle.Bundle, name string) string { return defaults[0] } -// resolveProfile resolves the profile within profileAuthBudget. The SDK fetches -// host metadata without a context, so a resolution past the budget is left to -// finish in the background. The upload may be cut off at exit, so its auth never -// refreshes an OAuth token. -func resolveProfile(ctx context.Context, profile string) (*sdkconfig.Config, error) { - type result struct { - cfg *sdkconfig.Config - err error - } - done := make(chan result, 1) - go func() { - defer func() { - if r := recover(); r != nil { - done <- result{err: fmt.Errorf("panic: %v", r)} - } - }() - w := config.Workspace{Profile: profile} - client, err := w.Client(ctx) - if err != nil { - done <- result{err: err} - return - } - client.Config.Credentials = auth.CredentialsWithoutRefresh() - done <- result{cfg: client.Config} - }() - select { - case r := <-done: - return r.cfg, r.err - case <-time.After(profileAuthBudget): - return nil, fmt.Errorf("not resolved within %s", profileAuthBudget) - } -} - // LogTelemetry emits the BundleConfigRemoteSyncEvent for this run. func (s *Stats) LogTelemetry(ctx context.Context) { defer recoverTelemetry(ctx) From 7eb3860cd49a868609f394f13796495b73bb9aa0 Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Fri, 20 Nov 2026 14:56:57 +0000 Subject: [PATCH 13/14] Let the profile win over auth env vars in the telemetry fallback Co-authored-by: Isaac --- .../telemetry/config-remote-sync-error-message/output.txt | 8 ++++++++ .../telemetry/config-remote-sync-error-message/script | 4 +++- bundle/configsync/telemetry.go | 8 +++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index 57620ed0ef5..befdfa11fe1 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -27,6 +27,10 @@ Error: failed to perform target override for target=bad: variable undefined_var Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value +>>> musterr [CLI] bundle config-remote-sync -t bad -p myprofile +Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value + + >>> musterr [CLI] bundle config-remote-sync -t own-host -p myprofile Error: failed to perform target override for target=own-host: variable undefined_var is not defined but is assigned a value @@ -44,6 +48,10 @@ Error: failed to perform target override for target=bad: variable undefined_var "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", "error_category": "BUNDLE_LOAD_FAILED" } +{ + "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", + "error_category": "BUNDLE_LOAD_FAILED" +} { "error_message": "failed to perform target override for target=own-host: variable undefined_var is not defined but is assigned a value", "error_category": "BUNDLE_LOAD_FAILED" diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index 2adea7d5c05..ed2793528b3 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -16,10 +16,12 @@ trace musterr $CLI bundle config-remote-sync -t bad -p myprofile trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' # So is one with the profile from DATABRICKS_CONFIG_PROFILE, one where the bundle's or the target's host is the -# profile's, and a default target next to a target on another host. +# profile's (also to the profile's host when DATABRICKS_HOST names another), and a default target next to a target +# on another host. DATABRICKS_CONFIG_PROFILE=myprofile trace musterr $CLI bundle config-remote-sync -t bad envsubst < same-host/databricks.yml > out && mv out same-host/databricks.yml withdir same-host trace musterr $CLI bundle config-remote-sync -t bad -p myprofile +DATABRICKS_HOST=https://other.test withdir same-host trace musterr $CLI bundle config-remote-sync -t bad -p myprofile envsubst < conflict/databricks.yml > out && mv out conflict/databricks.yml withdir conflict trace musterr $CLI bundle config-remote-sync -t own-host -p myprofile withdir default-target trace musterr $CLI bundle config-remote-sync -p myprofile diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index 63b8187b940..ae2324b1200 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -14,6 +14,7 @@ import ( "github.com/databricks/cli/bundle/statemgmt" "github.com/databricks/cli/libs/auth" "github.com/databricks/cli/libs/cmdctx" + "github.com/databricks/cli/libs/databrickscfg" "github.com/databricks/cli/libs/databrickscfg/profile" "github.com/databricks/cli/libs/env" "github.com/databricks/cli/libs/log" @@ -329,14 +330,15 @@ func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profileName, target if t := b.Config.Targets[selectedTarget(ctx, b, target)]; t != nil && t.Workspace != nil && t.Workspace.Host != "" { host = t.Workspace.Host } - // DATABRICKS_HOST takes precedence over the profile's host when the config resolves. - profileHost := cmp.Or(env.Get(ctx, "DATABRICKS_HOST"), profiles[0].Host) - if host != "" && canonicalHost(host) != canonicalHost(profileHost) { + if host != "" && canonicalHost(host) != canonicalHost(profiles[0].Host) { log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s is for another host than the bundle's %s", profileName, host) return ctx } } cfg := (&config.Workspace{Profile: profileName}).Config(ctx) + // As for a bundle's own profile, the profile wins over auth env vars, so the + // upload goes to the host checked above. + cfg.Loaders = databrickscfg.ProfileAuthLoaders cfg.Credentials = auth.CredentialsWithoutRefresh() return cmdctx.SetConfigUsed(ctx, cfg) } From 4f09cc008af0b16da0bf4121b1b488ba354489ed Mon Sep 17 00:00:00 2001 From: "ilya.kuznetsov" Date: Fri, 20 Nov 2026 15:01:17 +0000 Subject: [PATCH 14/14] Skip the telemetry fallback for a profile on another workspace of the bundle's host Co-authored-by: Isaac --- .../other-workspace/databricks.yml | 16 ++++++++++++++ .../output.txt | 12 ++++++++++ .../config-remote-sync-error-message/script | 16 ++++++++++---- bundle/configsync/telemetry.go | 22 +++++++++++++------ 4 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 acceptance/bundle/telemetry/config-remote-sync-error-message/other-workspace/databricks.yml diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/other-workspace/databricks.yml b/acceptance/bundle/telemetry/config-remote-sync-error-message/other-workspace/databricks.yml new file mode 100644 index 00000000000..cba3a6f717e --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/other-workspace/databricks.yml @@ -0,0 +1,16 @@ +bundle: + name: config-remote-sync-telemetry-other-workspace + +workspace: + host: $DATABRICKS_HOST + workspace_id: "1111" + +targets: + bad: + variables: + undefined_var: value + profile-workspace: + workspace: + workspace_id: "2222" + variables: + undefined_var: value diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt index befdfa11fe1..16a2dac71a4 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/output.txt @@ -35,6 +35,10 @@ Error: failed to perform target override for target=bad: variable undefined_var Error: failed to perform target override for target=own-host: variable undefined_var is not defined but is assigned a value +>>> musterr [CLI] bundle config-remote-sync -t profile-workspace -p workspace2222 +Error: failed to perform target override for target=profile-workspace: variable undefined_var is not defined but is assigned a value + + >>> musterr [CLI] bundle config-remote-sync -p myprofile Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value @@ -56,6 +60,10 @@ Error: failed to perform target override for target=bad: variable undefined_var "error_message": "failed to perform target override for target=own-host: variable undefined_var is not defined but is assigned a value", "error_category": "BUNDLE_LOAD_FAILED" } +{ + "error_message": "failed to perform target override for target=profile-workspace: variable undefined_var is not defined but is assigned a value", + "error_category": "BUNDLE_LOAD_FAILED" +} { "error_message": "failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value", "error_category": "BUNDLE_LOAD_FAILED" @@ -85,6 +93,10 @@ Error: failed to perform target override for target=bad: variable undefined_var Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value +>>> musterr [CLI] bundle config-remote-sync -t bad -p workspace2222 +Error: failed to perform target override for target=bad: variable undefined_var is not defined but is assigned a value + + >>> musterr [CLI] bundle config-remote-sync -t other -p myprofile Error: failed to perform target override for target=other: variable undefined_var is not defined but is assigned a value diff --git a/acceptance/bundle/telemetry/config-remote-sync-error-message/script b/acceptance/bundle/telemetry/config-remote-sync-error-message/script index ed2793528b3..7855baf7785 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-error-message/script +++ b/acceptance/bundle/telemetry/config-remote-sync-error-message/script @@ -7,6 +7,11 @@ cat > .databrickscfg < out && mv out same-host/databricks.yml withdir same-host trace musterr $CLI bundle config-remote-sync -t bad -p myprofile DATABRICKS_HOST=https://other.test withdir same-host trace musterr $CLI bundle config-remote-sync -t bad -p myprofile envsubst < conflict/databricks.yml > out && mv out conflict/databricks.yml withdir conflict trace musterr $CLI bundle config-remote-sync -t own-host -p myprofile +envsubst < other-workspace/databricks.yml > out && mv out other-workspace/databricks.yml +withdir other-workspace trace musterr $CLI bundle config-remote-sync -t profile-workspace -p workspace2222 withdir default-target trace musterr $CLI bundle config-remote-sync -p myprofile trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' @@ -33,11 +40,12 @@ DATABRICKS_BUNDLE_ROOT=missing trace musterr $CLI bundle config-remote-sync -p m trace print_requests.py //telemetry-ext | jq '.body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_config_remote_sync_event | {error_message, error_category}' -# Without a profile, with one that does not resolve, with one for another host than the bundle's or the target's, -# or when the bundle's own auth fails, nothing is sent. +# Without a profile, with one that does not resolve, with one for another host than the bundle's or the target's +# or for another workspace on the bundle's host, or when the bundle's own auth fails, nothing is sent. trace musterr $CLI bundle config-remote-sync -t bad trace musterr $CLI bundle config-remote-sync -t bad -p missing withdir conflict trace musterr $CLI bundle config-remote-sync -t bad -p myprofile +withdir other-workspace trace musterr $CLI bundle config-remote-sync -t bad -p workspace2222 trace musterr $CLI bundle config-remote-sync -t other -p myprofile DATABRICKS_BUNDLE_TARGET=other trace musterr $CLI bundle config-remote-sync -p myprofile trace musterr $CLI bundle config-remote-sync -t auth-error -p myprofile diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index ae2324b1200..935f5713c55 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -323,15 +323,18 @@ func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profileName, target log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s not found", profileName) return ctx } - // As in bundle auth, a profile for another host than the bundle's is rejected. + // As in bundle auth, a profile for another host than the bundle's is rejected, + // and so is one for another workspace on the same unified host. if b != nil { - host := b.Config.Workspace.Host - // The target was not merged, so its own host is not in the root config yet. - if t := b.Config.Targets[selectedTarget(ctx, b, target)]; t != nil && t.Workspace != nil && t.Workspace.Host != "" { - host = t.Workspace.Host + host, id := b.Config.Workspace.Host, b.Config.Workspace.WorkspaceID + // The target was not merged, so its own workspace is not in the root config yet. + if t := b.Config.Targets[selectedTarget(ctx, b, target)]; t != nil && t.Workspace != nil { + host, id = cmp.Or(t.Workspace.Host, host), cmp.Or(t.Workspace.WorkspaceID, id) } - if host != "" && canonicalHost(host) != canonicalHost(profiles[0].Host) { - log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s is for another host than the bundle's %s", profileName, host) + p := profiles[0] + bundleID, profileID := workspaceID(host, id), workspaceID(p.Host, p.WorkspaceID) + if host != "" && canonicalHost(host) != canonicalHost(p.Host) || bundleID != "" && profileID != "" && bundleID != profileID { + log.Debugf(ctx, "config-remote-sync telemetry skipped: profile %s is for another workspace than the bundle's %s", profileName, host) return ctx } } @@ -343,6 +346,11 @@ func WithProfileAuth(ctx context.Context, b *bundle.Bundle, profileName, target return cmdctx.SetConfigUsed(ctx, cfg) } +// workspaceID returns the explicit workspace ID, else the one in the host URL. +func workspaceID(host, id string) string { + return cmp.Or(id, auth.ExtractHostQueryParams(host).WorkspaceID) +} + func canonicalHost(host string) string { return (&sdkconfig.Config{Host: host}).CanonicalHostName() }