Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
75a0eab
intercept auth header in the PopulateCurrentUser mutator
anton-107 Jul 24, 2025
e5c1b46
cache the auth header in local dir
anton-107 Jul 28, 2025
09d972a
store and read current user info from local cache
anton-107 Jul 28, 2025
71de033
remove unnecessary check
anton-107 Jul 28, 2025
c982a6e
remove ensureCacheDir method
anton-107 Jul 28, 2025
ad7f41d
use bearer token for fingerprint
anton-107 Sep 8, 2025
6565558
fix the fingerprint when using the
anton-107 Sep 8, 2025
489cb3e
refactor: extract caching logic from Apply
anton-107 Sep 8, 2025
ea54f71
cleanup: remove poc code
anton-107 Sep 8, 2025
bdae5a5
fix lint
anton-107 Sep 8, 2025
dd6943d
add an exploratory test for quicker debugging of cache
anton-107 Sep 16, 2025
6acaa44
cleanup: send debugging statements to a separate log
anton-107 Sep 16, 2025
de89c9b
make lint
anton-107 Sep 16, 2025
e3a0239
revert populate_current_user.go
anton-107 Sep 16, 2025
6efc941
new Cache interface with a single GetOrCompute method
anton-107 Sep 18, 2025
9db3ee5
unit tests are passing
anton-107 Sep 18, 2025
0e47cf1
randomize temp path before writing cache to disk
anton-107 Sep 18, 2025
e48ca3d
use arbitrary structs as cache fingerprint
anton-107 Sep 18, 2025
a338c05
make fingerprintToString private
anton-107 Sep 18, 2025
a37f176
make Cache interface generic
anton-107 Sep 22, 2025
e5669aa
temporarily use `DATABRICKS_EXPERIMENTAL_CACHE_ENABLED` env var to en…
anton-107 Sep 22, 2025
e097a73
remove bundle/cache.go
anton-107 Sep 22, 2025
75d51be
use struct as a fingerprint
anton-107 Sep 22, 2025
8309318
use os.UserCacheDir as the root dir for cache files
anton-107 Sep 22, 2025
f0849fd
remove BundleLevelCacheDir
anton-107 Sep 22, 2025
06e9d56
fix unit test on windows
anton-107 Sep 22, 2025
ebefd43
remove unused variable
anton-107 Sep 22, 2025
c60339b
do not use cache if bearer token is empty
anton-107 Sep 23, 2025
7dcca0f
use auth header as a cache fingerprint
anton-107 Sep 23, 2025
4b3a48b
fix trailing whitespaces in debug messages
anton-107 Sep 23, 2025
aea6b1f
replace populate_current_user.go with the implementation that has a c…
anton-107 Sep 23, 2025
1267194
restore DomainFriendlyName
anton-107 Sep 23, 2025
45c8234
basic cache cleanup in background
anton-107 Sep 23, 2025
d8aab3b
remove the ScanInterval setting
anton-107 Sep 23, 2025
7519530
store expiration time instead of timestamp in a cache entry
anton-107 Sep 23, 2025
11e8702
rename file_cache_expiry_test.go; change the assertion
anton-107 Sep 24, 2025
c6a1da7
add telemetry on caching events
anton-107 Sep 24, 2025
4bbc589
add new `cache clear` command
anton-107 Sep 24, 2025
bcc8dc9
fix tests
anton-107 Sep 24, 2025
d35727a
silence the first cache clear command in an acceptance test
anton-107 Sep 25, 2025
5e8fcb0
env variable DATABRICKS_CACHE_FOLDER allows to set up location for ca…
anton-107 Sep 25, 2025
44fc845
check the cache entry expiration before returning
anton-107 Sep 25, 2025
8c0afb8
turn the cache to be always on; DATABRICKS_CACHE_DISABLED env variabl…
anton-107 Sep 25, 2025
a374a46
make cache hits no-op
anton-107 Sep 26, 2025
f6d1807
make test-update
anton-107 Sep 26, 2025
e31f7fd
fix mutex unlocking
anton-107 Sep 26, 2025
f8287ad
update unit tests for no-op caching layer
anton-107 Sep 26, 2025
5f1b865
use unique cache folder in each acceptance test
anton-107 Sep 26, 2025
ef495c3
disable caching for telemetry acc tests
anton-107 Sep 26, 2025
782c5b1
fix sync code
andrewnester Nov 4, 2025
e4f03c2
simplify
andrewnester Nov 4, 2025
ac8c361
Merge branch 'main' into anton-107/cache-control-flow
andrewnester Nov 4, 2025
5d78056
fixes
andrewnester Nov 4, 2025
127853f
updated output
andrewnester Nov 7, 2025
37bce6e
Merge branch 'main' into anton-107/cache-control-flow
andrewnester Nov 13, 2025
cf15cd0
fixed output
andrewnester Nov 13, 2025
f4af271
disable cache for a couple of tests
andrewnester Nov 13, 2025
6aab004
fix output
andrewnester Nov 13, 2025
0063164
fix output
andrewnester Nov 13, 2025
4a1392b
write cache synchornously
andrewnester Nov 13, 2025
48fd2d1
fix output
andrewnester Nov 13, 2025
eddf974
fix cache test
andrewnester Nov 13, 2025
ef26518
removed async logic + addressed feedback
andrewnester Nov 17, 2025
367a6bf
sanitise version
andrewnester Nov 17, 2025
010b55e
Merge branch 'main' into anton-107/cache-control-flow
andrewnester Nov 17, 2025
ae89682
use DATABRICKS_CACHE_DIR in tests
andrewnester Nov 17, 2025
314852e
address comments
andrewnester Nov 25, 2025
5c2b570
fix tests
andrewnester Nov 25, 2025
59b2d2a
repl
andrewnester Nov 25, 2025
828e416
ctx
andrewnester Nov 25, 2025
60770f1
fix test for windows
andrewnester Nov 25, 2025
bcaf666
only measure dont cache
andrewnester Nov 27, 2025
49da1e0
Merge branch 'main' into anton-107/cache-control-flow
andrewnester Nov 27, 2025
4cd6fd1
fix tests
andrewnester Nov 27, 2025
93d01a9
fix tests
andrewnester Nov 27, 2025
be0374c
fix test
andrewnester Nov 27, 2025
88cd440
repls
andrewnester Nov 27, 2025
ecc4e9c
simplify
andrewnester Nov 27, 2025
4fad903
addressed feedback + refactor
andrewnester Dec 1, 2025
1c7a2da
use separate cache test dir
andrewnester Dec 1, 2025
3e37776
fixes for windows
andrewnester Dec 1, 2025
72d43b4
skip on windows
andrewnester Dec 1, 2025
55f5438
fixes
andrewnester Dec 5, 2025
8239199
avoid double computations
andrewnester Dec 5, 2025
ae498cf
remove repls
andrewnester Dec 8, 2025
6ec5219
hardcode hash and refactor
andrewnester Dec 9, 2025
1624419
fix lint
andrewnester Dec 9, 2025
512433c
refactor to use generic function
andrewnester Dec 10, 2025
86dfd04
simplified
andrewnester Dec 10, 2025
cfdcd5d
addressed feedback
andrewnester Dec 10, 2025
07c05b6
addressed comments
andrewnester Dec 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,11 @@ func runTest(t *testing.T,
cmd.Env = append(cmd.Env, "GOCOVERDIR="+coverDir)
}

