Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions acceptance/bundle/dms/attempt-name/databricks.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bundle:
name: dms-attempt-name-$UNIQUE_NAME
experimental:
deployment_history: true

resources:
jobs:
foo:
name: foo
2 changes: 2 additions & 0 deletions acceptance/bundle/dms/attempt-name/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = true
EnvMatrix.DMS = ["true"]
88 changes: 88 additions & 0 deletions acceptance/bundle/dms/attempt-name/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

=== With DATABRICKS_AUTO_DEPLOY_ATTEMPT set, the version the deploy creates records the attempt

>>> DATABRICKS_AUTO_DEPLOY_ATTEMPT=webhook-triggers/[UUID][0]/attempts/[UUID][1] [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dms-attempt-name-[UNIQUE_NAME]/default/files...
Created jobs.foo
Files: 2 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged

>>> print_requests.py --dms //versions ^//operations ^//complete
{
"method": "POST",
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions",
"q": {
"version_id": "1"
},
"body": {
"auto_deploy_attempt": "webhook-triggers/[UUID][0]/attempts/[UUID][1]",
"cli_version": "[CLI_VERSION]",
"operations": [
{
"action_type": "OPERATION_ACTION_TYPE_CREATE",
"resource_key": "jobs.foo"
}
],
"version_type": "VERSION_TYPE_DEPLOY"
}
}

=== Without it, the request has no attempt

>>> update_file.py databricks.yml name: foo name: renamed

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/dms-attempt-name-[UNIQUE_NAME]/default/files...
Updated jobs.foo
Files: 1 uploaded, 0 deleted
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged

>>> print_requests.py --dms //versions ^//operations ^//complete
{
"method": "POST",
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions",
"q": {
"version_id": "2"
},
"body": {
"cli_version": "[CLI_VERSION]",
"operations": [
{
"action_type": "OPERATION_ACTION_TYPE_UPDATE",
"resource_key": "jobs.foo"
}
],
"previous_version_id": "1",
"version_type": "VERSION_TYPE_DEPLOY"
}
}

=== A destroy doesn't record the attempt, even with the variable set

>>> DATABRICKS_AUTO_DEPLOY_ATTEMPT=webhook-triggers/[UUID][0]/attempts/[UUID][1] [CLI] bundle destroy --auto-approve
The following resources will be deleted:
delete resources.jobs.foo

All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/dms-attempt-name-[UNIQUE_NAME]/default

Destroy: 1 deleted

>>> print_requests.py --dms //versions ^//operations ^//complete
{
"method": "POST",
"path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions",
"q": {
"version_id": "3"
},
"body": {
"cli_version": "[CLI_VERSION]",
"operations": [
{
"action_type": "OPERATION_ACTION_TYPE_DELETE",
"resource_key": "jobs.foo"
}
],
"previous_version_id": "2",
"version_type": "VERSION_TYPE_DESTROY"
}
}
19 changes: 19 additions & 0 deletions acceptance/bundle/dms/attempt-name/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
envsubst < databricks.yml.tmpl > databricks.yml
attempt=webhook-triggers/11111111-1111-1111-1111-111111111111/attempts/22222222-2222-2222-2222-222222222222

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nice to have] This test inherits Cloud = true from acceptance/bundle/dms/test.toml (see out.test.toml), so it also runs against a real workspace with a made-up webhook-triggers/1111…/attempts/2222… name. The description says the service validates the value. If it checks that the attempt exists, the first deploy fails with "failed to create deployment version" in the cloud run. Should this directory set Cloud = false until there's a real attempt to point at, or was it checked against a workspace?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The service checks only the attempt name's format, not that the attempt exists, and this name is well formed (lowercase canonical UUIDs). It hasn't run against a workspace yet, because no workspace accepts the field until it ships. That's also when this PR can merge, so I'm keeping the cloud run: it confirms the field is live.

trap "errcode trace '$CLI' bundle destroy --auto-approve" EXIT

title "With DATABRICKS_AUTO_DEPLOY_ATTEMPT set, the version the deploy creates records the attempt"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nice to have] Nothing destroys the bundle at the end, so on the inherited cloud run the job (foo/renamed), the bundle files and the DMS deployment are left in the workspace after every run. Can you add trap "errcode trace '$CLI' bundle destroy --auto-approve" EXIT before the first deploy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 3e4f7f0. The last step destroys the bundle itself, to check that a destroy carries no attempt, so the script clears the trap after it.

