Skip to content

Commit cf4dc1a

Browse files
atreyadbrxIsaac
andcommitted
Add git provenance to bundle deploy telemetry
Populate the new git and from_workspace_folder fields on BundleDeployEvent from b.Config.Bundle.Git and the deploy environment, so a deploy's origin, branch and commit are captured in telemetry. Requires the matching universe proto change to the frontend log. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
1 parent a392d3e commit cf4dc1a

7 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bundle:
2+
name: test-bundle

‎acceptance/bundle/telemetry/deploy-git/out.test.toml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
4+
Files: 3 uploaded, 0 deleted
5+
Resources: 0 created, 0 changed, 0 deleted, 0 unchanged
6+
7+
>>> cat [OUTPUT_DIR]/out.requests.txt
8+
{
9+
"git": {
10+
"origin_url": "https://github.com/databricks/cli",
11+
"branch": "main",
12+
"commit": "[COMMIT_SHA]"
13+
},
14+
"from_workspace_folder": null
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
git-repo-init
2+
git remote add origin https://github.com/databricks/cli
3+
4+
trace $CLI bundle deploy
5+
6+
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}'
7+
8+
rm "$OUT_REQUESTS"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# git-repo-init creates a repo in the test directory so the deploy has git metadata.
2+
Ignore = [
3+
'.git',
4+
]
5+
6+
# The commit is different on every run.
7+
[[Repls]]
8+
Old = '\b[0-9a-f]{40}\b'
9+
New = '[COMMIT_SHA]'

‎bundle/phases/telemetry.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/databricks/cli/bundle/config/resources"
1515
"github.com/databricks/cli/bundle/libraries"
1616
"github.com/databricks/cli/bundle/metrics"
17+
"github.com/databricks/cli/libs/dbr"
1718
"github.com/databricks/cli/libs/dyn"
1819
"github.com/databricks/cli/libs/log"
1920
"github.com/databricks/cli/libs/telemetry"
@@ -195,6 +196,29 @@ func aiRuntimeTaskMetrics(jobs map[string]*resources.Job) (present, scheduled, m
195196
return present, scheduled, multitask
196197
}
197198

199+
// bundleGitInfo builds the git metadata for the deploy event, or nil when the
200+
// bundle root is not inside a git repository. OriginURL already has credentials
201+
// stripped by the load_git_details mutator.
202+
func bundleGitInfo(b *bundle.Bundle) *protos.BundleGitInfo {
203+
git := b.Config.Bundle.Git
204+
if git.Branch == "" && git.Commit == "" && git.OriginURL == "" {
205+
return nil
206+
}
207+
return &protos.BundleGitInfo{
208+
OriginURL: git.OriginURL,
209+
Branch: git.Branch,
210+
Commit: git.Commit,
211+
}
212+
}
213+
214+
// fromWorkspaceFolder reports whether the bundle was deployed from a workspace
215+
// folder: the CLI running on a Databricks cluster with the bundle source under
216+
// /Workspace/, as opposed to a local checkout. Same signal as the source-linked
217+
// deployment preset uses to detect a Databricks workspace.
218+
func fromWorkspaceFolder(ctx context.Context, b *bundle.Bundle) bool {
219+
return dbr.RunsOnRuntime(ctx) && strings.HasPrefix(b.SyncRootPath, "/Workspace/")
220+
}
221+
198222
// LogDeployTelemetry logs a telemetry event for a bundle deploy command.
199223
func LogDeployTelemetry(ctx context.Context, b *bundle.Bundle, errMsg string) {
200224
errMsg = telemetry.ScrubErrorMessage(errMsg)
@@ -386,6 +410,9 @@ func LogDeployTelemetry(ctx context.Context, b *bundle.Bundle, errMsg string) {
386410

387411
ResourcesMetadata: collectResourcesMetadata(ctx, b),
388412

413+
Git: bundleGitInfo(b),
414+
FromWorkspaceFolder: fromWorkspaceFolder(ctx, b),
415+
389416
Experimental: &protos.BundleDeployExperimental{
390417
BundleMode: mode,
391418
ConfigurationFileCount: b.Metrics.ConfigurationFileCount,

‎libs/telemetry/protos/bundle_deploy.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,34 @@ type BundleDeployEvent struct {
3838
// Per-resource-type metadata (counts and state-size statistics).
3939
ResourcesMetadata *BundleResourcesMetadata `json:"resources_metadata,omitempty"`
4040

41+
// Git metadata of the source the bundle was deployed from. Nil when the
42+
// bundle root is not inside a git repository.
43+
Git *BundleGitInfo `json:"git,omitempty"`
44+
45+
// True when the bundle was deployed from a workspace folder: the CLI ran on a
46+
// Databricks cluster with the bundle source under /Workspace/, rather than
47+
// from a local checkout. A deployment attribute, not git metadata, so it sits
48+
// beside Git rather than inside it.
49+
FromWorkspaceFolder bool `json:"from_workspace_folder,omitempty"`
50+
4151
Experimental *BundleDeployExperimental `json:"experimental,omitempty"`
4252
}
4353

54+
// BundleGitInfo mirrors the universe proto. Git provenance the CLI resolves during
55+
// deploy: from `.git` locally, or from the workspace API when deploying from a
56+
// Databricks Git folder. Values set under `bundle.git` in the configuration take
57+
// precedence. Mirrors the git_info sent to the Deployment Metadata Service.
58+
type BundleGitInfo struct {
59+
// URL of the "origin" remote, with any userinfo (credentials) stripped.
60+
OriginURL string `json:"origin_url,omitempty"`
61+
62+
// Branch deployed from.
63+
Branch string `json:"branch,omitempty"`
64+
65+
// Full SHA of the HEAD commit deployed.
66+
Commit string `json:"commit,omitempty"`
67+
}
68+
4469
// These metrics are experimental and are often added in an adhoc manner. There
4570
// are no guarantees for these metrics and they maybe removed in the future without
4671
// any notice.

0 commit comments

Comments
 (0)