// Set unique cache folder for this test to avoid race conditions between parallel tests
// Use test temp directory to avoid polluting user's cache
uniqueCacheDir := filepath.Join(t.TempDir(), ".cache")
cmd.Env = append(cmd.Env, "DATABRICKS_CACHE_DIR="+uniqueCacheDir)

for _, key := range utils.SortedKeys(config.Env) {
if hasKey(customEnv, key) {
// We want EnvMatrix to take precedence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ experimental.use_legacy_run_as false
has_classic_interactive_compute false
has_classic_job_compute false
has_serverless_compute true
local.cache.attempt true
local.cache.miss true
presets_name_prefix_is_set false
python_wheel_wrapper_is_set false
resref_jobs.tags.* true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ experimental.use_legacy_run_as false
has_classic_interactive_compute false
has_classic_job_compute false
has_serverless_compute true
local.cache.attempt true
local.cache.miss true
presets_name_prefix_is_set false
python_wheel_wrapper_is_set false
resref_jobs.tags.* true
Expand Down
2 changes: 2 additions & 0 deletions acceptance/bundle/resource_deps/resources_var/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ experimental.use_legacy_run_as false
has_classic_interactive_compute false
has_classic_job_compute false
has_serverless_compute false
local.cache.attempt true
local.cache.hit true
presets_name_prefix_is_set true
python_wheel_wrapper_is_set false
resref_volumes.catalog_name true
Expand Down
3 changes: 3 additions & 0 deletions acceptance/bundle/run/scripts/databricks-cli/test.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
RecordRequests = true
IncludeRequestHeaders = ["Authorization"]

[Env]
DATABRICKS_CACHE_ENABLED = 'false'

# "client_id:client_secret" in base64 is Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=, expect to
# see this in Authorization header
[[Repls]]
Expand Down
16 changes: 16 additions & 0 deletions acceptance/bundle/telemetry/deploy-compute-type/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ Deployment complete!

>>> cat out.requests.txt
[
{
"key": "local.cache.attempt",
"value": true
},
{
"key": "local.cache.miss",
"value": true
},
{
"key": "experimental.use_legacy_run_as",
"value": false
Expand Down Expand Up @@ -47,6 +55,14 @@ Deployment complete!
}
]
[
{
"key": "local.cache.attempt",
"value": true
},
{
"key": "local.cache.hit",
"value": true
},
{
"key": "experimental.use_legacy_run_as",
"value": false
Expand Down
8 changes: 8 additions & 0 deletions acceptance/bundle/telemetry/deploy-experimental/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ Deployment complete!
>>> cat out.requests.txt
{
"bool_values": [
{
"key": "local.cache.attempt",
"value": true
},
{
"key": "local.cache.miss",
"value": true
},
{
"key": "experimental.use_legacy_run_as",
"value": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Deployment complete!
>>> cat out.requests.txt
{
"bool_values": [
{
"key": "local.cache.attempt",
"value": true
},
{
"key": "local.cache.miss",
"value": true
},
{
"key": "experimental.use_legacy_run_as",
"value": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Deployment complete!
>>> cat out.requests.txt
{
"bool_values": [
{
"key": "local.cache.attempt",
"value": true
},
{
"key": "local.cache.miss",
"value": true
},
{
"key": "experimental.use_legacy_run_as",
"value": false
Expand Down
16 changes: 16 additions & 0 deletions acceptance/bundle/telemetry/deploy-whl-artifacts/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Deployment complete!
>>> cat out.requests.txt
{
"bool_values": [
{
"key": "local.cache.attempt",
"value": true
},
{
"key": "local.cache.miss",
"value": true
},
{
"key": "artifact_build_command_is_set",
"value": false
Expand Down Expand Up @@ -48,6 +56,14 @@ Deployment complete!
}
{
"bool_values": [
{
"key": "local.cache.attempt",
"value": true
},
{
"key": "local.cache.hit",
"value": true
},
{
"key": "artifact_build_command_is_set",
"value": true
Expand Down
11 changes: 10 additions & 1 deletion acceptance/bundle/telemetry/deploy/out.telemetry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
"lookup_variable_count": 0,
"target_count": 1,
"bool_values": [
{
"key": "local.cache.attempt",
"value": true
},
{
"key": "local.cache.miss",
"value": true
},
{
"key": "experimental.use_legacy_run_as",
"value": false
Expand Down Expand Up @@ -76,7 +84,8 @@
}
],
"bundle_mode": "TYPE_UNSPECIFIED",
"workspace_artifact_path_type": "WORKSPACE_FILE_SYSTEM"
"workspace_artifact_path_type": "WORKSPACE_FILE_SYSTEM",
"local_cache_measurements_ms": [...redacted...]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional) maybe worth recording the keys for the int map.

}
}
}
Expand Down
7 changes: 7 additions & 0 deletions acceptance/bundle/telemetry/test.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
RecordRequests = true
IncludeRequestHeaders = ["User-Agent"]

[Env]
DATABRICKS_CACHE_ENABLED = 'false'

[[Repls]]
Old = '"execution_time_ms": \d{1,5},'
New = '"execution_time_ms": SMALL_INT,'

[[Repls]]
Old = '(linux|darwin|windows)'
New = '[OS]'

[[Repls]]
Old = '"local_cache_measurements_ms": \[[^\]]*\]'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if cache is disabled, should this be non-empty?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always measure if the cahce is disabled, with disabled cache we always compute values though anyway

New = '"local_cache_measurements_ms": [...redacted...]'
3 changes: 3 additions & 0 deletions acceptance/bundle/user_agent/test.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
RecordRequests = true
Local = true
IncludeRequestHeaders = ["User-Agent"]

[Env]
DATABRICKS_CACHE_ENABLED = 'false'
2 changes: 2 additions & 0 deletions acceptance/cache/clear/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bundle:
name: cache-clear-test
5 changes: 5 additions & 0 deletions acceptance/cache/clear/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions acceptance/cache/clear/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

=== First call in a session is expected to be a cache miss:
[DEBUG_TIMESTAMP] Debug: [Local Cache] using cache key: [SHA256_HASH]
[DEBUG_TIMESTAMP] Debug: [Local Cache] failed to stat cache file: (redacted)
[DEBUG_TIMESTAMP] Debug: [Local Cache] cache miss, computing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should include function name that is being computed? This maybe more relevant in the future where is more than one function.

[DEBUG_TIMESTAMP] Debug: [Local Cache] computed and stored result

=== Second call in a session is expected to be a cache hit
[DEBUG_TIMESTAMP] Debug: [Local Cache] using cache key: [SHA256_HASH]
[DEBUG_TIMESTAMP] Debug: [Local Cache] cache hit

>>> [CLI] cache clear
Cache cleared successfully from [TEST_TMP_DIR]/.cache

=== First call after a clear is expected to be a cache miss:
[DEBUG_TIMESTAMP] Debug: [Local Cache] using cache key: [SHA256_HASH]
[DEBUG_TIMESTAMP] Debug: [Local Cache] failed to stat cache file: (redacted)
[DEBUG_TIMESTAMP] Debug: [Local Cache] cache miss, computing
[DEBUG_TIMESTAMP] Debug: [Local Cache] computed and stored result
16 changes: 16 additions & 0 deletions acceptance/cache/clear/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export DATABRICKS_CACHE_DIR=$(pwd)/.cache

$CLI cache clear &> /dev/null

title "First call in a session is expected to be a cache miss:\n"
trace $CLI bundle validate --debug 2>&1 | grep "Local Cache" | grep -v "cache path"

title "Second call in a session is expected to be a cache hit\n"
trace $CLI bundle validate --debug 2>&1 | grep "Local Cache" | grep -v "cache path"

trace $CLI cache clear

title "First call after a clear is expected to be a cache miss:\n"
trace $CLI bundle validate --debug 2>&1 | grep "Local Cache" | grep -v "cache path"

rm -rf "${DATABRICKS_CACHE_DIR}"
14 changes: 14 additions & 0 deletions acceptance/cache/clear/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Cloud = false
Local = true

[Env]
DATABRICKS_CACHE_ENABLED = 'true'

# Redact structured logging fields from debug output
[[Repls]]
Old = ' pid=[0-9]+'
New = ''

[[Repls]]
Old = ' mutator=[A-Za-z]+'
New = ''
2 changes: 2 additions & 0 deletions acceptance/cache/simple/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bundle:
name: exploratory-cache-test
5 changes: 5 additions & 0 deletions acceptance/cache/simple/out.test.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions acceptance/cache/simple/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

=== First call in a session is expected to be a cache miss:
[DEBUG_TIMESTAMP] Debug: [Local Cache] using cache key: [SHA256_HASH]
[DEBUG_TIMESTAMP] Debug: [Local Cache] failed to stat cache file: (redacted)
[DEBUG_TIMESTAMP] Debug: [Local Cache] cache miss, computing
[DEBUG_TIMESTAMP] Debug: [Local Cache] computed and stored result

=== Second call in a session is expected to be a cache hit
[DEBUG_TIMESTAMP] Debug: [Local Cache] using cache key: [SHA256_HASH]
[DEBUG_TIMESTAMP] Debug: [Local Cache] cache hit

=== Bundle deploy should send telemetry values

>>> [CLI] bundle deploy -p dogfood
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/exploratory-cache-test/default/files...
Deploying resources...
Deployment complete!

>>> print_telemetry_bool_values
local.cache.attempt true
local.cache.hit true
16 changes: 16 additions & 0 deletions acceptance/cache/simple/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export DATABRICKS_CACHE_DIR=$(pwd)/.cache

$CLI cache clear &> /dev/null

title "First call in a session is expected to be a cache miss:\n"
trace $CLI bundle validate -p dogfood --debug 2>&1 | grep "Local Cache" | grep -v "cache path"

title "Second call in a session is expected to be a cache hit\n"
trace $CLI bundle validate -p dogfood --debug 2>&1 | grep "Local Cache" | grep -v "cache path"

title "Bundle deploy should send telemetry values\n"
trace $CLI bundle deploy -p dogfood

trace print_telemetry_bool_values | grep "local.cache"
rm out.requests.txt
rm -rf "${DATABRICKS_CACHE_DIR}"
16 changes: 16 additions & 0 deletions acceptance/cache/simple/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Cloud = false
Local = true

RecordRequests = true

[Env]
DATABRICKS_CACHE_ENABLED = 'true'

# Redact structured logging fields from debug output
[[Repls]]
Old = ' pid=[0-9]+'
New = ''

[[Repls]]
Old = ' mutator=[A-Za-z]+'
New = ''
15 changes: 15 additions & 0 deletions acceptance/cache/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[Repls]]
Old = '\d\d:\d\d:\d\d'
New = "[DEBUG_TIMESTAMP]"

[[Repls]]
Old = '[a-f0-9]{64}'
New = "[SHA256_HASH]"

[[Repls]]
Old = '[a-f0-9]{12}'
New = "[CACHE_KEY]"

[[Repls]]
Old = 'failed to stat cache file: .*'
New = "failed to stat cache file: (redacted)"
1 change: 1 addition & 0 deletions acceptance/help/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Additional Commands:
account Databricks Account Commands
api Perform Databricks API call
auth Authentication related commands
cache Local cache related commands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the description it's not obvious that is user-level cache (and not whatever we have in .databricks). Perhaps make it explicit "user-level cache"? cc @juliacrawf-db

completion Generate the autocompletion script for the specified shell
configure Configure authentication
help Help about any command
Expand Down
2 changes: 2 additions & 0 deletions acceptance/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ func LoadConfig(t *testing.T, dir string) (TestConfig, string) {
}
}

// Always ignore .cache directory (used by local cache)
result.Ignore = append(result.Ignore, ".cache")
result.CompiledIgnoreObject = ignore.CompileIgnoreLines(result.Ignore...)

return result, strings.Join(configs, ", ")
Expand Down
Loading