trace DATABRICKS_AUTO_DEPLOY_ATTEMPT=$attempt $CLI bundle deploy
add_repl "$($CLI bundle summary -o json | jq -r .bundle.deployment.deployment_id)" DEPLOYMENT_ID

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nit] .agents/rules/testing.md says to use the acceptance/bin/ helpers instead of inline jq pipelines, and to prefer gron.py | grep field for single values. Can this read the deployment ID that way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's no helper for the deployment ID, and gron.py prints path = value; lines, so capturing a bare value with it takes more parsing than jq -r. bundle summary returns the ID as a string, so jq can't round it. I've kept it as is.

trace print_requests.py --dms //versions ^//operations ^//complete

title "Without it, the request has no attempt"
trace update_file.py databricks.yml 'name: foo' 'name: renamed'
trace $CLI bundle deploy
trace print_requests.py --dms //versions ^//operations ^//complete

title "A destroy doesn't record the attempt, even with the variable set"
trace DATABRICKS_AUTO_DEPLOY_ATTEMPT=$attempt $CLI bundle destroy --auto-approve
trace print_requests.py --dms //versions ^//operations ^//complete
# Destroyed above, so the cleanup trap has nothing left to do.
trap - EXIT
11 changes: 11 additions & 0 deletions bundle/env/dms.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ func RecordsDeploymentHistory(ctx context.Context, configured *bool) bool {
value, _ := get(ctx, []string{DeploymentHistoryVariable})
return value == "true"
}

// AutoDeployAttemptVariable names the auto-deploy attempt a deploy runs for. The auto-deploy runner
// sets it, and the deploy records it on the deployment version it creates.
const AutoDeployAttemptVariable = "DATABRICKS_AUTO_DEPLOY_ATTEMPT"

// AutoDeployAttempt returns the auto-deploy attempt to record on the deployment version.
func AutoDeployAttempt(ctx context.Context) (string, bool) {
return get(ctx, []string{
AutoDeployAttemptVariable,
})
}
9 changes: 9 additions & 0 deletions bundle/phases/dms.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/bundle/deployplan"
"github.com/databricks/cli/bundle/env"
"github.com/databricks/cli/internal/build"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/dms"
Expand Down Expand Up @@ -225,6 +226,13 @@
OriginUrl: git.OriginURL,
}
}
// Links a deploy's version to the auto-deploy attempt that ran it, passed through as is for the
// service to validate. Auto-deploy never destroys, and other deploys leave the variable unset, so
// their request doesn't change.
var attempt string
if versionType == dms.VersionTypeDeploy {
attempt, _ = env.AutoDeployAttempt(ctx)
}
version, err := w.BundleDeployments.CreateVersion(ctx, bundledeployments.CreateVersionRequest{
Parent: dms.DeploymentName(deploymentID),
VersionId: strconv.Itoa(versionID),
Expand All @@ -234,6 +242,7 @@
PreviousVersionId: previousVersionID,
GitInfo: gitInfo,
Operations: staged,
AutoDeployAttempt: attempt,

Check failure on line 245 in bundle/phases/dms.go

View workflow job for this annotation

GitHub Actions / lint

unknown field AutoDeployAttempt in struct literal of type bundledeployments.Version (typecheck)

Check failure on line 245 in bundle/phases/dms.go

View workflow job for this annotation

GitHub Actions / validate-generated

unknown field AutoDeployAttempt in struct literal of type bundledeployments.Version

Check failure on line 245 in bundle/phases/dms.go

View workflow job for this annotation

GitHub Actions / task test (macos, directdms)

unknown field AutoDeployAttempt in struct literal of type bundledeployments.Version

Check failure on line 245 in bundle/phases/dms.go

View workflow job for this annotation

GitHub Actions / task test (macos, direct)

unknown field AutoDeployAttempt in struct literal of type bundledeployments.Version

Check failure on line 245 in bundle/phases/dms.go

View workflow job for this annotation

GitHub Actions / task test (linux, directdms)

unknown field AutoDeployAttempt in struct literal of type bundledeployments.Version

Check failure on line 245 in bundle/phases/dms.go

View workflow job for this annotation

GitHub Actions / task test (windows, direct)

unknown field AutoDeployAttempt in struct literal of type bundledeployments.Version

Check failure on line 245 in bundle/phases/dms.go

View workflow job for this annotation

GitHub Actions / task test (windows, directdms)

unknown field AutoDeployAttempt in struct literal of type bundledeployments.Version

Check failure on line 245 in bundle/phases/dms.go

View workflow job for this annotation

GitHub Actions / task test (linux, direct)

unknown field AutoDeployAttempt in struct literal of type bundledeployments.Version

Check failure on line 245 in bundle/phases/dms.go

View workflow job for this annotation

GitHub Actions / regression-report

unknown field AutoDeployAttempt in struct literal of type bundledeployments.Version
},
})
if err != nil {
Expand Down
Loading