diff --git a/acceptance/bundle/config-remote-sync/job_fields/output.txt b/acceptance/bundle/config-remote-sync/job_fields/output.txt index b932a52aa88..f19b851fe58 100644 --- a/acceptance/bundle/config-remote-sync/job_fields/output.txt +++ b/acceptance/bundle/config-remote-sync/job_fields/output.txt @@ -110,7 +110,8 @@ Resource: resources.jobs.my_job "resource_job_ids": [ "[MY_JOB_ID]" ] - } + }, + "in_git_repo": false } >>> [CLI] bundle destroy --auto-approve diff --git a/acceptance/bundle/config-remote-sync/resolve_variables/output.txt b/acceptance/bundle/config-remote-sync/resolve_variables/output.txt index da1e166f682..842ae93983d 100644 --- a/acceptance/bundle/config-remote-sync/resolve_variables/output.txt +++ b/acceptance/bundle/config-remote-sync/resolve_variables/output.txt @@ -155,7 +155,8 @@ Resource: resources.pipelines.my_pipeline "resource_pipeline_ids": [ "[MY_PIPELINE_ID]" ] - } + }, + "in_git_repo": false } >>> [CLI] bundle destroy --auto-approve diff --git a/acceptance/bundle/config-remote-sync/variable_reference_parent/output.txt b/acceptance/bundle/config-remote-sync/variable_reference_parent/output.txt index a4eac5ef990..c12bc083cf9 100644 --- a/acceptance/bundle/config-remote-sync/variable_reference_parent/output.txt +++ b/acceptance/bundle/config-remote-sync/variable_reference_parent/output.txt @@ -56,7 +56,8 @@ Resource: resources.jobs.my_job "resource_job_ids": [ "[MY_JOB_ID]" ] - } + }, + "in_git_repo": false } >>> [CLI] bundle destroy --auto-approve diff --git a/acceptance/bundle/telemetry/config-remote-sync-git/databricks.yml b/acceptance/bundle/telemetry/config-remote-sync-git/databricks.yml new file mode 100644 index 00000000000..d29b7d3d1ff --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-git/databricks.yml @@ -0,0 +1,11 @@ +bundle: + name: config-remote-sync-git-telemetry + +resources: + jobs: + foo: + name: test job + tasks: + - task_key: main + notebook_task: + notebook_path: /Workspace/Users/tester@databricks.com/notebook diff --git a/acceptance/bundle/telemetry/config-remote-sync-git/out.test.toml b/acceptance/bundle/telemetry/config-remote-sync-git/out.test.toml new file mode 100644 index 00000000000..aadf9e4a151 --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-git/out.test.toml @@ -0,0 +1,3 @@ +Cloud = false +GOOS.windows = false +EnvMatrix.DMS = [""] diff --git a/acceptance/bundle/telemetry/config-remote-sync-git/output.txt b/acceptance/bundle/telemetry/config-remote-sync-git/output.txt new file mode 100644 index 00000000000..b9815d3bfa1 --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-git/output.txt @@ -0,0 +1,15 @@ + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/config-remote-sync-git-telemetry/default/files... +Created jobs.foo +Files: 1 uploaded, 0 deleted +Resources: 1 created, 0 changed, 0 deleted, 0 unchanged + +>>> [CLI] bundle config-remote-sync +No changes detected. + + +>>> cat [OUTPUT_DIR]/out.requests.txt +{ + "in_git_repo": true +} diff --git a/acceptance/bundle/telemetry/config-remote-sync-git/script b/acceptance/bundle/telemetry/config-remote-sync-git/script new file mode 100644 index 00000000000..2bc9fb41e28 --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-git/script @@ -0,0 +1,9 @@ +git-repo-init + +trace $CLI bundle deploy + +trace $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) | {in_git_repo}' + +rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/telemetry/config-remote-sync-git/test.toml b/acceptance/bundle/telemetry/config-remote-sync-git/test.toml new file mode 100644 index 00000000000..75c69a13716 --- /dev/null +++ b/acceptance/bundle/telemetry/config-remote-sync-git/test.toml @@ -0,0 +1,7 @@ +# config-remote-sync is not supported on Windows. +GOOS.windows = false + +# git-repo-init creates a repo in the test directory so the run has git metadata. +Ignore = [ + '.git', +] diff --git a/acceptance/bundle/telemetry/config-remote-sync-recreate/output.txt b/acceptance/bundle/telemetry/config-remote-sync-recreate/output.txt index 39e27d0f075..f296e54a6bd 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-recreate/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-recreate/output.txt @@ -35,5 +35,6 @@ Resource: resources.pipelines.foo "resource_pipeline_ids": [ "[FOO_ID]" ] - } + }, + "in_git_repo": false } diff --git a/acceptance/bundle/telemetry/config-remote-sync-save/output.txt b/acceptance/bundle/telemetry/config-remote-sync-save/output.txt index 530b2535442..2b89354ecb9 100644 --- a/acceptance/bundle/telemetry/config-remote-sync-save/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync-save/output.txt @@ -37,5 +37,6 @@ Resource: resources.jobs.foo "resource_job_ids": [ "[FOO_ID]" ] - } + }, + "in_git_repo": false } diff --git a/acceptance/bundle/telemetry/config-remote-sync/output.txt b/acceptance/bundle/telemetry/config-remote-sync/output.txt index 157b4cb6d79..689f60f465b 100644 --- a/acceptance/bundle/telemetry/config-remote-sync/output.txt +++ b/acceptance/bundle/telemetry/config-remote-sync/output.txt @@ -34,7 +34,8 @@ Resource: resources.jobs.foo "resource_job_ids": [ "[FOO_ID]" ] - } + }, + "in_git_repo": false } >>> cat [OUTPUT_DIR]/out.requests.txt diff --git a/acceptance/bundle/telemetry/deploy-git/output.txt b/acceptance/bundle/telemetry/deploy-git/output.txt index 8196d77e7b3..259b256c782 100644 --- a/acceptance/bundle/telemetry/deploy-git/output.txt +++ b/acceptance/bundle/telemetry/deploy-git/output.txt @@ -11,5 +11,6 @@ Resources: 0 created, 0 changed, 0 deleted, 0 unchanged "branch": "main", "commit": "[COMMIT_SHA]" }, - "from_workspace_folder": null + "from_workspace_folder": null, + "in_git_repo": true } diff --git a/acceptance/bundle/telemetry/deploy-git/script b/acceptance/bundle/telemetry/deploy-git/script index c3f3975c610..bbcb7701461 100644 --- a/acceptance/bundle/telemetry/deploy-git/script +++ b/acceptance/bundle/telemetry/deploy-git/script @@ -3,6 +3,6 @@ git remote add origin https://github.com/databricks/cli trace $CLI bundle deploy -trace cat "$OUT_REQUESTS" | jq 'select(has("path") and .path == "/telemetry-ext") | .body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_deploy_event | {git, from_workspace_folder}' +trace cat "$OUT_REQUESTS" | jq 'select(has("path") and .path == "/telemetry-ext") | .body.protoLogs[] | fromjson | .entry.databricks_cli_log.bundle_deploy_event | {git, from_workspace_folder, in_git_repo}' rm "$OUT_REQUESTS" diff --git a/acceptance/bundle/telemetry/deploy/out.telemetry.txt b/acceptance/bundle/telemetry/deploy/out.telemetry.txt index cb92e434e30..1945afe889c 100644 --- a/acceptance/bundle/telemetry/deploy/out.telemetry.txt +++ b/acceptance/bundle/telemetry/deploy/out.telemetry.txt @@ -35,6 +35,7 @@ "[PIPELINE_ONE_ID]", "[PIPELINE_TWO_ID]" ], + "in_git_repo": false, "experimental": { "configuration_file_count": 1, "variable_count": 0, diff --git a/bundle/bundle.go b/bundle/bundle.go index 6762b38b91e..fab13f9917d 100644 --- a/bundle/bundle.go +++ b/bundle/bundle.go @@ -143,6 +143,10 @@ type Bundle struct { // https://git-scm.com/docs/git-worktree WorktreeRoot vfs.Path + // InGitRepo reports whether the bundle root is inside a git repository. + // Nil when git detection did not run or failed. + InGitRepo *bool + // Config contains the bundle configuration. // It is loaded from the bundle configuration files and mutators may update it. Config config.Root diff --git a/bundle/config/mutator/load_git_details.go b/bundle/config/mutator/load_git_details.go index f2d3be08a1b..15c6a331a65 100644 --- a/bundle/config/mutator/load_git_details.go +++ b/bundle/config/mutator/load_git_details.go @@ -27,6 +27,11 @@ func (m *loadGitDetails) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn diags = append(diags, diag.WarningFromErr(err)...) } + // On error the repository root is unknown, not absent, so leave InGitRepo unset. + if err == nil { + b.InGitRepo = new(info.WorktreeRoot != "") + } + if info.WorktreeRoot == "" { b.WorktreeRoot = b.SyncRoot } else { diff --git a/bundle/configsync/telemetry.go b/bundle/configsync/telemetry.go index 86743a62efb..4370dded6dd 100644 --- a/bundle/configsync/telemetry.go +++ b/bundle/configsync/telemetry.go @@ -71,6 +71,8 @@ type Stats struct { StateResourceIDs *protos.BundleConfigRemoteSyncResourceIds SelectedResourceIDs *protos.BundleConfigRemoteSyncResourceIds + InGitRepo *bool + ErrorMessage string ErrorCategory protos.BundleConfigRemoteSyncErrorCategory } @@ -317,6 +319,7 @@ func (s *Stats) LogTelemetry(ctx context.Context) { StatesAvailableCount: s.StatesAvailableCount, StateResourceIDs: s.StateResourceIDs, SelectedResourceIDs: s.SelectedResourceIDs, + InGitRepo: s.InGitRepo, ErrorMessage: s.ErrorMessage, ErrorCategory: s.ErrorCategory, }, diff --git a/bundle/phases/telemetry.go b/bundle/phases/telemetry.go index 5442c5fc16a..723bcd9346f 100644 --- a/bundle/phases/telemetry.go +++ b/bundle/phases/telemetry.go @@ -474,6 +474,7 @@ func LogDeployTelemetry(ctx context.Context, b *bundle.Bundle, errMsg string) { Git: bundleGitInfo(b), FromWorkspaceFolder: fromWorkspaceFolder(ctx, b), + InGitRepo: b.InGitRepo, Experimental: &protos.BundleDeployExperimental{ BundleMode: mode, diff --git a/cmd/bundle/config_remote_sync.go b/cmd/bundle/config_remote_sync.go index 67f74e926bf..83344855e5c 100644 --- a/cmd/bundle/config_remote_sync.go +++ b/cmd/bundle/config_remote_sync.go @@ -76,7 +76,7 @@ Examples: skippedChanges []configsync.SkippedChange ) - _, _, err := utils.ProcessBundleRet(cmd, utils.ProcessOptions{ + b, _, err := utils.ProcessBundleRet(cmd, utils.ProcessOptions{ ReadState: true, Build: true, AlwaysPull: true, @@ -174,6 +174,9 @@ Examples: return nil }, }) + if b != nil { + stats.InGitRepo = b.InGitRepo + } return configsync.WriteResult(cmd.OutOrStdout(), root.OutputType(cmd) == flags.OutputJSON, &stats, files, changes, skippedChanges, err) } diff --git a/libs/telemetry/protos/bundle_config_remote_sync.go b/libs/telemetry/protos/bundle_config_remote_sync.go index 467acb09939..a62a823c64e 100644 --- a/libs/telemetry/protos/bundle_config_remote_sync.go +++ b/libs/telemetry/protos/bundle_config_remote_sync.go @@ -112,6 +112,10 @@ type BundleConfigRemoteSyncEvent struct { StateResourceIDs *BundleConfigRemoteSyncResourceIds `json:"state_resource_ids,omitempty"` SelectedResourceIDs *BundleConfigRemoteSyncResourceIds `json:"selected_resource_ids,omitempty"` + // Whether the bundle root is inside a git repository. Same semantics as + // BundleDeployEvent.InGitRepo. + InGitRepo *bool `json:"in_git_repo,omitempty"` + // Scrubbed, truncated summary of the failure when the command exits with an // error. Privileged free-text (DATA_LABEL_USER_COMMANDS_RESPONSE, LPP-5543); // stays in-region and is stripped from centralized logfood. Unset on success. diff --git a/libs/telemetry/protos/bundle_deploy.go b/libs/telemetry/protos/bundle_deploy.go index 89f966a2dcf..3200c3860c7 100644 --- a/libs/telemetry/protos/bundle_deploy.go +++ b/libs/telemetry/protos/bundle_deploy.go @@ -54,6 +54,11 @@ type BundleDeployEvent struct { // beside Git rather than inside it. FromWorkspaceFolder bool `json:"from_workspace_folder,omitempty"` + // Whether the bundle root is inside a git repository, regardless of + // `bundle.git` overrides. A pointer so that false is sent explicitly, and + // the field is omitted only when git detection did not run or failed. + InGitRepo *bool `json:"in_git_repo,omitempty"` + Experimental *BundleDeployExperimental `json:"experimental,omitempty"` }