Skip to content

Commit f3ef15b

Browse files
authored
Log to telemetry redacted $resources references (#3567)
## Changes For every $resource.group.key.field1.field2 reference add resref_group_field1_field2 bool metric. If we encounter map key, place "mapkey" in case of actual value. If we encounter error during struct traversal, log what we can with resreferr_ prefix instead. ## Why With remote state lookups added in #3531 we use API / SDK struct schema for accessing remote fields, which is different from Terraform schema. Having telemetry allows to estimate number of customers using $resources references and estimate usage of incompatible references. ## Tests Existing tests expanded to log telemetry. New acceptance test which includes longer path. New helper in tests to log boolean fields from telemetry request. New unit tests.
1 parent 1024fbf commit f3ef15b

File tree

17 files changed

+342
-6
lines changed

17 files changed

+342
-6
lines changed

acceptance/bundle/debuglog/out.stderr.direct-exp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
10:07:59 Debug: Apply pid=12345 mutator=ConfigureWSFS
4646
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources
4747
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=ResolveVariableReferences(resources)
48+
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=LogResourceReferences
4849
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=NormalizePaths
4950
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=TranslatePathsDashboards
5051
10:07:59 Debug: Apply pid=12345 mutator=PythonMutator(load_resources)

acceptance/bundle/debuglog/out.stderr.terraform.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
10:07:59 Debug: Apply pid=12345 mutator=ConfigureWSFS
4646
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources
4747
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=ResolveVariableReferences(resources)
48+
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=LogResourceReferences
4849
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=NormalizePaths
4950
10:07:59 Debug: Apply pid=12345 mutator=ProcessStaticResources mutator=TranslatePathsDashboards
5051
10:07:59 Debug: Apply pid=12345 mutator=PythonMutator(load_resources)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
resources:
2+
jobs:
3+
test_job:
4+
name: "My Wheel Job"
5+
environments: []
6+
tags:
7+
my_own_tag_key: my_own_tag_value
8+
tasks:
9+
- task_key: TestTask
10+
python_wheel_task:
11+
package_name: "my_test_code"
12+
entry_point: "run"
13+
environment_key: test_env
14+
libraries:
15+
- whl: hello.whl
16+
foo:
17+
name: "My foo Job"
18+
environments: []
19+
tags:
20+
my_other_tag: ${resources.jobs.test_job.tags.my_own_tag_key}
21+
tasks:
22+
- task_key: TestTask
23+
python_wheel_task:
24+
package_name: "my_test_code"
25+
# for direct, the syntax follows SDK struct:
26+
#entry_point: ${resources.jobs.test_job.tasks[0].python_wheel_task.entry_point}
27+
# for terraform, the syntax follows TF model:
28+
entry_point: ${resources.jobs.test_job.task[0].python_wheel_task[0].entry_point}
29+
environment_key: test_env
30+
libraries:
31+
- whl: hello.whl
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading hello.whl...
4+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
5+
Deploying resources...
6+
Updating deployment state...
7+
Deployment complete!
8+
9+
>>> print_telemetry_bool_values
10+
experimental.use_legacy_run_as false
11+
has_classic_interactive_compute false
12+
has_classic_job_compute false
13+
has_serverless_compute true
14+
presets_name_prefix_is_set false
15+
python_wheel_wrapper_is_set false
16+
resref_jobs.tags.* true
17+
resreferr_jobs.task true
18+
run_as_set false
19+
skip_artifact_cleanup false
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
touch hello.whl
2+
trace $CLI bundle deploy
3+
trace print_telemetry_bool_values
4+
rm out.requests.txt hello.whl
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RecordRequests = true
2+
3+
# direct fails with Error: schema mismatch for ${resources.jobs.test_job.task[0].python_wheel_task[0].entry_point}: task: field "task" not found in resources.Job
4+
EnvMatrix.DATABRICKS_CLI_DEPLOYMENT = ["terraform"] # uses TF-specific syntax task[0].python_wheel_task[0]

acceptance/bundle/resource_deps/missing_map_key_tffix/output.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@
4242
}
4343
}
4444
}
45+
46+
=== Nothing is logged in telemetry because deploy has failed
47+
>>> print_telemetry_bool_values
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
trace $CLI bundle validate -o json | jq .resources
22
musterr $CLI bundle plan &> out.plan.$DATABRICKS_CLI_DEPLOYMENT.txt
33
musterr $CLI bundle deploy &> out.deploy.$DATABRICKS_CLI_DEPLOYMENT.txt
4+
5+
title "Nothing is logged in telemetry because deploy has failed"
6+
trace print_telemetry_bool_values
7+
rm out.requests.txt
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Badness = "Uploading files even though bundle is wrong; bundle validate does not detect the issue; direct fails but with wrong error message"
2-
RecordRequests = false
2+
RecordRequests = true

0 commit comments

Comments
 (0)