diff --git a/acceptance/bundle/migrate/auto/plan-failure/output.txt b/acceptance/bundle/migrate/auto/plan-failure/output.txt index ea36c06bc7c..3b0e0de7d3f 100644 --- a/acceptance/bundle/migrate/auto/plan-failure/output.txt +++ b/acceptance/bundle/migrate/auto/plan-failure/output.txt @@ -20,6 +20,11 @@ The Terraform deployment engine was removed in Databricks CLI v1.20.0. Auto-migr >>> print_migration_telemetry direct_migrate_plan_error true +>>> print_engines +2 engine/direct GET /api/2.0/workspace/export +1 engine/direct GET /api/2.2/jobs/get +1 engine/direct POST /telemetry-ext + === Local state was NOT rewritten (still terraform) >>> find.py \.databricks/.*(\.tfstate|resources.*\.json|\.wal) diff --git a/acceptance/bundle/migrate/auto/plan-failure/script b/acceptance/bundle/migrate/auto/plan-failure/script index 0f56cae649c..9df767912a2 100644 --- a/acceptance/bundle/migrate/auto/plan-failure/script +++ b/acceptance/bundle/migrate/auto/plan-failure/script @@ -15,7 +15,11 @@ title "Inject GET failure so the migration plan check fails: migration hard-erro fault.py "GET /api/2.2/jobs/get*" 403 0 1 trace DATABRICKS_BUNDLE_ENGINE=direct musterr $CLI bundle deploy trace print_migration_telemetry -rm -f "$OUT_REQUESTS" +# A failed migration is fatal, so the deploy could only have run on the direct engine: every +# request it made, including those before the failure and the telemetry upload, is tagged +# engine/direct. An untagged request would show up as MISSING. print_engines also clears +# the recorded requests for the next step. +trace print_engines title "Local state was NOT rewritten (still terraform)" trace find.py '\.databricks/.*(\.tfstate|resources.*\.json|\.wal)' diff --git a/acceptance/bundle/migrate/auto/run-no-commit/output.txt b/acceptance/bundle/migrate/auto/run-no-commit/output.txt index 067d03c70fd..298b3dc25bb 100644 --- a/acceptance/bundle/migrate/auto/run-no-commit/output.txt +++ b/acceptance/bundle/migrate/auto/run-no-commit/output.txt @@ -40,7 +40,7 @@ Run URL: [DATABRICKS_URL]/jobs/[TEST_JOB_ID]/runs/[RUN_ID]?o=[WORKSPACE_ID] { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none lineage/AlC62qhncMO engine/direct auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none engine/direct lineage/AlC62qhncMO auth/pat" ] }, "method": "POST", diff --git a/acceptance/bundle/migrate/user-agent/engine-pinned/output.txt b/acceptance/bundle/migrate/user-agent/engine-pinned/output.txt index 1a6a4db4b1c..0083d7b5684 100644 --- a/acceptance/bundle/migrate/user-agent/engine-pinned/output.txt +++ b/acceptance/bundle/migrate/user-agent/engine-pinned/output.txt @@ -12,7 +12,7 @@ Unset the DATABRICKS_BUNDLE_ENGINE environment variable (or set it to "direct") See https://docs.databricks.com/dev-tools/bundles/direct for details >>> print_engines -1 MISSING POST /telemetry-ext +1 engine/direct POST /telemetry-ext === deploy with bundle.engine: terraform @@ -25,7 +25,7 @@ See https://docs.databricks.com/dev-tools/bundles/direct for details >>> print_engines -1 MISSING POST /telemetry-ext +1 engine/direct POST /telemetry-ext === summary with bundle.engine: terraform @@ -39,5 +39,5 @@ See https://docs.databricks.com/dev-tools/bundles/direct for details Notice: migrating your bundle to direct deployment engine (https://github.com/databricks/cli/issues/6765). >>> print_engines -1 MISSING GET /api/2.2/jobs/get 1 engine/direct GET /api/2.0/preview/scim/v2/Me +1 engine/direct GET /api/2.2/jobs/get diff --git a/acceptance/bundle/migrate/user-agent/race/output.txt b/acceptance/bundle/migrate/user-agent/race/output.txt index 2cf4adc2714..90eab8acfd5 100644 --- a/acceptance/bundle/migrate/user-agent/race/output.txt +++ b/acceptance/bundle/migrate/user-agent/race/output.txt @@ -14,5 +14,5 @@ Error: migrating Terraform state to the direct engine: terraform state [TEST_TMP direct_migrate_state_missing true >>> print_engines -2 MISSING GET /api/2.0/workspace/export -1 MISSING POST /telemetry-ext +2 engine/direct GET /api/2.0/workspace/export +1 engine/direct POST /telemetry-ext diff --git a/acceptance/bundle/state/state_present/output.txt b/acceptance/bundle/state/state_present/output.txt index 24ac39aae47..0b0aef6408c 100644 --- a/acceptance/bundle/state/state_present/output.txt +++ b/acceptance/bundle/state/state_present/output.txt @@ -9,8 +9,8 @@ Plan: 0 to add, 0 to change, 0 to delete, 1 unchanged >>> print_requests.py --get //api/2.1/unity-catalog/schemas "replay_tfstate.py" -"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID][0] interactive/none lineage/ARgQbIVroS5 auth/pat" -"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID][0] interactive/none lineage/ARgQbIVroS5 engine/direct auth/pat" +"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID][0] interactive/none engine/direct lineage/ARgQbIVroS5 auth/pat" +"cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID][0] interactive/none engine/direct lineage/ARgQbIVroS5 auth/pat" === A resources.json with a lower serial does not win: the terraform state still migrates diff --git a/acceptance/bundle/user_agent/output.txt b/acceptance/bundle/user_agent/output.txt index bb7b5c94d3d..cf26d5ea549 100644 --- a/acceptance/bundle/user_agent/output.txt +++ b/acceptance/bundle/user_agent/output.txt @@ -1,6 +1,6 @@ -MISS deploy /api/2.0/preview/scim/v2/Me 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID][0] interactive/none auth/pat' -MISS deploy /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID][0] interactive/none auth/pat' -MISS deploy /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID][0] interactive/none auth/pat' +OK deploy /api/2.0/preview/scim/v2/Me engine/direct +OK deploy /api/2.0/workspace/export engine/direct +OK deploy /api/2.0/workspace/export engine/direct OK deploy /api/2.0/workspace/export engine/direct OK deploy /api/2.0/workspace/export engine/direct OK deploy /api/2.0/workspace/export engine/direct @@ -20,9 +20,9 @@ OK deploy /api/2.0/workspace/mkdirs engine/direct OK deploy /api/2.0/workspace/mkdirs engine/direct OK deploy /api/2.1/unity-catalog/schemas engine/direct MISS deploy /.well-known/databricks-config 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]' -MISS destroy /api/2.0/preview/scim/v2/Me 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_destroy cmd-exec-id/[UUID][0] interactive/none auth/pat' -MISS destroy /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_destroy cmd-exec-id/[UUID][0] interactive/none auth/pat' -MISS destroy /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_destroy cmd-exec-id/[UUID][0] interactive/none auth/pat' +OK destroy /api/2.0/preview/scim/v2/Me engine/direct +OK destroy /api/2.0/workspace/export engine/direct +OK destroy /api/2.0/workspace/export engine/direct OK destroy /api/2.1/unity-catalog/schemas/mycatalog.myschema engine/direct OK destroy /api/2.0/workspace/export engine/direct OK destroy /api/2.0/workspace/get-status engine/direct @@ -33,25 +33,25 @@ OK destroy /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bu OK destroy /api/2.0/workspace/delete engine/direct OK destroy /api/2.0/workspace/delete engine/direct MISS destroy /.well-known/databricks-config 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]' -MISS plan /api/2.0/preview/scim/v2/Me 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat' -MISS plan /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat' -MISS plan /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat' +OK plan /api/2.0/preview/scim/v2/Me engine/direct +OK plan /api/2.0/workspace/export engine/direct +OK plan /api/2.0/workspace/export engine/direct OK plan /api/2.0/workspace/export engine/direct MISS plan /.well-known/databricks-config 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]' -MISS plan2 /api/2.0/preview/scim/v2/Me 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat' -MISS plan2 /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat' -MISS plan2 /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat' +OK plan2 /api/2.0/preview/scim/v2/Me engine/direct +OK plan2 /api/2.0/workspace/export engine/direct +OK plan2 /api/2.0/workspace/export engine/direct OK plan2 /api/2.0/workspace/export engine/direct OK plan2 /api/2.1/unity-catalog/schemas/mycatalog.myschema engine/direct MISS plan2 /.well-known/databricks-config 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]' -MISS run /api/2.0/preview/scim/v2/Me 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none auth/pat' -MISS run /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none auth/pat' -MISS run /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none auth/pat' +OK run /api/2.0/preview/scim/v2/Me engine/direct +OK run /api/2.0/workspace/export engine/direct +OK run /api/2.0/workspace/export engine/direct MISS run /.well-known/databricks-config 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]' -MISS summary /api/2.0/preview/scim/v2/Me 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_summary cmd-exec-id/[UUID] interactive/none auth/pat' -MISS summary /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_summary cmd-exec-id/[UUID] interactive/none auth/pat' -MISS summary /api/2.0/workspace/export 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_summary cmd-exec-id/[UUID] interactive/none auth/pat' OK summary /api/2.0/preview/scim/v2/Me engine/direct +OK summary /api/2.0/preview/scim/v2/Me engine/direct +OK summary /api/2.0/workspace/export engine/direct +OK summary /api/2.0/workspace/export engine/direct MISS summary /.well-known/databricks-config 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]' MISS validate /api/2.0/preview/scim/v2/Me 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_validate cmd-exec-id/[UUID] interactive/none auth/pat' MISS validate /api/2.0/workspace/get-status 'cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_validate cmd-exec-id/[UUID] interactive/none auth/pat' diff --git a/acceptance/bundle/user_agent/simple/out.requests.deploy.json b/acceptance/bundle/user_agent/simple/out.requests.deploy.json index 028011cb20c..aaca239572d 100644 --- a/acceptance/bundle/user_agent/simple/out.requests.deploy.json +++ b/acceptance/bundle/user_agent/simple/out.requests.deploy.json @@ -1,7 +1,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID][0] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID][0] interactive/none engine/direct auth/pat" ] }, "method": "GET", @@ -10,27 +10,27 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID][0] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID][0] interactive/none engine/direct auth/pat" ] }, "method": "GET", "path": "/api/2.0/workspace/export", "q": { "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json" + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock" } } { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID][0] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID][0] interactive/none engine/direct auth/pat" ] }, "method": "GET", "path": "/api/2.0/workspace/export", "q": { "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate" + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock" } } { @@ -43,7 +43,7 @@ "path": "/api/2.0/workspace/export", "q": { "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock" + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json" } } { @@ -56,7 +56,7 @@ "path": "/api/2.0/workspace/export", "q": { "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deploy.lock" + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json" } } { @@ -69,7 +69,7 @@ "path": "/api/2.0/workspace/export", "q": { "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json" + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate" } } { diff --git a/acceptance/bundle/user_agent/simple/out.requests.destroy.json b/acceptance/bundle/user_agent/simple/out.requests.destroy.json index a77a7a20300..7a9f294f930 100644 --- a/acceptance/bundle/user_agent/simple/out.requests.destroy.json +++ b/acceptance/bundle/user_agent/simple/out.requests.destroy.json @@ -1,7 +1,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_destroy cmd-exec-id/[UUID][0] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_destroy cmd-exec-id/[UUID][0] interactive/none engine/direct auth/pat" ] }, "method": "GET", @@ -10,7 +10,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_destroy cmd-exec-id/[UUID][0] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_destroy cmd-exec-id/[UUID][0] interactive/none engine/direct auth/pat" ] }, "method": "GET", @@ -23,7 +23,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_destroy cmd-exec-id/[UUID][0] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_destroy cmd-exec-id/[UUID][0] interactive/none engine/direct auth/pat" ] }, "method": "GET", diff --git a/acceptance/bundle/user_agent/simple/out.requests.plan.json b/acceptance/bundle/user_agent/simple/out.requests.plan.json index 8658a9f41f4..c9ec4d2edcf 100644 --- a/acceptance/bundle/user_agent/simple/out.requests.plan.json +++ b/acceptance/bundle/user_agent/simple/out.requests.plan.json @@ -1,7 +1,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", @@ -10,27 +10,27 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", "path": "/api/2.0/workspace/export", "q": { "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json" + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json" } } { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", "path": "/api/2.0/workspace/export", "q": { "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate" + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json" } } { @@ -43,7 +43,7 @@ "path": "/api/2.0/workspace/export", "q": { "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/deployment.json" + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate" } } { diff --git a/acceptance/bundle/user_agent/simple/out.requests.plan2.json b/acceptance/bundle/user_agent/simple/out.requests.plan2.json index 27810cf9e61..1abfbea97c9 100644 --- a/acceptance/bundle/user_agent/simple/out.requests.plan2.json +++ b/acceptance/bundle/user_agent/simple/out.requests.plan2.json @@ -1,7 +1,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", @@ -10,7 +10,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", @@ -23,7 +23,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_plan cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", diff --git a/acceptance/bundle/user_agent/simple/out.requests.run.json b/acceptance/bundle/user_agent/simple/out.requests.run.json index ace799d7c7e..7faea6514ab 100644 --- a/acceptance/bundle/user_agent/simple/out.requests.run.json +++ b/acceptance/bundle/user_agent/simple/out.requests.run.json @@ -1,7 +1,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", @@ -10,7 +10,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", @@ -23,7 +23,7 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_run cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", diff --git a/acceptance/bundle/user_agent/simple/out.requests.summary.json b/acceptance/bundle/user_agent/simple/out.requests.summary.json index 6182e907b70..31dc3daf318 100644 --- a/acceptance/bundle/user_agent/simple/out.requests.summary.json +++ b/acceptance/bundle/user_agent/simple/out.requests.summary.json @@ -1,36 +1,35 @@ { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_summary cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_summary cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", - "path": "/api/2.0/preview/scim/v2/Me" + "path": "/api/2.0/preview/scim/v2/Me", + "q": { + "excludedAttributes": "entitlements" + } } { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_summary cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_summary cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", - "path": "/api/2.0/workspace/export", - "q": { - "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json" - } + "path": "/api/2.0/preview/scim/v2/Me" } { "headers": { "User-Agent": [ - "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_summary cmd-exec-id/[UUID] interactive/none auth/pat" + "cli/[CLI_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_summary cmd-exec-id/[UUID] interactive/none engine/direct auth/pat" ] }, "method": "GET", "path": "/api/2.0/workspace/export", "q": { "direct_download": "true", - "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate" + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json" } } { @@ -40,9 +39,10 @@ ] }, "method": "GET", - "path": "/api/2.0/preview/scim/v2/Me", + "path": "/api/2.0/workspace/export", "q": { - "excludedAttributes": "entitlements" + "direct_download": "true", + "path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/terraform.tfstate" } } { diff --git a/cmd/bundle/utils/process.go b/cmd/bundle/utils/process.go index d89efd0b042..423c41f35ae 100644 --- a/cmd/bundle/utils/process.go +++ b/cmd/bundle/utils/process.go @@ -130,6 +130,27 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (b *bundle.Bundle cmd.SetContext(ctx) } + shouldReadState := opts.ReadState || opts.AlwaysPull || opts.InitIDs || opts.ErrorOnEmptyState || opts.PreDeployChecks || opts.Deploy || opts.ReadPlanPath != "" + + // needsState is narrower than shouldReadState: it drops the pull-only flags + // (ReadState, AlwaysPull) so read-only consumers like "bundle debug states" pull + // and display the state without triggering a migration, and adds PostStateFunc for + // commands that operate on the state (destroy, run). It gates migrating and opening + // the direct state. + needsState := opts.InitIDs || opts.ErrorOnEmptyState || opts.Deploy || opts.ReadPlanPath != "" || opts.PreDeployChecks || opts.PostStateFunc != nil + + // A command that reads and operates on the state can only run on the direct engine: a + // Terraform state is migrated first, and a failed migration is fatal. Tag the user agent + // before the bundle is loaded, so every request of the command carries the engine, + // including those of runs that fail early (a bad --var, a rejected engine setting). A + // run that fails its migration is therefore tagged engine/direct while its deploy + // telemetry reports the terraform state it started from. + engineTaggedUpfront := shouldReadState && needsState + if engineTaggedUpfront { + ctx = useragent.InContext(ctx, "engine", string(engine.EngineDirect)) + cmd.SetContext(ctx) + } + // Load bundle config and apply target b = root.MustConfigureBundle(cmd) @@ -239,8 +260,6 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (b *bundle.Bundle var dmsDeployment *bundledeployments.Deployment var dmsDeploymentID string - shouldReadState := opts.ReadState || opts.AlwaysPull || opts.InitIDs || opts.ErrorOnEmptyState || opts.PreDeployChecks || opts.Deploy || opts.ReadPlanPath != "" - if shouldReadState { // PullResourcesState depends on stateFiler which needs b.Config.Workspace.StatePath which is set in phases.Initialize stateDesc = statemgmt.PullResourcesState(ctx, b, statemgmt.AlwaysPull(opts.AlwaysPull)) @@ -250,11 +269,9 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (b *bundle.Bundle b.MigratingToDirect = !stateDesc.Engine.IsDirect() - // Tag the user agent with the engine this run actually uses. On the auto-migration - // path the engine is only final after the migration runs (below), so leave it unset - // here and tag there; setting it once rather than appending avoids a stale - // engine/terraform tag alongside engine/direct. - if !b.MigratingToDirect { + // Pull-only commands were not tagged up front and never migrate, so the pulled + // state's engine is the one they use. + if !engineTaggedUpfront { ctx = useragent.InContext(ctx, "engine", string(stateDesc.Engine)) } ctx = WithLineage(ctx, stateDesc) @@ -328,13 +345,6 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (b *bundle.Bundle // and state opening still happen in this single block. var plan *deployplan.Plan if shouldReadState { - // needsState is narrower than shouldReadState: it drops the pull-only flags - // (ReadState, AlwaysPull) so read-only consumers like "bundle debug states" pull - // and display the state without triggering a migration, and adds PostStateFunc for - // commands that operate on the state (destroy, run). It gates migrating and opening - // the direct state. - needsState := opts.InitIDs || opts.ErrorOnEmptyState || opts.Deploy || opts.ReadPlanPath != "" || opts.PreDeployChecks || opts.PostStateFunc != nil - // Migrate a Terraform state to the direct engine: the direct engine is the only engine, // so when the existing state still uses Terraform, convert it so the run proceeds on the // direct engine. Migrate is in-memory and reversible - nothing is written or pushed - so @@ -349,15 +359,6 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (b *bundle.Bundle } } - // Tag the user agent with the engine this run actually uses. The tag is left unset - // after the pull on the auto-migration path (see above) because the engine is only - // final here, after the migration ran, was skipped, or fell back. Setting it once - // (rather than appending) avoids a stale engine/terraform tag alongside engine/direct. - if b.MigratingToDirect { - ctx = useragent.InContext(ctx, "engine", string(stateDesc.Engine)) - cmd.SetContext(ctx) - } - // Open direct engine state once for all subsequent operations (ExportState, CalculatePlan, Apply, etc.) // A migrated-from-Terraform state is already open (seeded in memory above), so skip the disk open. needDirectState := stateDesc.Engine.IsDirect() && needsState @@ -586,8 +587,7 @@ func ProcessBundleRet(cmd *cobra.Command, opts ProcessOptions) (b *bundle.Bundle // On success it advances stateDesc and metrics to the direct engine. Any failure (parse, // conversion, plan check) is fatal and returns an error: the Terraform engine was removed, so there // is no engine to fall back to. Nothing is committed here - deploy calls statemgmt.CommitMigration -// after approval, destroy commits as part of its teardown. The caller tags the user agent with the -// resolved stateDesc.Engine afterwards. +// after approval, destroy commits as part of its teardown. func migrateTerraformToDirect(ctx context.Context, b *bundle.Bundle, stateDesc *statemgmt.StateDesc) error { if err := statemgmt.Migrate(ctx, b); err != nil { return fmt.Errorf("migrating Terraform state to the direct engine: %w", err)