Skip to content

Commit a35086d

Browse files
Add telemetry for bundle init (#2537)
## Changes This PR adds telemetry logging for the `databricks bundle init` command. ## Why We would like to know how often our templates are used and what revenues are associated with each of our templates. ## Tests Acceptance tests. Here are the properties that we want to ensure: 1. For Databricks templates, only enum/bool args should be captured; others should be ignored. Non-enum args are not safe for centralization. 2. For user-defined custom templates, we should not log either the template name or any of it's arguments (including boolean / enums). 3. The serialized bundle-uuid in `databricks.yml` should be the same as the one recorded in the telemetry payload. Also manually verified that the information shows up in our telemetry table.
1 parent 4b685be commit a35086d

File tree

29 files changed

+457
-14
lines changed

29 files changed

+457
-14
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
Cloud = false
2+
3+
[[Server]]
4+
Pattern = "POST /telemetry-ext"
5+
Response.Body = '''
6+
{
7+
"errors": [],
8+
"numProtoSuccess": 1
9+
}
10+
'''
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"properties": {
3+
"project_name": {
4+
"type": "string",
5+
"description": "The name of the project"
6+
},
7+
"some_enum": {
8+
"type": "string",
9+
"enum": [
10+
"v1",
11+
"v2",
12+
"v3"
13+
],
14+
"description": "An enum"
15+
}
16+
}
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"project_name": "my_custom_template",
3+
"some_enum": "v2"
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bundle:
2+
uuid: [BUNDLE-UUID]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"headers": {
3+
"User-Agent": [
4+
"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_init cmd-exec-id/[CMD-EXEC-ID] auth/pat"
5+
]
6+
},
7+
"method": "POST",
8+
"path": "/telemetry-ext",
9+
"body": {
10+
"uploadTime": "UNIX_TIME_MILLIS",
11+
"items": [],
12+
"protoLogs": [
13+
"{\"frontend_log_event_id\":\"[UUID]\",\"entry\":{\"databricks_cli_log\":{\"execution_context\":{\"cmd_exec_id\":\"[CMD-EXEC-ID]\",\"version\":\"[DEV_VERSION]\",\"command\":\"bundle_init\",\"operating_system\":\"[OS]\",\"execution_time_ms\":\"SMALL_INT\",\"exit_code\":0},\"bundle_init_event\":{\"bundle_uuid\":\"[BUNDLE-UUID]\",\"template_name\":\"custom\"}}}}"
14+
]
15+
}
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
>>> [CLI] bundle init . --config-file input.json --output-dir output
3+
✨ Successfully initialized template
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trace $CLI bundle init . --config-file input.json --output-dir output
2+
3+
# We only need to keep the output databricks.yml to assert the bundle_uuid is consistent
4+
# in both the generated YAML file and telemetry payload.
5+
mv output/my_custom_template/databricks.yml out.databricks.yml
6+
rm -r output
7+
8+
9+
cmd_exec_id=$(cat out.requests.txt | jq '.headers."User-Agent".[0]'| head -n 1 | grep -o 'cmd-exec-id/[^ ]*' | cut -d '/' -f2)
10+
bundle_uuid=$(cat out.databricks.yml | grep -o 'uuid: [^\n]*' | cut -d ' ' -f2)
11+
12+
update_file.py out.requests.txt $cmd_exec_id '[CMD-EXEC-ID]'
13+
update_file.py out.requests.txt $bundle_uuid '[BUNDLE-UUID]'
14+
update_file.py out.databricks.yml $bundle_uuid '[BUNDLE-UUID]'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bundle:
2+
uuid: {{bundle_uuid}}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"project_name": "my_dbt_sql",
3+
"http_path": "/sql/2.0/warehouses/f00dcafe",
4+
"default_catalog": "main",
5+
"personal_schemas": "yes, use a schema based on the current user name during development"
6+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This file defines the structure of this project and how it is deployed
2+
# to production using Databricks Asset Bundles.
3+
# See https://docs.databricks.com/dev-tools/bundles/index.html for documentation.
4+
bundle:
5+
name: my_dbt_sql
6+
uuid: [BUNDLE-UUID]
7+
8+
include:
9+
- resources/*.yml
10+
11+
# Deployment targets.
12+
# The default schema, catalog, etc. for dbt are defined in dbt_profiles/profiles.yml
13+
targets:
14+
dev:
15+
# The default target uses 'mode: development' to create a development copy.
16+
# - Deployed resources get prefixed with '[dev my_user_name]'
17+
# - Any job schedules and triggers are paused by default.
18+
# See also https://docs.databricks.com/dev-tools/bundles/deployment-modes.html.
19+
mode: development
20+
default: true
21+
workspace:
22+
host: [DATABRICKS_URL]
23+
24+
prod:
25+
mode: production
26+
workspace:
27+
host: [DATABRICKS_URL]
28+
# We explicitly deploy to /Workspace/Users/[USERNAME] to make sure we only have a single copy.
29+
root_path: /Workspace/Users/[USERNAME]/.bundle/${bundle.name}/${bundle.target}
30+
permissions:
31+
- user_name: [USERNAME]
32+
level: CAN_MANAGE

0 commit comments

Comments
 (0)