Skip to content

Commit 100a4a6

Browse files
Initial implementation of the local cache layer (#3678)
## Changes This PR introduces a local file-based cache layer for the Databricks CLI to improve performance of repeated operations. New libs/cache package: - Standalone generic function GetOrCompute[T any](ctx, cache, fingerprint, compute) that works with any type - File-based cache implementation (fileCache) storing JSON-encoded data - SHA256-based fingerprinting for cache keys from any struct - Automatic cleanup of expired cache files on initialization - Fail-open behavior: cache errors never block operations, just trigger recomputation - Cache isolation by CLI version: ~/.cache/databricks/<version>/<component>/ Cache Modes: - Measurement mode (default): Cache disabled, but still measures potential savings via telemetry - Enabled mode: Set DATABRICKS_CACHE_ENABLED=true to actually use cached values New CLI command: - databricks cache clear - Removes all cached files across all CLI versions Bundle Integration: - New InitializeCache() mutator to set up cache in bundle initialization phase - PopulateCurrentUser now uses cache for CurrentUser.Me() API call ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> This is the first attempt to speed up subsequent `databricks bundle` commands that a bundle developer runs while developing a bundle ## Tests <!-- How have you tested the changes? --> - changed existing acceptance tests to use a dedicated cache folder - added new acceptance test for overall caching functionality and telemetry - added new acceptance test for clearing the cache - added unit tests for `libs/cache` <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. --> --------- Co-authored-by: Andrew Nester <[email protected]> Co-authored-by: Andrew Nester <[email protected]>
1 parent d280f14 commit 100a4a6

File tree

47 files changed

+1595
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1595
-4
lines changed

acceptance/acceptance_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,11 @@ func runTest(t *testing.T,
628628
cmd.Env = append(cmd.Env, "GOCOVERDIR="+coverDir)
629629
}
630630

631+
// Set unique cache folder for this test to avoid race conditions between parallel tests
632+
// Use test temp directory to avoid polluting user's cache
633+
uniqueCacheDir := filepath.Join(t.TempDir(), ".cache")
634+
cmd.Env = append(cmd.Env, "DATABRICKS_CACHE_DIR="+uniqueCacheDir)
635+
631636
for _, key := range utils.SortedKeys(config.Env) {
632637
if hasKey(customEnv, key) {
633638
// We want EnvMatrix to take precedence.

acceptance/bundle/resource_deps/job_tasks/out.telemetry.direct.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ experimental.use_legacy_run_as false
22
has_classic_interactive_compute false
33
has_classic_job_compute false
44
has_serverless_compute true
5+
local.cache.attempt true
6+
local.cache.miss true
57
presets_name_prefix_is_set false
68
python_wheel_wrapper_is_set false
79
resref_jobs.tags.* true

acceptance/bundle/resource_deps/job_tasks/out.telemetry.terraform.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ experimental.use_legacy_run_as false
22
has_classic_interactive_compute false
33
has_classic_job_compute false
44
has_serverless_compute true
5+
local.cache.attempt true
6+
local.cache.miss true
57
presets_name_prefix_is_set false
68
python_wheel_wrapper_is_set false
79
resref_jobs.tags.* true

acceptance/bundle/resource_deps/resources_var/output.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ experimental.use_legacy_run_as false
4040
has_classic_interactive_compute false
4141
has_classic_job_compute false
4242
has_serverless_compute false
43+
local.cache.attempt true
44+
local.cache.hit true
4345
presets_name_prefix_is_set true
4446
python_wheel_wrapper_is_set false
4547
resref_volumes.catalog_name true

acceptance/bundle/run/scripts/databricks-cli/test.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
RecordRequests = true
22
IncludeRequestHeaders = ["Authorization"]
33

4+
[Env]
5+
DATABRICKS_CACHE_ENABLED = 'false'
6+
47
# "client_id:client_secret" in base64 is Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=, expect to
58
# see this in Authorization header
69
[[Repls]]

acceptance/bundle/telemetry/deploy-compute-type/output.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ Deployment complete!
1313

1414
>>> cat out.requests.txt
1515
[
16+
{
17+
"key": "local.cache.attempt",
18+
"value": true
19+
},
20+
{
21+
"key": "local.cache.miss",
22+
"value": true
23+
},
1624
{
1725
"key": "experimental.use_legacy_run_as",
1826
"value": false
@@ -47,6 +55,14 @@ Deployment complete!
4755
}
4856
]
4957
[
58+
{
59+
"key": "local.cache.attempt",
60+
"value": true
61+
},
62+
{
63+
"key": "local.cache.hit",
64+
"value": true
65+
},
5066
{
5167
"key": "experimental.use_legacy_run_as",
5268
"value": false

acceptance/bundle/telemetry/deploy-experimental/output.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ Deployment complete!
1212
>>> cat out.requests.txt
1313
{
1414
"bool_values": [
15+
{
16+
"key": "local.cache.attempt",
17+
"value": true
18+
},
19+
{
20+
"key": "local.cache.miss",
21+
"value": true
22+
},
1523
{
1624
"key": "experimental.use_legacy_run_as",
1725
"value": true

acceptance/bundle/telemetry/deploy-name-prefix/custom/output.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Deployment complete!
88
>>> cat out.requests.txt
99
{
1010
"bool_values": [
11+
{
12+
"key": "local.cache.attempt",
13+
"value": true
14+
},
15+
{
16+
"key": "local.cache.miss",
17+
"value": true
18+
},
1119
{
1220
"key": "experimental.use_legacy_run_as",
1321
"value": false

acceptance/bundle/telemetry/deploy-name-prefix/mode-development/output.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Deployment complete!
88
>>> cat out.requests.txt
99
{
1010
"bool_values": [
11+
{
12+
"key": "local.cache.attempt",
13+
"value": true
14+
},
15+
{
16+
"key": "local.cache.miss",
17+
"value": true
18+
},
1119
{
1220
"key": "experimental.use_legacy_run_as",
1321
"value": false

acceptance/bundle/telemetry/deploy-whl-artifacts/output.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ Deployment complete!
1616
>>> cat out.requests.txt
1717
{
1818
"bool_values": [
19+
{
20+
"key": "local.cache.attempt",
21+
"value": true
22+
},
23+
{
24+
"key": "local.cache.miss",
25+
"value": true
26+
},
1927
{
2028
"key": "artifact_build_command_is_set",
2129
"value": false
@@ -48,6 +56,14 @@ Deployment complete!
4856
}
4957
{
5058
"bool_values": [
59+
{
60+
"key": "local.cache.attempt",
61+
"value": true
62+
},
63+
{
64+
"key": "local.cache.hit",
65+
"value": true
66+
},
5167
{
5268
"key": "artifact_build_command_is_set",
5369
"value": true

0 commit comments

Comments
 (0)